Skip to content

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Mar 6, 2025

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.

ntBre added 2 commits March 6, 2025 16:35
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.
@ntBre ntBre added parser Related to the parser preview Related to preview mode features labels Mar 6, 2025
Copy link
Contributor

github-actions bot commented Mar 6, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@@ -667,6 +694,7 @@ impl Display for UnsupportedSyntaxError {
UnsupportedSyntaxErrorKind::StarExpressionInIndex => {
"Cannot use star expression in index"
}
UnsupportedSyntaxErrorKind::StarAnnotation => "Cannot use star annotation",
Copy link
Member

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.

Copy link
Contributor Author

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.

Base automatically changed from brent/syn-star-index to main March 14, 2025 14:51
@ntBre ntBre enabled auto-merge (squash) March 14, 2025 15:16
@ntBre ntBre merged commit 6311412 into main Mar 14, 2025
20 checks passed
@ntBre ntBre deleted the brent/syn-star-annotation branch March 14, 2025 15:20
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Related to the parser preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants