[ python-Bugs-1730480 ] dict init/update accesses internal items of dict derivative

SourceForge.net noreply at sourceforge.net
Mon Jun 4 06:00:58 CEST 2007


Bugs item #1730480, was opened at 2007-06-03 20:59
Message generated for change (Settings changed) made by blakeross
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1730480&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Blake Ross (blakeross)
Assigned to: Nobody/Anonymous (nobody)
>Summary: dict init/update accesses internal items of dict derivative

Initial Comment:
>>> 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...


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1730480&group_id=5470


More information about the Python-bugs-list mailing list