Skip to content
Snippets Groups Projects
Commit 211a5ef2 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

generic __copy__ fixes

parent 4f63567e
No related branches found
No related tags found
No related merge requests found
...@@ -276,7 +276,7 @@ class TwoWayDictionary(collections.abc.MutableMapping, tp.Generic[K, V]): ...@@ -276,7 +276,7 @@ class TwoWayDictionary(collections.abc.MutableMapping, tp.Generic[K, V]):
return self._reverse return self._reverse
class DirtyDict(collections.UserDict): class DirtyDict(collections.UserDict, tp.Generic[K, V]):
""" """
A dictionary that has also a flag called .dirty that sets to True if the dictionary has been A dictionary that has also a flag called .dirty that sets to True if the dictionary has been
changed since that flag was last cleared. changed since that flag was last cleared.
...@@ -289,6 +289,11 @@ class DirtyDict(collections.UserDict): ...@@ -289,6 +289,11 @@ class DirtyDict(collections.UserDict):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.dirty = False self.dirty = False
def __copy__(self):
dd = DirtyDict(self.data.copy())
dd.dirty = self.dirty
return dd
def __setitem__(self, key: K, value: V) -> None: def __setitem__(self, key: K, value: V) -> None:
if key in self: if key in self:
if self[key] == value: if self[key] == value:
...@@ -305,7 +310,11 @@ class DirtyDict(collections.UserDict): ...@@ -305,7 +310,11 @@ class DirtyDict(collections.UserDict):
self.dirty = False self.dirty = False
def copy_and_clear_dirty(self) -> tp.Dict[K, V]: def copy_and_clear_dirty(self) -> tp.Dict[K, V]:
"""Returns a copy of self and clears the dirty flag""" """
a = self.copy() Returns a copy of self and clears the dirty flag
:return: a plain, normal Python dictionary is returned
"""
a = self.data.copy()
self.dirty = False self.dirty = False
return a return a
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment