[issue40196] symtable.Symbol.is_local() can be True for global symbols

2020-04-05 Thread Wolfgang Stöcher

New submission from Wolfgang Stöcher :

Consider this function:

def f():
global e
e = 1

When inspecting symbols with symtable, symbol 'e' will be global and local, 
whereas is_local() should return False. See the attached file for reproducing. 
It will output to stdout:

symbol 'e' in function scope: is_global() = True, is_local() = True
global scope: e = 1

--
components: Library (Lib)
files: global_and_local.py
messages: 365820
nosy: coproc
priority: normal
severity: normal
status: open
title: symtable.Symbol.is_local() can be True for global symbols
versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49037/global_and_local.py

___
Python tracker 
<https://bugs.python.org/issue40196>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40196] symtable.Symbol.is_local() can be True for global symbols

2020-04-05 Thread Wolfgang Stöcher

Wolfgang Stöcher  added the comment:

see https://stackoverflow.com/a/61040435/1725562 for a proposed fix

--
type:  -> behavior

___
Python tracker 
<https://bugs.python.org/issue40196>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40196] symtable.Symbol.is_local() can be True for global symbols

2020-04-06 Thread Wolfgang Stöcher

Wolfgang Stöcher  added the comment:

In symtable.Function.get_locals() symbols with scopes in (LOCAL, CELL) are 
selected. Also

>>> 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.CELL
True

So I guess this would be the correct fix then:

def is_local(self):
return self.__scope in (LOCAL, CELL)

--

___
Python tracker 
<https://bugs.python.org/issue40196>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com