[New-bugs-announce] [issue46838] Parameters and arguments parser syntax error improvments
Andrej Klychin
report at bugs.python.org
Wed Feb 23 16:23:21 EST 2022
New submission from Andrej Klychin <andy_kl at bk.ru>:
I saw that pablogsal welcomed improvments to the parser's suggestions, so here are the messages for parameters and arguments lists I think should be written instead of the current generic "invalid syntax".
>>> def foo(*arg, *arg): pass
SyntaxError: * argument may appear only once
>>> def foo(**arg, **arg): pass
SyntaxError: ** argument may appear only once
>>> def foo(arg1, /, arg2, /, arg3): pass
SyntaxError: / may appear only once
>>> def foo(*args, /, arg): pass
SyntaxError: / must be ahead of *
>>> def foo(/, arg): pass
SyntaxError: at least one argument must precede /
>>> def foo(arg=): pass
SyntaxError: expected default value expression
>>> def foo(*args=None): pass
SyntaxError: * argument cannot have default value
>>> def foo(**kwargs=None): pass
SyntaxError: ** argument cannot have default value
>>> foo(*args=[0])
SyntaxError: cannot assign to iterable argument unpacking
>>> foo(**args={"a": None})
SyntaxError: cannot assign to keyword argument unpacking
>>> foo(arg=)
SyntaxError: expected argument value expression
----------
components: Parser
messages: 413856
nosy: Andy_kl, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Parameters and arguments parser syntax error improvments
type: enhancement
versions: Python 3.11
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46838>
_______________________________________
More information about the New-bugs-announce
mailing list