Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -1331,11 +1331,11 @@ invalid_default:
invalid_star_etc:
| a='*' (')' | ',' (')' | '**')) { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "named parameters must follow bare *") }
| '*' ',' TYPE_COMMENT { RAISE_SYNTAX_ERROR("bare * has associated type comment") }
| '*' param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional parameter cannot have default value") }
| '*' param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional parameter's default value cannot be changed because it has the immutable default value ()") }
| '*' (param_no_default | ',') param_maybe_default* a='*' (param_no_default | ',') {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "* may appear only once") }
invalid_kwds:
| '**' param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-keyword parameter cannot have default value") }
| '**' param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-keyword parameter's default value cannot be changed because it has the immutable default value {}") }
| '**' param ',' a=param { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameters cannot follow var-keyword parameter") }
| '**' param ',' a[Token*]=('*'|'**'|'/') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameters cannot follow var-keyword parameter") }
invalid_parameters_helper: # This is only there to avoid type errors
Expand All @@ -1359,11 +1359,11 @@ invalid_lambda_parameters_helper:
| lambda_param_with_default+
invalid_lambda_star_etc:
| '*' (':' | ',' (':' | '**')) { RAISE_SYNTAX_ERROR("named parameters must follow bare *") }
| '*' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional parameter cannot have default value") }
| '*' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-positional parameter's default value cannot be changed because it has the immutable default value ()") }
| '*' (lambda_param_no_default | ',') lambda_param_maybe_default* a='*' (lambda_param_no_default | ',') {
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "* may appear only once") }
invalid_lambda_kwds:
| '**' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-keyword parameter cannot have default value") }
| '**' lambda_param a='=' { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "var-keyword parameter's default value cannot be changed because it has the immutable default value {}") }
| '**' lambda_param ',' a=lambda_param { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameters cannot follow var-keyword parameter") }
| '**' lambda_param ',' a[Token*]=('*'|'**'|'/') { RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "parameters cannot follow var-keyword parameter") }
invalid_double_type_comments:
Expand Down
12 changes: 6 additions & 6 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,22 +461,22 @@
>>> def foo(a,*b=3,c):
... pass
Traceback (most recent call last):
SyntaxError: var-positional parameter cannot have default value
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is clearer. "var-positional parameter cannot have default value" is oddly worded but I think equal or better to this proposal.

>>> def foo(a,*b: int=,c):
... pass
Traceback (most recent call last):
SyntaxError: var-positional parameter cannot have default value
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value ()
>>> def foo(a,**b=3):
... pass
Traceback (most recent call last):
SyntaxError: var-keyword parameter cannot have default value
SyntaxError: var-keyword parameter's default value cannot be changed because it has the immutable default value {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, but this is worse -- it confuses the reader over {} (which is not immutable) vs the default (which notionally is).

>>> def foo(a,**b: int=3):
... pass
Traceback (most recent call last):
SyntaxError: var-keyword parameter cannot have default value
SyntaxError: var-keyword parameter's default value cannot be changed because it has the immutable default value {}
>>> def foo(a,*a, b, **c, d):
... pass
Expand Down Expand Up @@ -577,11 +577,11 @@
>>> lambda a,*b=3,c: None
Traceback (most recent call last):
SyntaxError: var-positional parameter cannot have default value
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SyntaxError: var-positional parameter's default value cannot be changed because it has the immutable default value ()
SyntaxError: Cannot change the default value of a var-positional parameter because it is already defined.

@AA-Turner Maybe this would make more sense to people?
For me, “immutable default value” feels too detailed, and the current message isn’t very user-friendly.

>>> lambda a,**b=3: None
Traceback (most recent call last):
SyntaxError: var-keyword parameter cannot have default value
SyntaxError: var-keyword parameter's default value cannot be changed because it has the immutable default value {}
>>> lambda a, *a, b, **c, d: None
Traceback (most recent call last):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix error msg for *args, **kwargs default value
Yoonho Hann.
8 changes: 4 additions & 4 deletions Parser/parser.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading