diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-15 16:54:52 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-05-15 16:54:52 +0000 |
commit | 775fd66d7bd74cdedef536ff4f8c134ba718678f (patch) | |
tree | 4f0f3a10518bb130dd9000fda2f1f5b2e4899d5f /Lib/weakref.py | |
parent | 52035a04abc8b75c1481064639150e4089cd80c7 (diff) | |
download | cpython-git-775fd66d7bd74cdedef536ff4f8c134ba718678f.tar.gz |
Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r-- | Lib/weakref.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index 78b74ad320..84d81a2734 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -85,6 +85,17 @@ class WeakValueDictionary(UserDict.UserDict): new[key] = o return new + __copy__ = copy + + def __deepcopy__(self, memo): + from copy import deepcopy + new = self.__class__() + for key, wr in self.data.items(): + o = wr() + if o is not None: + new[deepcopy(key, memo)] = o + return new + def get(self, key, default=None): try: wr = self.data[key] @@ -256,6 +267,17 @@ class WeakKeyDictionary(UserDict.UserDict): new[o] = value return new + __copy__ = copy + + def __deepcopy__(self, memo): + from copy import deepcopy + new = self.__class__() + for key, value in self.data.items(): + o = key() + if o is not None: + new[o] = deepcopy(value, memo) + return new + def get(self, key, default=None): return self.data.get(ref(key),default) |