Repeated keyword argument should cause SyntaxError, not TypeError
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
py: Confusing error message when function passed a keyword arg that's not expected
Consider this code snippet:
def f(x):
pass
f(y=1)
Errors reported are:
- In CPython:
TypeError: f() got an unexpected keyword argument 'y' - In uPy:
TypeError: function does not take keyword arguments
I hit this when calling a user-defined function and was very confused because all user-defined functions accept keyword arguments (only built-in ones may not accept kw args). IMO the error message should at least be changed to be less confusing, but if we can spare bytes it should report which particular kw arg is causing the problem (and that's quite a simple change since at that point in the code it is known what the kw is that couldn't be found).