QUERY · ISSUE
Repeated keyword argument should cause SyntaxError, not TypeError
bug
CPython:
>>> def f(x): pass
...
>>> f(x=1, x=1)
File "<stdin>", line 1
SyntaxError: keyword argument repeated
MicroPython:
>>> def f(x): pass
...
>>> f(x=1, x=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: function got multiple values for argument 'x'
Nitpicky? Yes. But I doubt fixing this would change code size, so...
See also #466. I would have submitted a patch instead of an issue, but it looks like that exception can be raised from two different places, and I don't know the difference.
Thanks,
Alex
CANDIDATE · ISSUE
unix: "function does not take keyword arguments" message can mislead
If function kw arguments are supplied from a dict, and the dict (erroneously) contains unexpected arguments, the above error message is rather misleading.
d = {'argument' : 'A', 'bar' : 0}
def foo(*, bar=False):
print('foo')
foo(**d)
Cpython produces the self-evident
>>> foo(**d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() got an unexpected keyword argument 'argument'
>>>