[ty] Use unqualified names for displays of TypeAliasTypes and unbound ParamSpecs/TypeVars#21960
Merged
AlexWaygood merged 1 commit intomainfrom Dec 13, 2025
Merged
[ty] Use unqualified names for displays of TypeAliasTypes and unbound ParamSpecs/TypeVars#21960AlexWaygood merged 1 commit intomainfrom
TypeAliasTypes and unbound ParamSpecs/TypeVars#21960AlexWaygood merged 1 commit intomainfrom
Conversation
ParamSpec, TypeVar and TypeAliasTypeTypeAliasTypes and unbound ParamSpecs/TypeVars
f804551 to
f3fb383
Compare
Diagnostic diff on typing conformance testsChanges were detected when running ty on typing conformance tests--- old-output.txt 2025-12-13 16:42:00.354281276 +0000
+++ new-output.txt 2025-12-13 16:42:04.015312025 +0000
@@ -43,11 +43,11 @@
aliases_newtype.py:63:15: error[invalid-newtype] Wrong number of arguments in `NewType` creation, expected 2, found 3
aliases_newtype.py:65:38: error[invalid-newtype] invalid base for `typing.NewType`: type `Any`
aliases_type_statement.py:10:52: error[invalid-type-arguments] Too many type arguments: expected 2, got 3
-aliases_type_statement.py:17:1: error[unresolved-attribute] Object of type `typing.TypeAliasType` has no attribute `bit_count`
+aliases_type_statement.py:17:1: error[unresolved-attribute] Object of type `TypeAliasType` has no attribute `bit_count`
aliases_type_statement.py:19:1: error[call-non-callable] Object of type `TypeAliasType` is not callable
-aliases_type_statement.py:23:7: error[unresolved-attribute] Object of type `typing.TypeAliasType` has no attribute `other_attrib`
-aliases_type_statement.py:26:18: error[invalid-base] Invalid class base with type `typing.TypeAliasType`
-aliases_type_statement.py:31:22: error[invalid-argument-type] Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Divergent, ...]`, found `typing.TypeAliasType`
+aliases_type_statement.py:23:7: error[unresolved-attribute] Object of type `TypeAliasType` has no attribute `other_attrib`
+aliases_type_statement.py:26:18: error[invalid-base] Invalid class base with type `TypeAliasType`
+aliases_type_statement.py:31:22: error[invalid-argument-type] Argument to function `isinstance` is incorrect: Expected `type | UnionType | tuple[Divergent, ...]`, found `TypeAliasType`
aliases_type_statement.py:37:22: error[invalid-type-form] Function calls are not allowed in type expressions
aliases_type_statement.py:38:22: error[invalid-type-form] List literals are not allowed in this context in a type expression: Did you mean `tuple[int, str]`?
aliases_type_statement.py:39:22: error[invalid-type-form] Tuple literals are not allowed in this context in a type expression
@@ -68,7 +68,7 @@
aliases_type_statement.py:82:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias3`
aliases_type_statement.py:88:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias6`
aliases_type_statement.py:89:1: error[cyclic-type-alias-definition] Cyclic definition of `RecursiveTypeAlias7`
-aliases_typealiastype.py:32:7: error[unresolved-attribute] Object of type `typing.TypeAliasType` has no attribute `other_attrib`
+aliases_typealiastype.py:32:7: error[unresolved-attribute] Object of type `TypeAliasType` has no attribute `other_attrib`
aliases_typealiastype.py:52:40: error[invalid-type-form] Function calls are not allowed in type expressions
aliases_typealiastype.py:53:40: error[invalid-type-form] List literals are not allowed in this context in a type expression: Did you mean `tuple[int, str]`?
aliases_typealiastype.py:54:42: error[invalid-type-form] Tuple literals are not allowed in this context in a type expression
@@ -580,7 +580,7 @@
generics_syntax_scoping.py:44:17: error[unresolved-reference] Name `T` used when not defined
generics_syntax_scoping.py:81:35: error[invalid-return-type] Function always implicitly returns `None`, which is not assignable to return type `((**P@decorator2) -> R@decorator2, /) -> (**P@decorator2) -> R@decorator2`
generics_syntax_scoping.py:113:9: error[type-assertion-failure] Type `str` does not match asserted type `Literal[""]`
-generics_syntax_scoping.py:116:13: error[type-assertion-failure] Type `TypeVar` does not match asserted type `typing.TypeVar`
+generics_syntax_scoping.py:116:13: error[type-assertion-failure] Type `TypeVar` does not match asserted type `TypeVar`
generics_syntax_scoping.py:121:9: error[type-assertion-failure] Type `int | float | complex` does not match asserted type `complex`
generics_syntax_scoping.py:124:13: error[type-assertion-failure] Type `int | float | complex` does not match asserted type `complex`
generics_type_erasure.py:38:16: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `int | None`, found `Literal[""]`
|
Member
Author
uh, not our greatest-ever error message, but the existing one was already pretty dreadful |
|
… `TypeAliasType`
f3fb383 to
91fe690
Compare
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
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
Currently if you create a TypeVar or a ParamSpec in a Python project in VSCode with the ty-vscode extension enabled, you get an inlay like this, which is verbose and pretty redundant IMO. Here's a screenshot from docstring-adder:
@Gankra solved this for most trivial initializer calls in #21848, but not for TypeVars/ParamSpecs/TypeAliasTypes, because these have their own distinct
Typevariants in ty and the displays for these variants currently use the fully qualified names of these types rather than the unqualified names.This PR switches those types to use the unqualified names in their displays, which means we hook into the machinery @Gankra added in #21848, and therefore the inlay hints go away.
I think we originally used the qualified names for some typing-module special forms because it matched the repr at runtime:
And then that became a pattern that we followed with other special typing-module types. But
Literalitself no longer has ^that display in our model (following #21775), so the pattern has already been broken. And using the qualified names for these displays is inconsistent with our displays for most nominal types, which generally use the unqualified names by default.Test Plan
Mdtests updated; inlay snapshots added