Skip to content

[ty] Fix panic on list[Annotated[()]]#24303

Merged
AlexWaygood merged 1 commit intomainfrom
alex/annotated-panic
Mar 30, 2026
Merged

[ty] Fix panic on list[Annotated[()]]#24303
AlexWaygood merged 1 commit intomainfrom
alex/annotated-panic

Conversation

@AlexWaygood
Copy link
Copy Markdown
Member

@AlexWaygood AlexWaygood commented Mar 30, 2026

Fixes astral-sh/ty#3179

Annotated is special because it can appear in annotation expressions, type expressions and type aliases. It should be parsed nearly the same way in all contexts, but with the subtle distinction that if it appears inside a type expression or type alias, it is only allowed to have type expressions inside it, whereas it is allowed to have annotation expressions inside it if it appears inside an annotation expression.

This difference has led to us implementing Annotated type-expression parsing twice, and that resulted in us gracefully recovering from x: Annotated[()] but panicking on x: list[Annotated[()]] (in the first example, Annotated appears in an annotation expression; in the second, it appears in a type expression).

This PR fixes the bug by unifying the logic into a single place where Annotated subscriptions are inferred.

@AlexWaygood AlexWaygood added bug Something isn't working ty Multi-file analysis & type inference labels Mar 30, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 30, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 86.61%. The percentage of expected errors that received a diagnostic held steady at 81.56%. The number of fully passing files held steady at 70/132.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 30, 2026

Memory usage report

Summary

Project Old New Diff Outcome
flake8 48.07MB 48.07MB -
trio 117.99MB 117.99MB -
sphinx 265.21MB 265.21MB -0.00% (116.00B) ⬇️
prefect 716.74MB 716.72MB -0.00% (19.91kB) ⬇️

Significant changes

Click to expand detailed breakdown

sphinx

Name Old New Diff Outcome
infer_deferred_types 5.61MB 5.61MB -0.00% (128.00B) ⬇️
infer_definition_types 23.97MB 23.97MB +0.00% (12.00B) ⬇️

prefect

Name Old New Diff Outcome
infer_scope_types_impl 54.11MB 54.09MB -0.03% (19.14kB) ⬇️
infer_deferred_types 14.72MB 14.72MB -0.01% (1.52kB) ⬇️
InternedType 4.15kB 5.41kB +30.51% (1.27kB) ⬇️
infer_definition_types 89.72MB 89.72MB -0.00% (528.00B) ⬇️

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 30, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@AlexWaygood AlexWaygood marked this pull request as ready for review March 30, 2026 12:24
@carljm carljm removed their request for review March 30, 2026 16:56
@@ -1,6 +1,5 @@
---
source: crates/ty_test/src/lib.rs
assertion_line: 621
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Not sure if intentional?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it was intentional... Somebody (or somebody's agent) has an old version of cargo-insta installed locally, which means that snapshots in "legacy formats" keep getting added, which then results in a bunch of annoying, noisy warnings being printed locally whenever you run cargo test -p ty_python_semantic --test=mdtest (or run uv run crates/ty_python_semantic/mdtest.py). The only way to fix the warnings is by running --force-update-snapshots locally, and this is the result. I could split it into its own PR, but that causes its own kind of churn...

@AlexWaygood AlexWaygood merged commit 7192216 into main Mar 30, 2026
49 checks passed
@AlexWaygood AlexWaygood deleted the alex/annotated-panic branch March 30, 2026 17:14
carljm added a commit that referenced this pull request Mar 31, 2026
* main: (35 commits)
  Store definition indexes as u32 (#24307)
  Avoid re-using symbol in RUF024 fix (#24316)
  [ty] Add materialization to `Divergent` type (#24255)
  [ty] Make `Divergent` a top-level type variant (#24252)
  [ty] Fix nested global and nonlocal lookups through forwarding scopes (#24279)
  Fetch the cargo-dist binary directly instead of using the installer (#24258)
  [ty] Fix panic on `list[Annotated[()]]` (#24303)
  Don't measure the AST deallocation time in parser benchmarks (#24301)
  Enable CodSpeed's memory benchmarks for simulation benchmarks (#24298)
  Upgrade imara-diff to 0.2.0 (#24299)
  [ty] Represent `InitVar` as a special form internally, not a class (#24248)
  `RUF067`: Allow dunder-named assignments in non-strict mode
  [`pyupgrade`] UP018 should detect more unnecessarily wrapped literals (UP018) (#24093)
  [ty] Remove unused `system.glob` method (#24300)
  [ty] Reject functional TypedDict with mismatched name (#24295)
  Update Rust crate arc-swap to v1.9.0 (#24292)
  [ty] Remove unused `@Todo(Functional TypedDicts)` (#24297)
  Update CodSpeedHQ/action action to v4.12.1 (#24290)
  Update taiki-e/install-action action to v2.69.6 (#24293)
  Update Rust crate toml to v1.0.7 (#24289)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

x: list[Annotated[()]] causes a panic

3 participants