From 80f6b7c1f030aa6c96a9a52ff16b84b6eb7cfa8f Mon Sep 17 00:00:00 2001 From: Lincoln Puzey <18750802+LincolnPuzey@users.noreply.github.com> Date: Thu, 22 Sep 2022 17:32:42 +0800 Subject: [PATCH 1/3] Add initial pyright config file This runs pyright with default settings against everything in "toolz", except for tests and _version.py --- pyrightconfig.json | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pyrightconfig.json diff --git a/pyrightconfig.json b/pyrightconfig.json new file mode 100644 index 00000000..1a4c36a0 --- /dev/null +++ b/pyrightconfig.json @@ -0,0 +1,18 @@ +{ + "include": [ + "toolz", + "tlz" + ], + "exclude": [ + "**/__pycache__", + "**/tests" + ], + "ignore": [ + "toolz/_version.py" + ], + "pythonVersion": "3.5", + "pythonPlatform": "All", + "stubPath": "", + "typeCheckingMode": "basic", + "reportUnnecessaryTypeIgnoreComment": true +} From 46c77405e09400e73e9d956cff161a6fa2fc3d11 Mon Sep 17 00:00:00 2001 From: Lincoln Puzey <18750802+LincolnPuzey@users.noreply.github.com> Date: Thu, 22 Sep 2022 18:52:51 +0800 Subject: [PATCH 2/3] Add github action to run pyright in CI --- .github/workflows/pyright.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/pyright.yml diff --git a/.github/workflows/pyright.yml b/.github/workflows/pyright.yml new file mode 100644 index 00000000..54be7498 --- /dev/null +++ b/.github/workflows/pyright.yml @@ -0,0 +1,15 @@ +name: Pyright + +on: + push: + branches: [ master ] + pull_request: + +jobs: + type-check: + runs-on: "ubuntu-latest" + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Run Pyright + uses: jakebailey/pyright-action@v1 From 4c99d5125732acfbdce716f33c09cdbb6ec8086e Mon Sep 17 00:00:00 2001 From: Lincoln Puzey <18750802+LincolnPuzey@users.noreply.github.com> Date: Thu, 22 Sep 2022 19:32:05 +0800 Subject: [PATCH 3/3] Silence pyright errors without changing existing code --- tlz/_build_tlz.py | 4 ++-- toolz/functoolz.py | 18 +++++++++--------- toolz/itertoolz.py | 9 ++++++--- toolz/sandbox/core.py | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/tlz/_build_tlz.py b/tlz/_build_tlz.py index 3ac78369..1c6d587d 100644 --- a/tlz/_build_tlz.py +++ b/tlz/_build_tlz.py @@ -37,7 +37,7 @@ def find_module(self, fullname, path=None): # pragma: py3 no cover def load_module(self, fullname): # pragma: py3 no cover if fullname in sys.modules: # pragma: no cover return sys.modules[fullname] - spec = ModuleSpec(fullname, self) + spec = ModuleSpec(fullname, self) # pyright: ignore module = self.create_module(spec) sys.modules[fullname] = module self.exec_module(module) @@ -46,7 +46,7 @@ def load_module(self, fullname): # pragma: py3 no cover def find_spec(self, fullname, path, target=None): # pragma: no cover package, dot, submodules = fullname.partition('.') if package == 'tlz': - return ModuleSpec(fullname, self) + return ModuleSpec(fullname, self) # pyright: ignore def create_module(self, spec): return types.ModuleType(spec.name) diff --git a/toolz/functoolz.py b/toolz/functoolz.py index 2c75d3a4..830d48f8 100644 --- a/toolz/functoolz.py +++ b/toolz/functoolz.py @@ -222,7 +222,7 @@ def __init__(self, *args, **kwargs): self.__doc__ = getattr(func, '__doc__', None) self.__name__ = getattr(func, '__name__', '') - self.__module__ = getattr(func, '__module__', None) + self.__module__ = getattr(func, '__module__', None) # pyright: ignore self.__qualname__ = getattr(func, '__qualname__', None) self._sigspec = None self._has_unknown_args = None @@ -241,7 +241,7 @@ def __signature__(self): params = list(sig.parameters.values()) skip = 0 - for param in params[:len(args)]: + for param in params[:len(args)]: # pyright: ignore if param.kind == param.VAR_POSITIONAL: break skip += 1 @@ -256,8 +256,8 @@ def __signature__(self): elif kind == param.VAR_POSITIONAL: if kwonly: continue - elif param.name in keywords: - default = keywords[param.name] + elif param.name in keywords: # pyright: ignore + default = keywords[param.name] # pyright: ignore kind = param.KEYWORD_ONLY kwonly = True else: @@ -311,7 +311,7 @@ def _should_curry(self, args, kwargs, exc=None): func = self.func args = self.args + args if self.keywords: - kwargs = dict(self.keywords, **kwargs) + kwargs = dict(self.keywords, **kwargs) # pyright: ignore if self._sigspec is None: sigspec = self._sigspec = _sigs.signature_or_spec(func) self._has_unknown_args = has_varargs(func, sigspec) is not False @@ -390,7 +390,7 @@ def _restore_curry(cls, func, args, kwargs, userdict, is_decorated): @curry -def memoize(func, cache=None, key=None): +def memoize(func, cache=None, key=None): # pyright: ignore """ Cache a function's result for speedy future evaluation Considerations: @@ -442,7 +442,7 @@ def memoize(func, cache=None, key=None): def key(args, kwargs): return args[0] elif may_have_kwargs: - def key(args, kwargs): + def key(args, kwargs): # pyright: ignore return ( args or None, frozenset(kwargs.items()) if kwargs else None, @@ -495,7 +495,7 @@ def __getstate__(self): def __setstate__(self, state): self.first, self.funcs = state - @instanceproperty(classval=__doc__) + @instanceproperty(classval=__doc__) # pyright: ignore def __doc__(self): def composed_doc(*fs): """Generate a docstring for the composition of fs. @@ -776,7 +776,7 @@ def __call__(self, *args, **kwargs): except self.exc as e: return self.handler(e) - @instanceproperty(classval=__doc__) + @instanceproperty(classval=__doc__) # pyright: ignore def __doc__(self): from textwrap import dedent diff --git a/toolz/itertoolz.py b/toolz/itertoolz.py index 5049e5eb..e2a59dd1 100644 --- a/toolz/itertoolz.py +++ b/toolz/itertoolz.py @@ -241,7 +241,7 @@ def interleave(seqs): yield next(itr) return except StopIteration: - predicate = partial(operator.is_not, itr) + predicate = partial(operator.is_not, itr) # pyright: ignore iters = itertools.cycle(itertools.takewhile(predicate, iters)) @@ -625,7 +625,7 @@ def reduceby(key, binop, seq, init=no_default): d[k] = item continue else: - d[k] = init() + d[k] = init() # pyright: ignore d[k] = binop(d[k], item) return d @@ -1054,4 +1054,7 @@ def random_sample(prob, seq, random_state=None): from random import Random random_state = Random(random_state) - return filter(lambda _: random_state.random() < prob, seq) + return filter( + lambda _: random_state.random() < prob, # pyright: ignore + seq, + ) diff --git a/toolz/sandbox/core.py b/toolz/sandbox/core.py index 55e09d74..35e5b6ab 100644 --- a/toolz/sandbox/core.py +++ b/toolz/sandbox/core.py @@ -74,7 +74,7 @@ def __hash__(self): if self.key == self._default_hashkey: val = self.key else: - val = self.key(self.item) + val = self.key(self.item) # pyright: ignore return hash(val) def __eq__(self, other):