classification
Title: variable resolution within exec() incorrect
Type: behavior Stage:
Components: None Versions: Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: An inconsistency with nested scopes
View: 991196
Assigned To: Nosy List: hawkett, mark.dickinson
Priority: normal Keywords:

Created on 2010-05-25 16:49 by hawkett, last changed 2010-05-26 08:49 by mark.dickinson. This issue is now closed.

Messages (6)
msg106447 - (view) Author: Colin Hawkett (hawkett) Date: 2010-05-25 16:49
A discussion on stack overflow - http://stackoverflow.com/questions/2904274/globals-and-locals-in-python-exec - has led to the conclusion that the variable lookup behaviour within code run using exec() is not behaving as expected. Variable lookup inside a class definition does not search the enclosing scope's locals() prior to issuing a NameError - there are full details and test cases at the above URL.
msg106451 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-25 17:15
This looks like a duplicate of issue 991196.
msg106464 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-25 18:53
Judging by the issue 991196 discussion, the described behaviour is intentional.  In particular, this behaviour isn't likely to change in Python 2.x:  2.6 is in bugfix only mode, and 2.7 is too close to release to start messing with internals.

You may be able to make an argument that the behaviour should be changed in Python 3.x; that discussion should happen on python-dev or python-ideas rather than on the tracker, though.
msg106510 - (view) Author: Colin Hawkett (hawkett) Date: 2010-05-26 07:09
Agreed, this is the same issue. I'll make my argument that this is a bug (intentional or otherwise) on that issue.
msg106515 - (view) Author: Colin Hawkett (hawkett) Date: 2010-05-26 08:41
Apologies for raising it in the tracker against your advice. My thinking was that you were suggesting discussions about 3.x content shouldn't be in the tracker, and I wanted to argue that it is a bug and should be fixed in 2.6+
msg106516 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-05-26 08:49
Hmm.  To get this changed in 2.x you'd have to convince people that it really is a bug.  You probably also need to do that very soon for there to be any hope of 2.7 having changed behaviour.

I'd suggest bringing this up on the python-dev mailing list;  it'll get better visibility there.  If you can describe exactly what should change (and even better, how that change might be implemented) that would be a bonus.
History
Date User Action Args
2010-05-26 08:49:50mark.dickinsonsetmessages: + msg106516
2010-05-26 08:41:47hawkettsetmessages: + msg106515
2010-05-26 07:09:58hawkettsetmessages: + msg106510
2010-05-25 18:53:02mark.dickinsonsetstatus: open -> closed
resolution: duplicate
superseder: An inconsistency with nested scopes
messages: + msg106464
2010-05-25 17:15:17mark.dickinsonsetnosy: + mark.dickinson
messages: + msg106451
2010-05-25 16:49:06hawkettcreate