bpo-35634: Raise an error when first passed kwargs contains duplicated keys. by serhiy-storchaka · Pull Request #11438 · python/cpython
| @@ -0,0 +1,3 @@ | |||
| ``func(**kwargs)`` will now raise an error when ``kwargs`` is a mapping | |||
| containing multiple entries with the same key. An error was already raised | |||
| when other keyword arguments are passed before ``**kwargs`` since Python 3.6. | |||
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does "other keyword arguments are passed before **kwargs" mean? Error was already raised when there are multiple **kwargs with overlapping keys since PEP 448 was implemented. The change in Python 3.6 was intended for optimization.
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo(**kwargs): pass
...
>>> foo(**{'a': 1}, **{'a': 1})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for keyword argument 'a'
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following cases are errors since 3.6:
g(a=3, **MultiDict([('x', 1), ('x', 2)])) g(**MultiDict([('a', 3)]), **MultiDict([('x', 1), ('x', 2)]))