diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-01-12 08:12:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-12 08:12:24 (GMT) |
commit | f1ec3cefad4639797c37eaa8c074830188fa0a44 (patch) | |
tree | 45310fd762d8b8c71e73ee6e481d9f759c16bd79 /Lib/test/test_extcall.py | |
parent | 58159ef856846d0235e0779aeb6013d70499570d (diff) | |
download | cpython-f1ec3cefad4639797c37eaa8c074830188fa0a44.zip cpython-f1ec3cefad4639797c37eaa8c074830188fa0a44.tar.gz cpython-f1ec3cefad4639797c37eaa8c074830188fa0a44.tar.bz2 |
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.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index 2c18483..a3ff441 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): |