-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[syntax-errors] Star annotations before Python 3.11 #16545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
|
@@ -667,6 +694,7 @@ impl Display for UnsupportedSyntaxError { | |||
UnsupportedSyntaxErrorKind::StarExpressionInIndex => { | |||
"Cannot use star expression in index" | |||
} | |||
UnsupportedSyntaxErrorKind::StarAnnotation => "Cannot use star annotation", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, it's an "annotation expression" but as a user facing message I think either "star annotation" or "star annotation expression" is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
* 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)
Summary
This is closely related to (and stacked on) #16544 and detects star annotations in function definitions.
I initially called the variant
StarExpressionInAnnotation
to mirrorStarExpressionInIndex
, 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.