Issue1475692
Created on 2006-04-24 17:45 by gangesmaster, last changed 2009-09-08 15:25 by r.david.murray.
|
msg60907 - (view) |
Author: ganges master (gangesmaster) |
Date: 2006-04-24 17:45 |
|
>>> 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.
|
|
msg83910 - (view) |
Author: Daniel Diniz (ajaksu2) |
Date: 2009-03-21 02:20 |
|
Confirmed, is this a valid issue?
|
|
msg92419 - (view) |
Author: R. David Murray (r.david.murray) |
Date: 2009-09-08 15:25 |
|
2.5 and 2.4 are in security-fix-only mode, so we don't set them in
versions since bugs won't get fixed there.
I don't think overridden methods should be called, since that would slow
down attribute lookup, which is already a bottleneck in Python. Whether
there should be an error message is a more complicated question, and I'd
have to look at how this is implemented to even have an opinion on that.
|
|
| Date |
User |
Action |
Args |
| 2009-09-08 15:25:50 | r.david.murray | set | priority: normal -> low versions:
+ Python 2.6, Python 3.2, - Python 2.5, Python 2.4 nosy:
+ r.david.murray
messages:
+ msg92419
|
| 2009-09-08 14:59:03 | matthieu.labbe | set | type: feature request -> behavior |
| 2009-09-08 14:57:22 | matthieu.labbe | set | nosy:
+ matthieu.labbe
versions:
+ Python 2.5, Python 2.4 |
| 2009-03-21 02:20:55 | ajaksu2 | set | versions:
+ Python 3.1, Python 2.7, - Python 2.4 nosy:
+ ajaksu2
messages:
+ msg83910
type: feature request stage: test needed |
| 2006-04-24 17:45:28 | gangesmaster | create | |
|