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

2020-04-06 Thread Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
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 miss-islington


miss-islington  added the comment:


New changeset 717f1668b3455b498424577e194719f9beae13a1 by Miss Islington (bot) 
in branch '3.7':
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables 
(GH-19391)
https://github.com/python/cpython/commit/717f1668b3455b498424577e194719f9beae13a1


--

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 8bd84e7f79a6cc7670a89a92edba3015aa781758 by Miss Islington (bot) 
in branch '3.8':
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables 
(GH-19391) (GH-19394)
https://github.com/python/cpython/commit/8bd84e7f79a6cc7670a89a92edba3015aa781758


--

___
Python tracker 

___
___
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 miss-islington


Change by miss-islington :


--
pull_requests: +18757
pull_request: https://github.com/python/cpython/pull/19395

___
Python tracker 

___
___
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 miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +18756
pull_request: https://github.com/python/cpython/pull/19394

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 799d7d61a91eb0ad3256ef9a45a90029cef93b7c by Pablo Galindo in 
branch 'master':
bpo-40196: Fix a bug in the symtable when reporting inspecting global variables 
(GH-19391)
https://github.com/python/cpython/commit/799d7d61a91eb0ad3256ef9a45a90029cef93b7c


--

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

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

Thanks for pointing that out. I will simplify PR 19391.

--

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
Removed message: https://bugs.python.org/msg365854

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

I prefer to explicitly check for absence of the global scope as in PR 19391

--

___
Python tracker 

___
___
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 

___
___
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 Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
Removed message: https://bugs.python.org/msg365843

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

That fix is not correct. For instance consider:

>>> code2 = """\
... def foo():
...x = 42
...def bar():
...   return -1
... """
>>> top.get_children()[0]

>>> top = symtable.symtable(code2, "?", "exec")
>>> top.get_children()[0].lookup('x')._Symbol__scope == symtable.LOCAL
True

but if we return x from bar:

>>> 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 

___
___
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 Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
keywords: +patch
pull_requests: +18753
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19391

___
Python tracker 

___
___
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 Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:

>>> code2 = """\
... def foo():
...x = 42
...def bar():
...   return -1
... """
>>> top.get_children()[0]

>>> 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 

___
___
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 Pablo Galindo Salgado


Change by Pablo Galindo Salgado :


--
assignee:  -> pablogsal
nosy: +pablogsal

___
Python tracker 

___
___
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 

___
___
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

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 

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