summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2023-08-21 09:49:08 (GMT)
committerGitHub <noreply@github.com>2023-08-21 09:49:08 (GMT)
commit20cc90c0df3e368fe7cb63d958f0b17a78fa9d0a (patch)
treea1d5d29060046a334d76a88de119dcd5f0cef316 /Lib/collections
parent014a5b71e7538926ae1c03c8c5ea13c96e741be3 (diff)
downloadcpython-20cc90c0df3e368fe7cb63d958f0b17a78fa9d0a.zip
cpython-20cc90c0df3e368fe7cb63d958f0b17a78fa9d0a.tar.gz
cpython-20cc90c0df3e368fe7cb63d958f0b17a78fa9d0a.tar.bz2
gh-105736: Sync pure python version of OrderedDict with the C version (#108098)
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 03ca2d7..8652dc8 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -95,17 +95,19 @@ class OrderedDict(dict):
# Individual links are kept alive by the hard reference in self.__map.
# Those hard references disappear when a key is deleted from an OrderedDict.
+ def __new__(cls, /, *args, **kwds):
+ "Create the ordered dict object and set up the underlying structures."
+ self = dict.__new__(cls)
+ self.__hardroot = _Link()
+ self.__root = root = _proxy(self.__hardroot)
+ root.prev = root.next = root
+ self.__map = {}
+ return self
+
def __init__(self, other=(), /, **kwds):
'''Initialize an ordered dictionary. The signature is the same as
regular dictionaries. Keyword argument order is preserved.
'''
- try:
- self.__root
- except AttributeError:
- self.__hardroot = _Link()
- self.__root = root = _proxy(self.__hardroot)
- root.prev = root.next = root
- self.__map = {}
self.__update(other, **kwds)
def __setitem__(self, key, value,