mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 00:14:41 +01:00
chore: type check xontribs,xompletions (#4642)
as well as match dmypy semantics
This commit is contained in:
parent
a1d94b822e
commit
a00b6014fe
11 changed files with 50 additions and 26 deletions
|
@ -66,12 +66,13 @@ def qa():
|
|||
$XONSH_TRACE_SUBPROC_FUNC = colored_tracer
|
||||
$XONSH_TRACE_SUBPROC = True
|
||||
|
||||
black --check xonsh xontrib tests
|
||||
black --check xonsh xontrib tests xompletions
|
||||
|
||||
python -m flake8
|
||||
|
||||
# todo: add xontrib folder here
|
||||
mypy xonsh
|
||||
mypy xontrib --namespace-packages --explicit-package-bases
|
||||
mypy xompletions --namespace-packages --explicit-package-bases
|
||||
|
||||
pytest -m news
|
||||
|
||||
|
|
|
@ -100,8 +100,12 @@ cache_dir = .cache/mypy/
|
|||
# warn_unused_ignores = True
|
||||
warn_unused_configs = True
|
||||
warn_no_return = False
|
||||
|
||||
; 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
|
||||
show_error_context = True
|
||||
|
|
|
@ -604,6 +604,7 @@ class ArgParserAlias:
|
|||
|
||||
def hook_post_add_argument(
|
||||
self,
|
||||
*,
|
||||
parser: "ArgParser|ap.ArgumentParser",
|
||||
action: "ap.Action",
|
||||
param: str,
|
||||
|
|
|
@ -154,7 +154,7 @@ class CompletionContext(NamedTuple):
|
|||
|
||||
class ExpansionOperation(enum.Enum):
|
||||
NEVER_EXPAND = object()
|
||||
SIMPLE_ARG_EXPANSION = None # the default
|
||||
SIMPLE_ARG_EXPANSION: "Any" = None # the default
|
||||
|
||||
|
||||
class Missing(enum.Enum):
|
||||
|
|
|
@ -3,10 +3,10 @@ from xonsh.lazyasd import lazyobject
|
|||
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
|
||||
if msg not in _WARNINGS_PRINTED:
|
||||
print_warning(msg)
|
||||
|
|
|
@ -15,12 +15,16 @@ The cache file is created on first use, if it does not already exist.
|
|||
"""
|
||||
import os
|
||||
import importlib
|
||||
import typing as tp
|
||||
|
||||
if tp.TYPE_CHECKING:
|
||||
from pygments.style import Style
|
||||
|
||||
|
||||
# Global storage variables
|
||||
__version__ = "0.1.1"
|
||||
CACHE = None
|
||||
CUSTOM_STYLES = {}
|
||||
CACHE: "dict[str, tp.Any] | None" = None
|
||||
CUSTOM_STYLES: "dict[str, Style]" = {}
|
||||
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``.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
name : str
|
||||
name
|
||||
Style name.
|
||||
style : pygments.Style
|
||||
style
|
||||
Custom style to add.
|
||||
"""
|
||||
CUSTOM_STYLES[name] = style
|
||||
|
|
|
@ -17,6 +17,8 @@ import shutil
|
|||
import importlib
|
||||
import threading
|
||||
import collections
|
||||
import typing as tp
|
||||
|
||||
|
||||
import xonsh.completers.tools as xct
|
||||
from xonsh.built_ins import XSH
|
||||
|
@ -46,12 +48,14 @@ from xonsh.platform import (
|
|||
from xonsh.lazyimps import pygments, pyghooks, winutils
|
||||
from xonsh.events import events
|
||||
|
||||
readline = None
|
||||
RL_COMPLETION_SUPPRESS_APPEND = RL_LIB = RL_STATE = None
|
||||
RL_COMPLETION_QUERY_ITEMS = None
|
||||
if tp.TYPE_CHECKING:
|
||||
from types import ModuleType
|
||||
|
||||
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_DONE = None
|
||||
RL_VARIABLE_VALUE = None
|
||||
RL_VARIABLE_VALUE: "tp.Callable[..., tp.Any]|None" = None
|
||||
_RL_STATE_DONE = 0x1000000
|
||||
_RL_STATE_ISEARCH = 0x0000080
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class _TokenType(tuple):
|
|||
See https://bitbucket.org/birkenfeld/pygments-main/raw/05818a4ef9891d9ac22c851f7b3ea4b4fce460ab/AUTHORS
|
||||
"""
|
||||
|
||||
parent = None
|
||||
parent: "_TokenType|None" = None
|
||||
|
||||
def split(self):
|
||||
buf = []
|
||||
|
|
|
@ -37,10 +37,22 @@ from xonsh.tools import check_for_partial_string
|
|||
|
||||
__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")
|
||||
builtins.abbrevs = proxy
|
||||
builtins.abbrevs = proxy # type: ignore
|
||||
|
||||
|
||||
class _LastExpanded(tp.NamedTuple):
|
||||
|
|
|
@ -17,8 +17,6 @@ from xonsh.built_ins import XSH
|
|||
__all__ = ()
|
||||
|
||||
|
||||
_policies = []
|
||||
|
||||
XSH.builtins.events.doc(
|
||||
"autovox_policy",
|
||||
"""
|
||||
|
|
|
@ -229,7 +229,7 @@ class VoxHandler(xcli.ArgParserAlias):
|
|||
def remove(
|
||||
self,
|
||||
names: xcli.Annotated[
|
||||
list,
|
||||
tp.List[str],
|
||||
xcli.Arg(metavar="ENV", nargs="+", completer=venv_names_completer),
|
||||
],
|
||||
force=False,
|
||||
|
@ -274,7 +274,7 @@ class VoxHandler(xcli.ArgParserAlias):
|
|||
|
||||
try:
|
||||
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
|
||||
# won't inherit the PATH
|
||||
|
@ -289,7 +289,7 @@ class VoxHandler(xcli.ArgParserAlias):
|
|||
str,
|
||||
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
|
||||
|
||||
|
@ -311,7 +311,7 @@ class VoxHandler(xcli.ArgParserAlias):
|
|||
|
||||
def runin_all(
|
||||
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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue