Message60907
>>> class mydict(dict):
... def __getitem__(self, key):
... return 17
...
>>> class blah(object):
... def __init__(self):
... self.__dict__ = mydict()
...
>>> b = blah()
>>> print b.x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'blah' object has no attribute 'x'
python doesn't call the overriden version of __getitem__.
i've done several more tests, and the cause to this
problem, afaik, is that the code assumes __dict__ is an
instance of dict, so it directly uses PyDict_GetItem
(or whatever it's called), thus skipping the overriden
method.
python should either disable setting __dict__ to
anything that is not a real dict (type(x) == dict
instead of isinstance(x, dict)), or be willing to call
overriden methods. |
|
Date |
User |
Action |
Args |
2008-01-20 09:58:41 | admin | link | issue1475692 messages |
2008-01-20 09:58:41 | admin | create | |
|