Skip to content

[ty] Support forward references in simple stub assignments - #27581

Draft
carljm wants to merge 4 commits into
mainfrom
cjm/ty-3967-stub-forward-assignment
Draft

[ty] Support forward references in simple stub assignments#27581
carljm wants to merge 4 commits into
mainfrom
cjm/ty-3967-stub-forward-assignment

Conversation

@carljm

@carljm carljm commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Resolve forward references in directly evaluated simple stub assignments using the existing deferred-expression semantics, covering class aliases, union aliases, and ordinary values.
  • Preserve at-use resolution for already-bound names so aliases of conditionally overloaded functions retain their complete overload sets; keep runtime-module assignments and specialized call handling unchanged.
  • Correct NumPy 2.5.1's _dtype = dtype forward alias so ndarray.view(np.uint32) selects the dtype overload and infers the proper ndarray dtype.

Fixes astral-sh/ty#3967.
Also fixes astral-sh/ty#4208.

Test plan

  • Added mdtests for forward and chained class aliases, union aliases, value aliases, builtins-stub forward references, generic-bound overload selection, existing bindings, self-reassignment, eager .py diagnostics, and aliases of conditionally overloaded methods.
  • All 494 semantic mdtests and parser, linter, typeshed, and semantic panic-corpus tests pass.
  • Replayed the original NumPy reproduction and affected Porcupine and Bokeh projects: overloaded method calls remain valid while the intended NumPy-related diagnostic improvements are preserved.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Aug 7, 2026
@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 96.96%. The percentage of expected errors that received a diagnostic held steady at 92.96%. The number of fully passing files held steady at 106/133.

@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

Lint rule Added Removed Changed
invalid-argument-type 0 2 0
unsound-return-statement 0 1 1
Total 0 3 1

Raw diff:

bokeh (https://github.com/bokeh/bokeh)
- src/bokeh/util/hex.py:235:27 error[invalid-argument-type] Method `__getitem__` of type `Overload[(key: _ArrayInt_co | tuple[_ArrayInt_co, ...], /) -> ndarray[_AnyShape, list[tuple[str, Any]]], (key: SupportsIndex | tuple[SupportsIndex, ...], /) -> Any, (key: _ToIndices, /) -> ndarray[_AnyShape, list[tuple[str, Any]]]]` cannot be called with key of type `Literal["q"]` on object of type `ndarray[_AnyShape, list[tuple[str, Any]]]`
- src/bokeh/util/hex.py:235:45 error[invalid-argument-type] Method `__getitem__` of type `Overload[(key: _ArrayInt_co | tuple[_ArrayInt_co, ...], /) -> ndarray[_AnyShape, list[tuple[str, Any]]], (key: SupportsIndex | tuple[SupportsIndex, ...], /) -> Any, (key: _ToIndices, /) -> ndarray[_AnyShape, list[tuple[str, Any]]]]` cannot be called with key of type `Literal["r"]` on object of type `ndarray[_AnyShape, list[tuple[str, Any]]]`
- src/bokeh/palettes.py:1529:12 warning[unsound-return-statement] Unsound return statement: `tuple[Unknown, ...]` is not a subtype of `Palette`

meson (https://github.com/mesonbuild/meson)
- mesonbuild/compilers/mixins/visualstudio.py:392:16 warning[unsound-return-statement] Unsound return statement: `list[str] | list[str | Divergent]` is not a subtype of `list[str]`
+ mesonbuild/compilers/mixins/visualstudio.py:392:16 warning[unsound-return-statement] Unsound return statement: `list[str] | list[Divergent]` is not a subtype of `list[str]`

Full report with detailed diff (timing results)

@carljm
carljm marked this pull request as ready for review August 7, 2026 20:41
@carljm
carljm requested a review from a team as a code owner August 7, 2026 20:41
@astral-sh-bot
astral-sh-bot Bot requested a review from dcreager August 7, 2026 20:41
@carljm
carljm marked this pull request as draft August 7, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

1 participant