Python obviously does not allow the same keyword to appear multiple times in function arguments. Here are 2 code samples to show that point:
def foo(a=None, **kwargs):
pass
Calling this code to produce a SyntaxError:
>>> # Example 1
>>> foo(a=1, a=1)
File "<stdin>", line 1
SyntaxError: keyword argument repeated
Calling this code to produce a TypeError:
>>> # Example 2
>>> foo(1, a=123)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for argument 'a'
Intuitively, I would expect both examples to raise SyntaxErrors.
Why does the first method produce a SyntaxError while the second method produces a TypeError?