You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is as small as I've gotten the reproducer. All these parts seem to be significant:
the outer if and an inner match
the decorated call being separate to the match
the match being a match (replacing the match with the equivalent if y is None: ... else: ... construct works fine)
the match having exhaustive arms with the unreachable call being unreachable (as far as mypy can tell) (e.g. deleting the case None: entirely works fine)
the unreachable call existing (inlining case _: raise NotImplementedError() works fine)
decorator being a lambda (or an class with __call__ method) (using def decorator(f): return f works fine)
decorated being defined after do_it in the file (changing the order works fine) (NB. it's just decorated, decorator and unreachable can be defined before or after do_it and still reproduce the behaviour)
Expected Behavior
This to pass type checking.
In particular, have same behaviour as any of the very similar ablations mentioned above, e.g. both of these work:
changing decorator = lambda f: f to def decorator(f): return f
moving decorated to be before do_it
Actual Behavior
file.py:19: error: Name "var" may be undefined [possibly-undefined]
Found 1 error in 1 file (checked 1 source file)
Bug Report
Some obtuse code results in a false positive for the
possibly-undefined
error code.To Reproduce
Run
mypy --enable-error-code possibly-undefined file.py
on this file:This is as small as I've gotten the reproducer. All these parts seem to be significant:
if
and an innermatch
decorated
call being separate to thematch
match
being amatch
(replacing thematch
with the equivalentif y is None: ... else: ...
construct works fine)match
having exhaustive arms with theunreachable
call being unreachable (as far as mypy can tell) (e.g. deleting thecase None:
entirely works fine)unreachable
call existing (inliningcase _: raise NotImplementedError()
works fine)decorator
being a lambda (or an class with__call__
method) (usingdef decorator(f): return f
works fine)decorated
being defined afterdo_it
in the file (changing the order works fine) (NB. it's justdecorated
,decorator
andunreachable
can be defined before or afterdo_it
and still reproduce the behaviour)Expected Behavior
This to pass type checking.
In particular, have same behaviour as any of the very similar ablations mentioned above, e.g. both of these work:
decorator = lambda f: f
todef decorator(f): return f
decorated
to be beforedo_it
Actual Behavior
Your Environment
--enable-error-code possibly-undefined
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: