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.

Author Chris Billington
Recipients Chris Billington
Date 2019-11-29.15:36:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1575041797.51.0.388884498792.issue38937@roundup.psfhosted.org>
In-reply-to
Content
Sorry for the spamming, realised I misunderstood further.

The original behaviour isn't because the exec'd code can't create new local variables - it can - it's because of the documented behaviour of exec when it gets different dicts for globals and locals:

"If exec gets two separate objects as globals and locals, the code will be executed as if it were embedded in a class definition"

So the new scope made by the list comprehension can't access the enclosing scope in which the new variable was defined, because that's how scoping works in class definitions.
History
Date User Action Args
2019-11-29 15:36:37Chris Billingtonsetrecipients: + Chris Billington
2019-11-29 15:36:37Chris Billingtonsetmessageid: <1575041797.51.0.388884498792.issue38937@roundup.psfhosted.org>
2019-11-29 15:36:37Chris Billingtonlinkissue38937 messages
2019-11-29 15:36:37Chris Billingtoncreate