summaryrefslogtreecommitdiff
path: root/Lib/test/test_extcall.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2019-01-12 10:12:24 +0200
committerGitHub <noreply@github.com>2019-01-12 10:12:24 +0200
commitf1ec3cefad4639797c37eaa8c074830188fa0a44 (patch)
tree45310fd762d8b8c71e73ee6e481d9f759c16bd79 /Lib/test/test_extcall.py
parent58159ef856846d0235e0779aeb6013d70499570d (diff)
downloadcpython-git-f1ec3cefad4639797c37eaa8c074830188fa0a44.tar.gz
bpo-35634: Raise an error when first passed kwargs contains duplicated keys. (GH-11438)
Diffstat (limited to 'Lib/test/test_extcall.py')
-rw-r--r--Lib/test/test_extcall.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py
index 2c1848337b..a3ff4413ee 100644
--- a/Lib/test/test_extcall.py
+++ b/Lib/test/test_extcall.py
@@ -316,6 +316,52 @@ not function
...
TypeError: dir() got multiple values for keyword argument 'b'
+Test a kwargs mapping with duplicated keys.
+
+ >>> from collections.abc import Mapping
+ >>> class MultiDict(Mapping):
+ ... def __init__(self, items):
+ ... self._items = items
+ ...
+ ... def __iter__(self):
+ ... return (k for k, v in self._items)
+ ...
+ ... def __getitem__(self, key):
+ ... for k, v in self._items:
+ ... if k == key:
+ ... return v
+ ... raise KeyError(key)
+ ...
+ ... def __len__(self):
+ ... return len(self._items)
+ ...
+ ... def keys(self):
+ ... return [k for k, v in self._items]
+ ...
+ ... def values(self):
+ ... return [v for k, v in self._items]
+ ...
+ ... def items(self):
+ ... return [(k, v) for k, v in self._items]
+ ...
+ >>> g(**MultiDict([('x', 1), ('y', 2)]))
+ 1 () {'y': 2}
+
+ >>> g(**MultiDict([('x', 1), ('x', 2)]))
+ Traceback (most recent call last):
+ ...
+ TypeError: g() got multiple values for keyword argument 'x'
+
+ >>> g(a=3, **MultiDict([('x', 1), ('x', 2)]))
+ Traceback (most recent call last):
+ ...
+ TypeError: g() got multiple values for keyword argument 'x'
+
+ >>> g(**MultiDict([('a', 3)]), **MultiDict([('x', 1), ('x', 2)]))
+ Traceback (most recent call last):
+ ...
+ TypeError: g() got multiple values for keyword argument 'x'
+
Another helper function
>>> def f2(*a, **b):