Name in class def is resolved in enclosing function, instead of global, scope. #12764
Labels
bug
mypy got something wrong
topic-runtime-semantics
mypy doesn't model runtime semantics correctly
topic-variable-scope
Bug Report
If a name
x
appearing in a class defC
is not yet bound, and it is bound in an enclosing function deff
, then mypy resolvesx
asf.x
. However, the python doc says:To Reproduce
Expected Behavior
Actual Behavior
See above.
Your Environment
Cause of the bug and a fix for it
In
SemanticAnalyzer.lookup()
methodsemanal.py
line 4419:This looks in enclosed functions even if in a class definition.
Change this to:
Result from mypy with this change:
The text was updated successfully, but these errors were encountered: