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 gangesmaster
Recipients
Date 2006-04-24.17:45:28
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
>>> 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.
History
Date User Action Args
2008-01-20 09:58:41adminlinkissue1475692 messages
2008-01-20 09:58:41admincreate