[issue40196] symtable.Symbol.is_local() can be True for global symbols
Pablo Galindo Salgado
report at bugs.python.org
Mon Apr 6 05:49:57 EDT 2020
Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:
>>> code2 = """\
... def foo():
... x = 42
... def bar():
... return -1
... """
>>> top.get_children()[0]
<Function SymbolTable for foo in ?>
>>> top = symtable.symtable(code2, "?", "exec")
>>> top.get_children()[0].lookup('x')._Symbol__scope == symtable.LOCAL
True
but if we return x from bar:
That fix is not correct. For instance consider:
>>> code = """\
... def foo():
... x = 42
... def bar():
... return x
... """
>>> import symtable
>>> top = symtable.symtable(code, "?", "exec")
>>> top.get_children()[0].lookup('x')._Symbol__scope == symtable.LOCAL
False
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40196>
_______________________________________
More information about the Python-bugs-list
mailing list