summaryrefslogtreecommitdiffstats
path: root/Lib/_collections_abc.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-27 14:35:26 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-27 14:35:26 (GMT)
commit8943ecfab20168f2b18bc477efb7671e32e91c24 (patch)
tree0a1b17968ff724a5b67e7bf85782c4a417a4ec10 /Lib/_collections_abc.py
parentf25e3bfefa800c20c354843b345644ac80b646a8 (diff)
parentae5cb214d2cd41d96943a0ef43a4e95bd9a10b7a (diff)
downloadcpython-8943ecfab20168f2b18bc477efb7671e32e91c24.zip
cpython-8943ecfab20168f2b18bc477efb7671e32e91c24.tar.gz
cpython-8943ecfab20168f2b18bc477efb7671e32e91c24.tar.bz2
Issue #22609: Constructors and update methods of mapping classes in the
collections module now accept the self keyword argument.
Diffstat (limited to 'Lib/_collections_abc.py')
-rw-r--r--Lib/_collections_abc.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 6935e55..9a84f4a 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -592,23 +592,24 @@ class MutableMapping(Mapping):
If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v
In either case, this is followed by: for k, v in F.items(): D[k] = v
'''
- if len(args) > 2:
- raise TypeError("update() takes at most 2 positional "
- "arguments ({} given)".format(len(args)))
- elif not args:
- raise TypeError("update() takes at least 1 argument (0 given)")
- self = args[0]
- other = args[1] if len(args) >= 2 else ()
-
- if isinstance(other, Mapping):
- for key in other:
- self[key] = other[key]
- elif hasattr(other, "keys"):
- for key in other.keys():
- self[key] = other[key]
- else:
- for key, value in other:
- self[key] = value
+ if not args:
+ raise TypeError("descriptor 'update' of 'MutableMapping' object "
+ "needs an argument")
+ self, *args = args
+ if len(args) > 1:
+ raise TypeError('update expected at most 1 arguments, got %d' %
+ len(args))
+ if args:
+ other = args[0]
+ if isinstance(other, Mapping):
+ for key in other:
+ self[key] = other[key]
+ elif hasattr(other, "keys"):
+ for key in other.keys():
+ self[key] = other[key]
+ else:
+ for key, value in other:
+ self[key] = value
for key, value in kwds.items():
self[key] = value