Skip to content

Commit

Permalink
Fix # 443: remove PKDict.__deepcopy__ and __copy__ and document copy (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rorour authored Mar 20, 2024
1 parent b3bc4c7 commit 77d8f09
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pykern/pkcollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ class PKDict(dict):
only, not general objects.
"""

def __copy__(self):
return self.__class__(self)

def __deepcopy__(self, memo):
rv = self.copy()
for k, v in rv.items():
rv[copy.deepcopy(k, memo)] = copy.deepcopy(v, memo)
return rv

def __delattr__(self, name):
raise PKDictNameError("{}: you cannot delete attributes", name)

Expand All @@ -76,7 +67,16 @@ def __setattr__(self, name, value):
super(PKDict, self).__setitem__(name, value)

def copy(self):
return self.__copy__()
"""Override `dict.copy` to ensure the class of the return object is correct.
Necessary because dict.copy will return a dict rather than PKDict.
Calls `self.__class__(self)` which makes a shallow copy.
Subclasses that do not accept this constructor form will need to override this method.
Returns:
object: shallow copy of self
"""
return self.__class__(self)

def pkdel(self, name, default=None):
"""Delete item if exists and return value
Expand Down

0 comments on commit 77d8f09

Please sign in to comment.