[syntax-errors] Parenthesized keyword argument names after Python 3.8#16482
Merged
[syntax-errors] Parenthesized keyword argument names after Python 3.8#16482
Conversation
Summary -- Unlike the other syntax errors detected so far, parenthesized keyword arguments are only allowed *before* 3.8. It sounds like they were only accidentally allowed before that [^1]. I wanted to mark the whole parenthesized range instead of just the kwarg name, so I moved the `ParsedExpr::is_parenthesized` bool to an `Option<TextRange>` and replaced it with an `is_parenthesized` method. Test Plan -- Inline tests. [^1]: python/cpython#78822
Contributor
|
MichaReiser
reviewed
Mar 4, 2025
dhruvmanila
reviewed
Mar 4, 2025
MichaReiser
reviewed
Mar 5, 2025
dhruvmanila
reviewed
Mar 5, 2025
16 tasks
MichaReiser
approved these changes
Mar 6, 2025
Member
MichaReiser
left a comment
There was a problem hiding this comment.
I still slightly prefer to not store the parenthesized range to make this PR smaller and avoid storing information that can be retrieved from the parser already but I'm happy to go with what you / @dhruvmanila think is best
dhruvmanila
approved these changes
Mar 6, 2025
Member
dhruvmanila
left a comment
There was a problem hiding this comment.
Nice.
As suggested #16482 (comment), I'd get the argument range locally using node_range and use that instead.
T-256
reviewed
Mar 6, 2025
crates/ruff_python_parser/resources/inline/err/parenthesized_kwarg_py38.py
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Unlike the other syntax errors detected so far, parenthesized keyword arguments are only allowed before 3.8. It sounds like they were only accidentally allowed before that 1.
As an aside, you get a pretty confusing error from Python for this, so it's nice that we can catch it:
Test Plan
Inline tests.
Footnotes
https://github.com/python/cpython/issues/78822 ↩