Message159099
```
class Foo1(dict):
def __getattr__(self, key): return self[key]
def __setattr__(self, key, value): self[key] = value
class Foo2(dict):
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
o1 = Foo1()
o1.x = 42
print(o1, o1.x)
o2 = Foo2()
o2.x = 42
print(o2, o2.x)
```
With CPython 2.5, 2.6 (similarly in 3.2), I get:
({'x': 42}, 42)
({}, 42)
With PyPy 1.5.0, I get the expected output::
({'x': 42}, 42)
({'x': 42}, 42)
I asked this also on SO: http://stackoverflow.com/questions/6305267/python-inconsistence-in-the-way-you-define-the-function-setattr
From the answers, I am not exactly sure wether this is considered as a bug in CPython or not. Anyway, I just wanted to post this here. |
|
Date |
User |
Action |
Args |
2012-04-23 22:53:33 | Albert.Zeyer | set | recipients:
+ Albert.Zeyer |
2012-04-23 22:53:33 | Albert.Zeyer | set | messageid: <1335221613.52.0.779214050633.issue14658@psf.upfronthosting.co.za> |
2012-04-23 22:53:32 | Albert.Zeyer | link | issue14658 messages |
2012-04-23 22:53:32 | Albert.Zeyer | create | |
|