[ty] Clarify in diagnostics that from __future__ import annotations only stringifies type annotations#23928
Conversation
… only stringifies type annotations
| 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 |
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
no problem! Thanks for the report -- it's important to us for our diagnostics to be clear and helpful :-)
Typing conformance resultsNo changes detected ✅Current numbersThe 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. |
|
Memory usage reportMemory usage unchanged ✅ |
* 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) ...
Fixes astral-sh/ty#3034