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.
Created on 2007年06月04日 03:59 by blakeross, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg32207 - (view) | Author: Blake Ross (blakeross) | Date: 2007年06月04日 03:59 | |
>>> class MyDict(dict):
... def keys(self): print "keys"
... def __getitem__(self, n): print "__getitem__"
...
>>> myDict = MyDict(a=1, b=2)
>>> dict(myDict)
{'a': 1, 'b': 2}
PyDict_Merge accesses the items of the dict to be merged directly rather than going through the interface for any dict instance--even a dict derivative--by virtue of using PyDict_Check rather than PyDict_CheckExact. I believe the logic needs to be:
if type(d).__getitem__ is dict.__getitem__ and type(d).keys is dict.keys:
...okay to access items directly...
else:
...go through the methods...
|
|||
| msg85623 - (view) | Author: Daniel Diniz (ajaksu2) * (Python triager) | Date: 2009年04月06日 09:41 | |
IIRC, the same behavior is present for subclasses of other builtin types. |
|||
| msg113372 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2010年08月09日 04:02 | |
It is documented that access to special methods is more direct than normal path. This is not going to change. A similar example was discussed on python-list earlier this year with the above conclusion. |
|||
| msg113627 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2010年08月11日 20:24 | |
I concur with Terry. This is just a fact of life when subclassing builtins. The objects are "open-for-extension, closed-for-modification". If you want more direct control use UserDict. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:24 | admin | set | github: 45034 |
| 2010年08月11日 20:24:29 | rhettinger | set | nosy:
+ rhettinger messages: + msg113627 |
| 2010年08月09日 04:02:30 | terry.reedy | set | status: open -> closed nosy: + terry.reedy messages: + msg113372 resolution: rejected |
| 2009年04月06日 09:41:55 | ajaksu2 | set | versions:
+ Python 3.1, Python 2.7 nosy: + ajaksu2 messages: + msg85623 type: enhancement stage: test needed |
| 2007年06月04日 03:59:53 | blakeross | create | |