SymbolTableNode.kind
is incorrect for from <module> import <name>
imports in a function body
#18616
Labels
bug
mypy got something wrong
Bug Report, Expected Behaviour, & Actual Behaviour
I'm writing a mypy plugin which needs to distinguish between the origin of variables (whether they're from the global scope or local scope). When analysing names from
ImportFrom
nodes, thekind
value appears to be incorrect:Potential fix
I believe the issue is here:
mypy/mypy/semanal.py
Line 2853 in e9a813c
Changing it to the following seems to fix the problem:
However, It's not obvious how to write a test for this. I'm looking at https://github.com/python/mypy/blob/master/test-data/unit/semanal-symtable.test but the tests here rely on
str()
ingifying amypy.nodes.SymbolTable
object, which is an attribute ofmypy.nodes.MypyFile
andmypy.nodes.TypeInfo
; there is no equivalent attribute inmypy.nodes.FuncDef
(function body symbol tables only temporarily exist atmypy/mypy/semanal.py
Lines 444 to 446 in e9a813c
Is there is an obvious way to test the local definition kinds directly (that is, without employing a mypy plugin into the tests)?
To Reproduce
Along with
module.py
above, put the following files in any directory, navigate inside the directory, and just runmypy
in the command line:Your Environment
The text was updated successfully, but these errors were encountered: