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 ronaldoussoren
Recipients Huyston, Krishna Oza, ronaldoussoren
Date 2019-10-01.20:28:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1569961722.92.0.434496977098.issue38331@roundup.psfhosted.org>
In-reply-to
Content
I don't think this is a bug.

def func():
   print(var)

This captures the globals at the time of definition, that is "global" references are resolved using the func.__globals__ attribute which is the globals dictionary at the time the function is created

exec("func()", globals=my_globals;locals=my_globals)

This runs code with a different globals dictionary, but that doesn't affect the already defined function because it resolves names with the previously captured globals dictionary.

This is basically the mechanism that ensures that functions defined in a module use that modules global namespace, and not the globals from where they are called.
History
Date User Action Args
2019-10-01 20:28:42ronaldoussorensetrecipients: + ronaldoussoren, Krishna Oza, Huyston
2019-10-01 20:28:42ronaldoussorensetmessageid: <1569961722.92.0.434496977098.issue38331@roundup.psfhosted.org>
2019-10-01 20:28:42ronaldoussorenlinkissue38331 messages
2019-10-01 20:28:42ronaldoussorencreate