This is the corresponding bit from grammar :
arglist: (argument ',')* (argument [','] |'*' test (',' argument)* [',' '**' test] |'**' test)
The first line allows you to put a comma after the last parameter when varargs / kwargs is not used (this is why your first example works). However, you are not allowed to put a comma after the kwargs parameter if it is specified, as shown in the second and third lines.
By the way, here is an interesting thing shown by grammar:
They are legal:
f(a=1, b=2, c=3,) f(*v, a=1, b=2, c=3)
but this is not so:
f(*v, a=1, b=2, c=3,)
It makes sense not to allow a comma after **kwargs , since it should always be the last parameter. I donโt know why the language designers decided not to allow my last example - perhaps supervision?
interjay
source share