mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Clear cyclical references in list based OrderedDict.
This commit is contained in:
parent
6caf7ff505
commit
3928276e64
1 changed files with 11 additions and 3 deletions
|
@ -67,8 +67,10 @@ class OrderedDict(dict, MutableMapping):
|
||||||
PREV = 0
|
PREV = 0
|
||||||
NEXT = 1
|
NEXT = 1
|
||||||
link = self.__map.pop(key)
|
link = self.__map.pop(key)
|
||||||
link[PREV][NEXT] = link[NEXT]
|
link_prev = link[PREV]
|
||||||
link[NEXT][PREV] = link[PREV]
|
link_next = link[NEXT]
|
||||||
|
link_prev[NEXT] = link_next
|
||||||
|
link_next[PREV] = link_prev
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
'od.__iter__() <==> iter(od)'
|
'od.__iter__() <==> iter(od)'
|
||||||
|
@ -103,7 +105,11 @@ class OrderedDict(dict, MutableMapping):
|
||||||
return (self.__class__, (items,), inst_dict)
|
return (self.__class__, (items,), inst_dict)
|
||||||
return self.__class__, (items,)
|
return self.__class__, (items,)
|
||||||
|
|
||||||
clear = MutableMapping.clear
|
def clear(self):
|
||||||
|
'od.clear() -> None. Remove all items from od.'
|
||||||
|
for k in dict.keys(self):
|
||||||
|
del self[k]
|
||||||
|
|
||||||
setdefault = MutableMapping.setdefault
|
setdefault = MutableMapping.setdefault
|
||||||
update = MutableMapping.update
|
update = MutableMapping.update
|
||||||
pop = MutableMapping.pop
|
pop = MutableMapping.pop
|
||||||
|
@ -157,6 +163,8 @@ class OrderedDict(dict, MutableMapping):
|
||||||
all(_imap(_eq, self.iteritems(), other.iteritems()))
|
all(_imap(_eq, self.iteritems(), other.iteritems()))
|
||||||
return dict.__eq__(self, other)
|
return dict.__eq__(self, other)
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.clear() # eliminate cyclical references
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue