Skip to content

Conversation

@sharktide
Copy link
Contributor

@sharktide sharktide commented Mar 7, 2025

Fixes and closes #129545

Overview:

The SyntaxError: parameter without a default follows parameter with a default error message has been modified to SyntaxError: positional parameter without a default follows parameter with a default to clarify error messages.

As mentioned in #129545

@smheidrich

Trying to define a function in which a positional parameter follows a parameter with a default value, we get a SyntaxError as expected:

>>> def f(a=1, b):
 File "<python-input-0>", line 1
 def f(a=1, b):
            ^
SyntaxError: parameter without a default follows parameter with a default

But the message that comes with it is not as accurate as it could be, as we can easily construct a valid function signature in which a parameter without a default follows a parameter with a default so long as both are keyword-only parameters:

>>> def f(*, a=1, b):
...     pass
...     
>>> 

(I didn't use a=1, *, b for this counterexample because then one could argue that, if "follows" is interpreted as "follows immediately", we did resolve the situation described in the error message, making it formally accurate, albeit confusing.)

As also mentioned by @smheidrich:

It's not just a matter of accuracy for accuracy's sake, however: This change would also hint to people who don't know or have forgotten about keyword-only parameters that there is another possibility of resolving the issue than the ones implied by the current message.

The new error message, should be accurate for most cases and should not be confusing. However, if there are cases where the original error message might be more appropriate ex when dealing with keyword-only parameters or other specific syntax rules but the new change would cause minimal confusion compared to the problem that this pr intends to solve.

@bedevere-app
Copy link

bedevere-app bot commented Mar 7, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sharktide
Copy link
Contributor Author

note: will add news entry tmw

Copy link
Member

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @sharktide! I'm good with this change. I've left one comment about a formatting issue.

@bedevere-app
Copy link

bedevere-app bot commented Mar 7, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sharktide sharktide requested a review from lysnikolaou March 7, 2025 13:01
@bedevere-app
Copy link

bedevere-app bot commented Mar 7, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

One editorial comment on the news blurb. Also, a better category for it would be Core and Builtins. Maybe move it there?

@sharktide
Copy link
Contributor Author

One editorial comment on the news blurb. Also, a better category for it would be Core and Builtins. Maybe move it there?

ok

@sharktide
Copy link
Contributor Author

@lysnikolaou I moved the news entry to Core and Builtins as well as took your change suggestion

@sharktide sharktide requested a review from lysnikolaou March 7, 2025 17:34
@sharktide
Copy link
Contributor Author

@lysnikolaou

Sorry to bother you, but could you please re-review this pull request? TiA

@sharktide
Copy link
Contributor Author

@lysnikolaou Could you please check this PR again? It has been over a month I have been waiting.

@sharktide
Copy link
Contributor Author

@lysnikolaou Please Review this PR. It has been 2mo

@lysnikolaou
Copy link
Member

@pablogsal What do you think about this wording change?

@pablogsal
Copy link
Member

I am not convinced is yielding a lot of extra clarity but maybe I am biased here so I am happy taking this in if you want. I am +0

@sharktide
Copy link
Contributor Author

@lysnikolaou pablogsal left his input. Please decide to merge or not

@lysnikolaou
Copy link
Member

Thanks @sharktide for all the reminders!

After discussing this with more folks, I'm gonna side with @pablogsal and say that this doesn't really provide too much more clarity, so I'll close the PR. Thanks a lot for your patience. I'd be happy to review another one if you wanna work on another part of the parser.

@lysnikolaou lysnikolaou closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError: parameter without a default follows parameter with a default is inaccurate

3 participants