Message310388
Take the following code:
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())
This should consitently either call or not call the overridden methods on the dictionary, producing either no output or:
set foo
get foo
get qyz
get foo
get foo
set K
get foo
set g
get g
set f
get f
Instead, only sometime the override gets called, producing
set foo
get foo
get qyz
set K
get foo
set g
get g
get f
meaning that
(a) modifications of global variables via global statements
(b) code at class-level
ignore overridden methods, whereas everything else follows them |
|
Date |
User |
Action |
Args |
2018-01-21 23:46:26 | ppperry | set | recipients:
+ ppperry |
2018-01-21 23:46:26 | ppperry | set | messageid: <1516578386.14.0.467229070634.issue32615@psf.upfronthosting.co.za> |
2018-01-21 23:46:26 | ppperry | link | issue32615 messages |
2018-01-21 23:46:25 | ppperry | create | |
|