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 Keepun
Recipients Keepun
Date 2021-03-09.15:42:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1615304578.57.0.704046890189.issue43448@roundup.psfhosted.org>
In-reply-to
Content
exec() ignores scope.

Code:
--------------------------
class ExecTest:
    def public(self):
        h=None
        exec("h='It is public'")
        print(h)
        self._private()
    def _private(self):
        h=None
        exec("h='It is private'", globals(), locals())
        print(h)

h = None
exec("h='It is global'")
print(h)

e=ExecTest()
e.public()

Result
--------------------------
It is global
None
None

--------------------------
Python 3.7.10 (default, Feb 26 2021, 13:06:18) [MSC v.1916 64 bit (AMD64)]
and
Python 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]
History
Date User Action Args
2021-03-09 15:42:58Keepunsetrecipients: + Keepun
2021-03-09 15:42:58Keepunsetmessageid: <1615304578.57.0.704046890189.issue43448@roundup.psfhosted.org>
2021-03-09 15:42:58Keepunlinkissue43448 messages
2021-03-09 15:42:58Keepuncreate