diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-04 08:25:44 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-04 08:25:44 (GMT) |
commit | 31017aed36a5c5b0e4b16ca58bea09c9ce360134 (patch) | |
tree | 766d70bb4fbb6878a71c81fc3874515cfcbc8aa8 /Lib/weakref.py | |
parent | 6c79a518e70ea8e45e3287573d99c648ae3cb21b (diff) | |
download | cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.zip cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.tar.gz cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.tar.bz2 |
SF #904720: dict.update should take a 2-tuple sequence like dict.__init_
(Championed by Bob Ippolito.)
The update() method for mappings now accepts all the same argument forms
as the dict() constructor. This includes item lists and/or keyword
arguments.
Diffstat (limited to 'Lib/weakref.py')
-rw-r--r-- | Lib/weakref.py | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/Lib/weakref.py b/Lib/weakref.py index 09bed65..5c66186 100644 --- a/Lib/weakref.py +++ b/Lib/weakref.py @@ -122,10 +122,15 @@ class WeakValueDictionary(UserDict.UserDict): else: return wr() - def update(self, dict): + def update(self, dict=None, **kwargs): d = self.data - for key, o in dict.items(): - d[key] = ref(o, self.__makeremove(key)) + if dict is not None: + if not hasattr(dict, "items"): + dict = type({})(dict) + for key, o in dict.items(): + d[key] = ref(o, self.__makeremove(key)) + if len(kwargs): + self.update(kwargs) def values(self): L = [] @@ -239,10 +244,15 @@ class WeakKeyDictionary(UserDict.UserDict): def setdefault(self, key, default): return self.data.setdefault(ref(key, self._remove),default) - def update(self, dict): + def update(self, dict=None, **kwargs): d = self.data - for key, value in dict.items(): - d[ref(key, self._remove)] = value + if dict is not None: + if not hasattr(dict, "items"): + dict = type({})(dict) + for key, value in dict.items(): + d[ref(key, self._remove)] = value + if len(kwargs): + self.update(kwargs) class BaseIter: |