Skip to content

Commit

Permalink
Silence pyright errors without changing existing code
Browse files Browse the repository at this point in the history
  • Loading branch information
LincolnPuzey committed Sep 23, 2022
1 parent 46c7740 commit 4c99d51
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tlz/_build_tlz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions toolz/functoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def __init__(self, *args, **kwargs):

self.__doc__ = getattr(func, '__doc__', None)
self.__name__ = getattr(func, '__name__', '<curry>')
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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions toolz/itertoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
)
2 changes: 1 addition & 1 deletion toolz/sandbox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 4c99d51

Please sign in to comment.