summaryrefslogtreecommitdiffstats
path: root/Lib/collections
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/collections')
-rw-r--r--Lib/collections/__init__.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 706907a..960d82a 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -1038,6 +1038,13 @@ class UserDict(_collections_abc.MutableMapping):
# Now, add the methods in dicts but not in MutableMapping
def __repr__(self): return repr(self.data)
+ def __copy__(self):
+ inst = self.__class__.__new__(self.__class__)
+ inst.__dict__.update(self.__dict__)
+ # Create a copy and avoid triggering descriptors
+ inst.__dict__["data"] = self.__dict__["data"].copy()
+ return inst
+
def copy(self):
if self.__class__ is UserDict:
return UserDict(self.data.copy())
@@ -1050,6 +1057,7 @@ class UserDict(_collections_abc.MutableMapping):
self.data = data
c.update(self)
return c
+
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
@@ -1118,6 +1126,12 @@ class UserList(_collections_abc.MutableSequence):
def __imul__(self, n):
self.data *= n
return self
+ def __copy__(self):
+ inst = self.__class__.__new__(self.__class__)
+ inst.__dict__.update(self.__dict__)
+ # Create a copy and avoid triggering descriptors
+ inst.__dict__["data"] = self.__dict__["data"][:]
+ return inst
def append(self, item): self.data.append(item)
def insert(self, i, item): self.data.insert(i, item)
def pop(self, i=-1): return self.data.pop(i)