[syntax-errors] Star annotations before Python 3.11#16545
Merged
Conversation
Summary -- This PR detects tuple unpacking expressions in index/subscript expressions before Python 3.11. Test Plan -- New inline tests
Summary -- This is closely related to (and stacked on) #16544 and detects star annotations in function definitions. I initially called the variant `StarExpressionInAnnotation` to mirror `StarExpressionInIndex`, but I realized it's not really a "star expression" in this position and renamed it. `StarAnnotation` seems in line with the PEP. Test Plan -- Two new inline tests. It looked like there was pretty good existing coverage of this syntax, so I just added simple examples to test the version cutoff.
Contributor
|
MichaReiser
reviewed
Mar 7, 2025
MichaReiser
approved these changes
Mar 7, 2025
dhruvmanila
approved these changes
Mar 7, 2025
| UnsupportedSyntaxErrorKind::StarExpressionInIndex => { | ||
| "Cannot use star expression in index" | ||
| } | ||
| UnsupportedSyntaxErrorKind::StarAnnotation => "Cannot use star annotation", |
Member
There was a problem hiding this comment.
Technically, it's an "annotation expression" but as a user facing message I think either "star annotation" or "star annotation expression" is fine.
Contributor
Author
There was a problem hiding this comment.
Oh good to know, thanks! I guess I'll leave it alone for now, but I'm happy to switch to star annotation expression if that would be more precise. It looks like pyright's message here is "Unpack operator not allowed in type expression," which also makes sense.
16 tasks
dcreager
added a commit
that referenced
this pull request
Mar 14, 2025
* main: [red-knot] Use `try_call_dunder` for augmented assignment (#16717) [red-knot] Document current state of attribute assignment diagnostics (#16746) [red-knot] Case sensitive module resolver (#16521) [red-knot] Very minor simplification of the render tests (#16759) [syntax-errors] Unparenthesized assignment expressions in sets and indexes (#16404) ruff_db: add a new diagnostic renderer ruff_db: add `context` configuration red_knot: plumb through `DiagnosticFormat` to the CLI ruff_db: add concise diagnostic mode [syntax-errors] Star annotations before Python 3.11 (#16545) [syntax-errors] Star expression in index before Python 3.11 (#16544) Ruff 0.11.0 (#16723) [red-knot] Preliminary tests for typing.Final (#15917) [red-knot] fix: improve type inference for binary ops on tuples (#16725) [red-knot] Assignments to attributes (#16705) [`pygrep-hooks`]: Detect file-level suppressions comments without rul… (#16720) Fallback to requires-python in certain cases when target-version is not found (#16721)
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
This is closely related to (and stacked on) #16544 and detects star annotations in function definitions.
I initially called the variant
StarExpressionInAnnotationto mirrorStarExpressionInIndex, but I realized it's not really a "star expression" in this position and renamed it.StarAnnotationseems in line with the PEP.Test Plan
Two new inline tests. It looked like there was pretty good existing coverage of this syntax, so I just added simple examples to test the version cutoff.