Skip to content

[ty] Clarify in diagnostics that from __future__ import annotations only stringifies type annotations#23928

Merged
AlexWaygood merged 1 commit intomainfrom
alex/604-diags
Mar 13, 2026
Merged

[ty] Clarify in diagnostics that from __future__ import annotations only stringifies type annotations#23928
AlexWaygood merged 1 commit intomainfrom
alex/604-diags

Conversation

@AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood added ty Multi-file analysis & type inference diagnostics Related to reporting of diagnostics. labels Mar 13, 2026
16 | Y = tuple[str | int, ...] # error: [unsupported-operator]
|
info: PEP 604 `|` unions are only available on Python 3.10+ unless they are quoted
info: `from __future__ import annotations` has no effect outside type annotations
Copy link
Member Author

Choose a reason for hiding this comment

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

@marcofrasvda, would this have helped make the error clearer for you? "outside type annotations" feels like it might not be clear to everybody, because some folks might think of type alias definitions as being "inside type annotations". Not sure I can think of a better formulation, though, and this diagnostic is already pretty verbose

Choose a reason for hiding this comment

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

Yeah now that I better understand the issue I get that it's not easy to make the error more clear. I think the "has no effect outside" part in the last line is a good indicator that importing annotations might not have the effect the user expects.

Choose a reason for hiding this comment

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

A different wording might be "this use of type annotations is not covered by from __future__ import annotation" so it makes a comment about the specific usage rather than a generic statement, but I'm not sure it's better then what you wrote, I guess the next person to encounter this issue might have a better idea :)
Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

no problem! Thanks for the report -- it's important to us for our diagnostics to be clear and helpful :-)

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

Typing conformance results

No changes detected ✅

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

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:99:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 58 diagnostics
+ Found 57 diagnostics

@astral-sh-bot
Copy link

astral-sh-bot bot commented Mar 13, 2026

Memory usage report

Memory usage unchanged ✅

@AlexWaygood AlexWaygood marked this pull request as ready for review March 13, 2026 10:43
@AlexWaygood AlexWaygood assigned sharkdp and unassigned dcreager Mar 13, 2026
Copy link
Contributor

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

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

Cool!

@AlexWaygood AlexWaygood merged commit dc10320 into main Mar 13, 2026
54 checks passed
@AlexWaygood AlexWaygood deleted the alex/604-diags branch March 13, 2026 11:04
carljm added a commit that referenced this pull request Mar 13, 2026
* main: (94 commits)
  Fix shell injection via `shell=True` in subprocess calls (#23894)
  [ty] Refactor `relation.rs` to store state on a struct rather than passing around 7 arguments every time we recurse (#23837)
  Don't return code actions for non-Python documents (#23905)
  [ty] Make the default database truly statically infallible (#23929)
  [ty] Add `Download` button to ty playground which creates a zip export (#23478)
  [ty] Respect `kw_only` overwrites in dataclasses (#23930)
  [ty] Clarify in diagnostics that `from __future__ import annotations` only stringifies type annotations (#23928)
  [ty]  Add a `Copy Markdown` button to playground (#23002)
  [ty] Fix folding range classification of lines starting with `#` (#23831)
  [ty] Fix folding ranges for notebooks (#23830)
  [ty] fix too-many-cycle panics when inferring literal type loop variables (#23875)
  Add `RegularCallableTypeOf` and `into_regular_callable` in `ty_extensions` (#23909)
  [ty] treat properties as full structural types (#23925)
  [ty] Avoid duplicated work during multi-inference (#23923)
  [ty]: make `possibly-missing-attribute` ignored by default
  [ty]: split out `possibly-missing-submodule` from `possibly-missing-attribute`
  Update astral-sh/setup-uv action to v7.5.0 (#23922)
  [ty] Show truthiness in ConstraintSet display and simplify falsy error message (#23913)
  Bump 0.15.6 (#23919)
  [ty] Narrow type context during collection literal inference (#23844)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics. ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unsupported-operator when using | in type aliases in Python 3.9

5 participants