
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2020-04-05 13:30 bycoproc, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| global_and_local.py | coproc,2020-04-05 13:30 | console output (as in comment) shows that for global symbol 'e' also is_local() returns True | ||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 19391 | merged | pablogsal,2020-04-06 10:06 | |
| PR 19394 | merged | miss-islington,2020-04-06 16:06 | |
| PR 19395 | merged | miss-islington,2020-04-06 16:06 | |
| Messages (8) | |||
|---|---|---|---|
| msg365820 -(view) | Author: Wolfgang Stöcher (coproc) | Date: 2020-04-05 13:30 | |
Consider this function:def f():global ee = 1When 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() = Trueglobal scope: e = 1 | |||
| msg365821 -(view) | Author: Wolfgang Stöcher (coproc) | Date: 2020-04-05 13:34 | |
seehttps://stackoverflow.com/a/61040435/1725562 for a proposed fix | |||
| msg365845 -(view) | Author: Pablo Galindo Salgado (pablogsal)*![]() | Date: 2020-04-06 10:07 | |
That fix is not correct. For instance consider:>>> 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.LOCALTruebut 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.LOCALFalse | |||
| msg365853 -(view) | Author: Wolfgang Stöcher (coproc) | Date: 2020-04-06 13:28 | |
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.CELLTrueSo I guess this would be the correct fix then:def is_local(self): return self.__scope in (LOCAL, CELL) | |||
| msg365855 -(view) | Author: Pablo Galindo Salgado (pablogsal)*![]() | Date: 2020-04-06 13:35 | |
> In symtable.Function.get_locals() symbols with scopes in (LOCAL, CELL) are selected.Thanks for pointing that out. I will simplifyPR 19391. | |||
| msg365868 -(view) | Author: Pablo Galindo Salgado (pablogsal)*![]() | Date: 2020-04-06 16:06 | |
New changeset799d7d61a91eb0ad3256ef9a45a90029cef93b7c 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 | |||
| msg365870 -(view) | Author: miss-islington (miss-islington) | Date: 2020-04-06 16:41 | |
New changeset717f1668b3455b498424577e194719f9beae13a1 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 | |||
| msg365871 -(view) | Author: Pablo Galindo Salgado (pablogsal)*![]() | Date: 2020-04-06 16:41 | |
New changeset8bd84e7f79a6cc7670a89a92edba3015aa781758 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 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:29 | admin | set | github: 84377 |
| 2020-04-06 16:42:07 | pablogsal | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2020-04-06 16:41:59 | pablogsal | set | messages: +msg365871 |
| 2020-04-06 16:41:32 | miss-islington | set | messages: +msg365870 |
| 2020-04-06 16:06:50 | miss-islington | set | pull_requests: +pull_request18757 |
| 2020-04-06 16:06:41 | miss-islington | set | nosy: +miss-islington pull_requests: +pull_request18756 |
| 2020-04-06 16:06:04 | pablogsal | set | messages: +msg365868 |
| 2020-04-06 13:35:19 | pablogsal | set | messages: +msg365855 |
| 2020-04-06 13:33:56 | pablogsal | set | messages: -msg365854 |
| 2020-04-06 13:33:08 | pablogsal | set | messages: +msg365854 |
| 2020-04-06 13:28:36 | coproc | set | messages: +msg365853 |
| 2020-04-06 10:07:07 | pablogsal | set | messages: +msg365845 |
| 2020-04-06 10:06:55 | pablogsal | set | messages: -msg365843 |
| 2020-04-06 10:06:05 | pablogsal | set | keywords: +patch stage: patch review pull_requests: +pull_request18753 |
| 2020-04-06 09:49:56 | pablogsal | set | messages: +msg365843 |
| 2020-04-06 08:33:27 | pablogsal | set | assignee:pablogsal nosy: +pablogsal |
| 2020-04-05 13:34:28 | coproc | set | type: behavior messages: +msg365821 |
| 2020-04-05 13:30:26 | coproc | create | |