Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue40196

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:symtable.Symbol.is_local() can be True for global symbols
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: pablogsalNosy List: coproc, miss-islington, pablogsal
Priority:normalKeywords:patch

Created on2020-04-05 13:30 bycoproc, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
global_and_local.pycoproc,2020-04-05 13:30console output (as in comment) shows that for global symbol 'e' also is_local() returns True
Pull Requests
URLStatusLinkedEdit
PR 19391mergedpablogsal,2020-04-06 10:06
PR 19394mergedmiss-islington,2020-04-06 16:06
PR 19395mergedmiss-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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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
DateUserActionArgs
2022-04-11 14:59:29adminsetgithub: 84377
2020-04-06 16:42:07pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-04-06 16:41:59pablogsalsetmessages: +msg365871
2020-04-06 16:41:32miss-islingtonsetmessages: +msg365870
2020-04-06 16:06:50miss-islingtonsetpull_requests: +pull_request18757
2020-04-06 16:06:41miss-islingtonsetnosy: +miss-islington
pull_requests: +pull_request18756
2020-04-06 16:06:04pablogsalsetmessages: +msg365868
2020-04-06 13:35:19pablogsalsetmessages: +msg365855
2020-04-06 13:33:56pablogsalsetmessages: -msg365854
2020-04-06 13:33:08pablogsalsetmessages: +msg365854
2020-04-06 13:28:36coprocsetmessages: +msg365853
2020-04-06 10:07:07pablogsalsetmessages: +msg365845
2020-04-06 10:06:55pablogsalsetmessages: -msg365843
2020-04-06 10:06:05pablogsalsetkeywords: +patch
stage: patch review
pull_requests: +pull_request18753
2020-04-06 09:49:56pablogsalsetmessages: +msg365843
2020-04-06 08:33:27pablogsalsetassignee:pablogsal

nosy: +pablogsal
2020-04-05 13:34:28coprocsettype: behavior
messages: +msg365821
2020-04-05 13:30:26coproccreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp