summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2021-08-03 11:00:55 (GMT)
committerGitHub <noreply@github.com>2021-08-03 11:00:55 (GMT)
commit8c9f847997196aa76500d1ae104cbe7fe2a467ed (patch)
tree6f7b08d25d4ca71d14ac2447e732fcd4b068b76f /Lib/collections
parent83ca46b7784b7357d82ec47b33295e09ed7380cb (diff)
downloadcpython-8c9f847997196aa76500d1ae104cbe7fe2a467ed.zip
cpython-8c9f847997196aa76500d1ae104cbe7fe2a467ed.tar.gz
cpython-8c9f847997196aa76500d1ae104cbe7fe2a467ed.tar.bz2
bpo-27275: Change popitem() and pop() methods of collections.OrderedDict (GH-27530)
* Unify the C and Python implementations of OrderedDict.popitem(). The C implementation no longer calls ``__getitem__`` and ``__delitem__`` methods of the OrderedDict subclasses. * Change popitem() and pop() methods of collections.OrderedDict For consistency with dict both implementations (pure Python and C) of these methods in OrderedDict no longer call __getitem__ and __delitem__ methods of the OrderedDict subclasses. Previously only the Python implementation of popitem() did not call them.
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index bae0805..d989d85 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -236,11 +236,19 @@ class OrderedDict(dict):
is raised.
'''
- if key in self:
- result = self[key]
- del self[key]
+ marker = self.__marker
+ result = dict.pop(self, key, marker)
+ if result is not marker:
+ # The same as in __delitem__().
+ link = self.__map.pop(key)
+ link_prev = link.prev
+ link_next = link.next
+ link_prev.next = link_next
+ link_next.prev = link_prev
+ link.prev = None
+ link.next = None
return result
- if default is self.__marker:
+ if default is marker:
raise KeyError(key)
return default