mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-91210: Improve error message when non-default param follows default (GH-95933)
- Improve error message when parameter without a default follows one with a default - Show same error message when positional-only params precede the default/non-default sequence
This commit is contained in:
parent
78359b1d45
commit
7e36abbb78
5 changed files with 655 additions and 629 deletions
|
@ -334,7 +334,12 @@ From ast_for_arguments():
|
|||
>>> def f(x, y=1, z):
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: non-default argument follows default argument
|
||||
SyntaxError: parameter without a default follows parameter with a default
|
||||
|
||||
>>> def f(x, /, y=1, z):
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: parameter without a default follows parameter with a default
|
||||
|
||||
>>> def f(x, None):
|
||||
... pass
|
||||
|
@ -555,6 +560,14 @@ SyntaxError: expected default value expression
|
|||
Traceback (most recent call last):
|
||||
SyntaxError: expected default value expression
|
||||
|
||||
>>> lambda a,d=3,c: None
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: parameter without a default follows parameter with a default
|
||||
|
||||
>>> lambda a,/,d=3,c: None
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: parameter without a default follows parameter with a default
|
||||
|
||||
>>> import ast; ast.parse('''
|
||||
... def f(
|
||||
... *, # type: int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue