[New-bugs-announce] [issue34882] f(a=1, *args) should be a SyntaxError

metaxm report at bugs.python.org
Wed Oct 3 04:01:12 EDT 2018


New submission from metaxm <metaxm at gmail.com>:

>>> def f(a, b, c):
...     pass
>>> f(a=1, 2, 3)
SyntaxError: positional argument follows keyword argument
>>> f(a=1, *(2, 3))
TypeError: f() got multiple values for argument 'a'


f(a=1, 2, 3) will cause a SyntaxError, but f(a=1, *(2, 3)) will cause a TypeError. This makes me feel confused.

As keyword arguments must follow positional arguments, I suppose a SyntaxError rather than a TypeError should be reported if a variadic argument follows keyword arguments. Would you kindly explain why the CPython takes different actions for these two cases?

----------
components: Interpreter Core
messages: 326945
nosy: metaxm
priority: normal
severity: normal
status: open
title: f(a=1, *args) should be a SyntaxError
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34882>
_______________________________________


More information about the New-bugs-announce mailing list