Message310810
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. |
|
Date |
User |
Action |
Args |
2018-01-26 22:21:00 | terry.reedy | set | recipients:
+ terry.reedy, ppperry |
2018-01-26 22:21:00 | terry.reedy | set | messageid: <1517005260.03.0.467229070634.issue32615@psf.upfronthosting.co.za> |
2018-01-26 22:21:00 | terry.reedy | link | issue32615 messages |
2018-01-26 22:20:59 | terry.reedy | create | |
|