mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
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.
This commit is contained in:
parent
6c79a518e7
commit
31017aed36
11 changed files with 92 additions and 56 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue