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 qpeter
Recipients eryksun, qpeter, steven.daprano
Date 2021-12-23.14:07:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1640268474.81.0.0668232231038.issue46153@roundup.psfhosted.org>
In-reply-to
Content
Maybe a note could be added to https://docs.python.org/3/library/functions.html#exec

Something along the lines of:

Note: If exec gets two separate objects as `globals` and `locals`, the code will not be executed as if it were embedded in a function definition. For example, any function or comprehension defined at the top level will not have access to the `locals` scope.

PS: It would be nice for my usecase to have a way around this, maybe a flag in `compile` or `exec` that would produce "function code" instead of "module code". My workaround for this problem consist in wrapping my code in a function definition.

I think this means https://bugs.python.org/issue41918 should be closed as well?
History
Date User Action Args
2021-12-23 14:07:54qpetersetrecipients: + qpeter, steven.daprano, eryksun
2021-12-23 14:07:54qpetersetmessageid: <1640268474.81.0.0668232231038.issue46153@roundup.psfhosted.org>
2021-12-23 14:07:54qpeterlinkissue46153 messages
2021-12-23 14:07:54qpetercreate