← index #3281Issue #466
Related · high · value 2.234
QUERY · ISSUE

Repeated keyword argument should cause SyntaxError, not TypeError

openby alex-robbinsopened 2017-08-22updated 2024-08-28
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

positional args after kwargs doesn't throw SyntaxError

closedby lurchopened 2014-04-11updated 2014-04-27
enhancement

If I call

def testfun(arg1=1,arg2=2):
    print(arg1,arg2)

as testfun(arg1='one','two') in CPython3.3 it throws SyntaxError: non-keyword arg after keyword arg.
But doing the same in micropython instead throws TypeError: function does not take keyword arguments.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied