chore: type check xontribs,xompletions (#4642)

as well as match dmypy semantics
This commit is contained in:
Noorhteen Raja NJ 2022-01-18 20:24:31 +05:30 committed by GitHub
parent a1d94b822e
commit a00b6014fe
Failed to generate hash of commit
11 changed files with 50 additions and 26 deletions

View file

@ -66,12 +66,13 @@ def qa():
$XONSH_TRACE_SUBPROC_FUNC = colored_tracer $XONSH_TRACE_SUBPROC_FUNC = colored_tracer
$XONSH_TRACE_SUBPROC = True $XONSH_TRACE_SUBPROC = True
black --check xonsh xontrib tests black --check xonsh xontrib tests xompletions
python -m flake8 python -m flake8
# todo: add xontrib folder here
mypy xonsh mypy xonsh
mypy xontrib --namespace-packages --explicit-package-bases
mypy xompletions --namespace-packages --explicit-package-bases
pytest -m news pytest -m news

View file

@ -100,8 +100,12 @@ cache_dir = .cache/mypy/
# warn_unused_ignores = True # warn_unused_ignores = True
warn_unused_configs = True warn_unused_configs = True
warn_no_return = False warn_no_return = False
; a regex to exclude certain directories ; a regex to exclude certain directories
exclude = ((xonsh/ply)|(__amalgam__.py)) exclude = ((xonsh/ply)|(__amalgam__.py)|(xontrib/(mpl.*py|distributed.py|jedi.py)))
;match dmypy semantics - https://github.com/python/mypy/issues/8046
local_partial_types = True
# report # report
show_error_context = True show_error_context = True

View file

@ -604,6 +604,7 @@ class ArgParserAlias:
def hook_post_add_argument( def hook_post_add_argument(
self, self,
*,
parser: "ArgParser|ap.ArgumentParser", parser: "ArgParser|ap.ArgumentParser",
action: "ap.Action", action: "ap.Action",
param: str, param: str,

View file

@ -154,7 +154,7 @@ class CompletionContext(NamedTuple):
class ExpansionOperation(enum.Enum): class ExpansionOperation(enum.Enum):
NEVER_EXPAND = object() NEVER_EXPAND = object()
SIMPLE_ARG_EXPANSION = None # the default SIMPLE_ARG_EXPANSION: "Any" = None # the default
class Missing(enum.Enum): class Missing(enum.Enum):

View file

@ -3,10 +3,10 @@ from xonsh.lazyasd import lazyobject
from xonsh.tools import print_warning from xonsh.tools import print_warning
_WARNINGS_PRINTED = set() _WARNINGS_PRINTED: "set[str]" = set()
def _print_proc_warning(msg): def _print_proc_warning(msg: str):
global _WARNINGS_PRINTED global _WARNINGS_PRINTED
if msg not in _WARNINGS_PRINTED: if msg not in _WARNINGS_PRINTED:
print_warning(msg) print_warning(msg)

View file

@ -15,12 +15,16 @@ The cache file is created on first use, if it does not already exist.
""" """
import os import os
import importlib import importlib
import typing as tp
if tp.TYPE_CHECKING:
from pygments.style import Style
# Global storage variables # Global storage variables
__version__ = "0.1.1" __version__ = "0.1.1"
CACHE = None CACHE: "dict[str, tp.Any] | None" = None
CUSTOM_STYLES = {} CUSTOM_STYLES: "dict[str, Style]" = {}
DEBUG = False DEBUG = False
@ -267,14 +271,14 @@ def cache_filename():
) )
def add_custom_style(name, style): def add_custom_style(name: str, style: "Style"):
"""Register custom style to be able to retrieve it by ``get_style_by_name``. """Register custom style to be able to retrieve it by ``get_style_by_name``.
Parameters Parameters
---------- ----------
name : str name
Style name. Style name.
style : pygments.Style style
Custom style to add. Custom style to add.
""" """
CUSTOM_STYLES[name] = style CUSTOM_STYLES[name] = style

View file

@ -17,6 +17,8 @@ import shutil
import importlib import importlib
import threading import threading
import collections import collections
import typing as tp
import xonsh.completers.tools as xct import xonsh.completers.tools as xct
from xonsh.built_ins import XSH from xonsh.built_ins import XSH
@ -46,12 +48,14 @@ from xonsh.platform import (
from xonsh.lazyimps import pygments, pyghooks, winutils from xonsh.lazyimps import pygments, pyghooks, winutils
from xonsh.events import events from xonsh.events import events
readline = None if tp.TYPE_CHECKING:
RL_COMPLETION_SUPPRESS_APPEND = RL_LIB = RL_STATE = None from types import ModuleType
RL_COMPLETION_QUERY_ITEMS = None
readline: "ModuleType|None" = None
RL_COMPLETION_SUPPRESS_APPEND = RL_LIB = RL_STATE = None # type: tp.Any
RL_COMPLETION_QUERY_ITEMS: "tp.Any" = None
RL_CAN_RESIZE = False RL_CAN_RESIZE = False
RL_DONE = None RL_VARIABLE_VALUE: "tp.Callable[..., tp.Any]|None" = None
RL_VARIABLE_VALUE = None
_RL_STATE_DONE = 0x1000000 _RL_STATE_DONE = 0x1000000
_RL_STATE_ISEARCH = 0x0000080 _RL_STATE_ISEARCH = 0x0000080

View file

@ -15,7 +15,7 @@ class _TokenType(tuple):
See https://bitbucket.org/birkenfeld/pygments-main/raw/05818a4ef9891d9ac22c851f7b3ea4b4fce460ab/AUTHORS See https://bitbucket.org/birkenfeld/pygments-main/raw/05818a4ef9891d9ac22c851f7b3ea4b4fce460ab/AUTHORS
""" """
parent = None parent: "_TokenType|None" = None
def split(self): def split(self):
buf = [] buf = []

View file

@ -37,10 +37,22 @@ from xonsh.tools import check_for_partial_string
__all__ = () __all__ = ()
# todo: do not assign .abbrevs and directly use abbrevs as mutable const.
XSH.abbrevs = abbrevs = dict() if tp.TYPE_CHECKING:
class AbbrCallType(tp.Protocol):
def __call__(self, word: str, buffer: Buffer) -> str:
...
AbbrValType = tp.Union[str, AbbrCallType]
abbrevs: "dict[str, AbbrValType]" = dict()
# XSH.builtins is a namespace and extendable
XSH.builtins.abbrevs = abbrevs
proxy = DynamicAccessProxy("abbrevs", "__xonsh__.abbrevs") proxy = DynamicAccessProxy("abbrevs", "__xonsh__.abbrevs")
builtins.abbrevs = proxy builtins.abbrevs = proxy # type: ignore
class _LastExpanded(tp.NamedTuple): class _LastExpanded(tp.NamedTuple):

View file

@ -17,8 +17,6 @@ from xonsh.built_ins import XSH
__all__ = () __all__ = ()
_policies = []
XSH.builtins.events.doc( XSH.builtins.events.doc(
"autovox_policy", "autovox_policy",
""" """

View file

@ -229,7 +229,7 @@ class VoxHandler(xcli.ArgParserAlias):
def remove( def remove(
self, self,
names: xcli.Annotated[ names: xcli.Annotated[
list, tp.List[str],
xcli.Arg(metavar="ENV", nargs="+", completer=venv_names_completer), xcli.Arg(metavar="ENV", nargs="+", completer=venv_names_completer),
], ],
force=False, force=False,
@ -274,7 +274,7 @@ class VoxHandler(xcli.ArgParserAlias):
try: try:
return subprocess.check_call( return subprocess.check_call(
[command] + list(args), shell=ON_WINDOWS, env=env, **kwargs [command] + list(args), shell=bool(ON_WINDOWS), env=env, **kwargs
) )
# need to have shell=True on windows, otherwise the PYTHONPATH # need to have shell=True on windows, otherwise the PYTHONPATH
# won't inherit the PATH # won't inherit the PATH
@ -289,7 +289,7 @@ class VoxHandler(xcli.ArgParserAlias):
str, str,
xcli.Arg(completer=venv_names_completer), xcli.Arg(completer=venv_names_completer),
], ],
args: xcli.Annotated[tp.List[str], xcli.Arg(nargs="...")], args: xcli.Annotated[tp.Sequence[str], xcli.Arg(nargs="...")],
): ):
"""Run the command in the given environment """Run the command in the given environment
@ -311,7 +311,7 @@ class VoxHandler(xcli.ArgParserAlias):
def runin_all( def runin_all(
self, self,
args: xcli.Annotated[tp.List[str], xcli.Arg(nargs="...")], args: xcli.Annotated[tp.Sequence[str], xcli.Arg(nargs="...")],
): ):
"""Run the command in all environments found under $VIRTUALENV_HOME """Run the command in all environments found under $VIRTUALENV_HOME