This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Local variable created with reflection cannot be referenced with identifier
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ethan.furman, native_api, r.david.murray
Priority: normal Keywords:

Created on 2013-10-15 15:30 by native_api, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg200004 - (view) Author: Ivan Pozdeev (native_api) * Date: 2013-10-15 15:30
It appears that the interpreter assigns an identifier to local or global scope at compilation time rather than searching locals, then globals (i.e. vars()) at the time of execution.

An example:

>>> def test():
...   vars()['a']=1
...   print(a)
...
>>> test()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in test
NameError: global name 'a' is not defined
>>>
msg200005 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-10-15 16:07
Not really.  But locals() is not reliably modifiable, and the vars documentation also notes this.
msg200033 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-10-16 01:42
Ethan, why did you reopen the issue?  Do you have a different opinion, or was it just an issue-update error?
msg200034 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2013-10-16 02:46
Oops!  Issue update error, I was just adding myself to nosy as it looked like it was still open.

Re-closing.
History
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63467
2013-10-16 02:46:59ethan.furmansetstatus: open -> closed
resolution: not a bug
messages: + msg200034

stage: resolved
2013-10-16 01:42:54r.david.murraysetmessages: + msg200033
2013-10-15 22:50:11ethan.furmansetstatus: closed -> open
nosy: + ethan.furman

resolution: not a bug -> (no value)
stage: resolved -> (no value)
2013-10-15 16:07:51r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg200005

resolution: not a bug
stage: resolved
2013-10-15 15:30:41native_apicreate