-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Support legacy typing special forms in implicit type aliases
#21433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sharkdp
merged 1 commit into
main
from
david/implicit-type-aliases-typing-special-forms
Nov 14, 2025
Merged
[ty] Support legacy typing special forms in implicit type aliases
#21433
sharkdp
merged 1 commit into
main
from
david/implicit-type-aliases-typing-special-forms
Nov 14, 2025
+307
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-11-13 18:52:28.399550432 +0000
+++ new-output.txt 2025-11-13 18:52:31.878582783 +0000
@@ -576,7 +576,6 @@
generics_syntax_scoping.py:124:13: error[type-assertion-failure] Argument does not have asserted type `int | float | complex`
generics_type_erasure.py:38:16: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `int | None`, found `Literal[""]`
generics_type_erasure.py:40:16: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `str | None`, found `Literal[0]`
-generics_type_erasure.py:56:1: error[type-assertion-failure] Argument does not have asserted type `bytes`
generics_typevartuple_args.py:16:34: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `tuple[@Todo(PEP 646), ...]`
generics_typevartuple_args.py:20:1: error[type-assertion-failure] Argument does not have asserted type `tuple[int, str]`
generics_typevartuple_args.py:27:77: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `tuple[@Todo(PEP 646), ...]`
@@ -1000,5 +999,5 @@
typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict `Movie` constructor
typeddicts_usage.py:28:18: error[invalid-key] Invalid key for TypedDict `Movie`: Unknown key "title"
typeddicts_usage.py:40:24: error[invalid-type-form] The special form `typing.TypedDict` is not allowed in type expressions. Did you mean to use a concrete TypedDict or `collections.abc.Mapping[str, object]` instead?
-Found 1002 diagnostics
+Found 1001 diagnostics
WARN A fatal error occurred while checking some files. Not all project files were analyzed. See the diagnostics list above for details.
|
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
75 | 2 | 8 |
unused-ignore-comment |
0 | 33 | 0 |
invalid-type-form |
7 | 0 | 0 |
possibly-missing-attribute |
1 | 4 | 2 |
invalid-assignment |
3 | 0 | 2 |
invalid-return-type |
1 | 1 | 2 |
no-matching-overload |
4 | 0 | 0 |
not-iterable |
0 | 0 | 2 |
unresolved-attribute |
2 | 0 | 0 |
unresolved-reference |
0 | 2 | 0 |
unsupported-operator |
1 | 0 | 0 |
| Total | 94 | 42 | 16 |
sharkdp
commented
Nov 13, 2025
Comment on lines
+686
to
+697
| InvalidSubclassOf1 = type[1] | ||
|
|
||
| # TODO: This should be an error | ||
| InvalidSubclassOfLiteral = type[Literal[42]] | ||
|
|
||
| def _( | ||
| invalid_subclass_of_1: InvalidSubclassOf1, | ||
| invalid_subclass_of_literal: InvalidSubclassOfLiteral, | ||
| ): | ||
| reveal_type(invalid_subclass_of_1) # revealed: type[Unknown] | ||
| # TODO: this should be `type[Unknown]` or `Unknown` | ||
| reveal_type(invalid_subclass_of_literal) # revealed: <class 'int'> |
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a follow-up from a previous PR.
carljm
approved these changes
Nov 14, 2025
Contributor
carljm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
dcreager
added a commit
that referenced
this pull request
Nov 14, 2025
* origin/main: (59 commits) [ty] Improve diagnostic range for `non-subscriptable` diagnostics (#21461) [ty] Improve literal promotion heuristics (#21439) [ty] Further improve details around which expressions should be deferred in stub files (#21456) [ty] Improve generic class constructor inference (#21442) [ty] Propagate type context through conditional expressions (#21443) [ty] Suppress completions when introducing names with `as` [ty] Add panic-by-default await methods to `TestServer` (#21451) [ty] name is parameter and global is a syntax error (#21312) [ty] Fixup a few details around version-specific dataclass features (#21453) [ty] Support attribute-expression `TYPE_CHECKING` conditionals (#21449) [ty] Support stringified annotations in value-position `Annotated` instances (#21447) [ty] Type inference for genererator expressions (#21437) [ty] Make `__getattr__` available for `ModuleType` instances (#21450) [ty] Increase default receive timeout in tests to 10s (#21448) [ty] Add synthetic members to completions on dataclasses (#21446) [ty] Support legacy `typing` special forms in implicit type aliases (#21433) Bump 0.14.5 (#21435) [ty] Support `type[…]` and `Type[…]` in implicit type aliases (#21421) [ty] Respect notebook cell boundaries when adding an auto import (#21322) Update PyCharm setup instructions (#21409) ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Support various legacy
typingspecial forms (List,Dict, …) in implicit type aliases.Ecosystem impact
A lot of true positives (e.g. on
alerta)!Test Plan
New Markdown tests