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 terry.reedy
Recipients ppperry, terry.reedy
Date 2018-01-26.22:20:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1517005260.03.0.467229070634.issue32615@psf.upfronthosting.co.za>
In-reply-to
Content
I did take the code, and it would not run because of the indent.  With that fixed, it still did not run because the the indent in the quoted code fed to exec.  This does run:

import builtins
class K(dict):
    def __getitem__(self, k):
            if k not in builtins.__dict__:
                    print("get %s" % k)
            return dict.__getitem__(self, k)
    def __setitem__(self, k, v):
            print("set %s" % k)
            dict.__setitem__(self, k, v)
exec("""
foo = "bar"
foo
try:
    qyz
except NameError:
    pass
class K:
    baz = foo
    def f(ggg=foo): pass
def g(ggg=foo):
    global f
    f = 87
    f
g()
""", K())

When I run in IDLE, which execs the entire code, so none is run at module level, I get the same result.  The same is true running directly in Python after wrapping the entire code with

exec('''
# and
''')

In this case, nothing other than the outer exec is run at module level.  So I am not sure there is a bug.  If you don't get a more definitive response here, I suggest posting to python-list for opinions on whether bug or feature.
History
Date User Action Args
2018-01-26 22:21:00terry.reedysetrecipients: + terry.reedy, ppperry
2018-01-26 22:21:00terry.reedysetmessageid: <1517005260.03.0.467229070634.issue32615@psf.upfronthosting.co.za>
2018-01-26 22:21:00terry.reedylinkissue32615 messages
2018-01-26 22:20:59terry.reedycreate