From cdec0f94216d1b3586015e62577696d1760f7a6d Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama Date: Fri, 12 Dec 2025 19:03:25 +0900 Subject: [PATCH] add TODO comment about PEP 613 type aliases --- .../mdtest/generics/legacy/variables.md | 23 ++++++++++++++----- .../mdtest/generics/pep695/variables.md | 15 ++++++++---- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md b/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md index 1fea54f078..b723318963 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/legacy/variables.md @@ -107,21 +107,32 @@ reveal_type(S) # revealed: TypeVar ### No explicit specialization A type variable itself cannot be explicitly specialized; the result of the specialization is -`Unknown`. +`Unknown`. However, anything designated as a generic type alias by `typing.TypeAlias` can be +explicitly specialized. ```py -from typing import TypeVar +from typing import TypeVar, TypeAlias T = TypeVar("T") +BareAnnotated = T +Annotated: TypeAlias = T def _( # error: [invalid-type-form] "A type variable itself cannot be specialized" - x: T[int], + a: T[int], # error: [invalid-type-form] "A type variable itself cannot be specialized" - y: T[T], + b: T[T], + # error: [invalid-type-form] "A type variable itself cannot be specialized" + c: BareAnnotated[int], + # TODO: no error + # error: [invalid-type-form] + d: Annotated[int], ): - reveal_type(x) # revealed: Unknown - reveal_type(y) # revealed: Unknown + reveal_type(a) # revealed: Unknown + reveal_type(b) # revealed: Unknown + reveal_type(c) # revealed: Unknown + # TODO: should be `int` + reveal_type(d) # revealed: Unknown ``` ### Type variables with a default diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md index cef846ab0a..289cf13ef4 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md @@ -101,17 +101,22 @@ def f[T: (int,)](): ### No explicit specialization A type variable itself cannot be explicitly specialized; the result of the specialization is -`Unknown`. +`Unknown`. However, anything designated as a generic type alias by a type statement can be +explicitly specialized. ```py +type Annotated[T] = T + def _[T]( # error: [invalid-type-form] "A type variable itself cannot be specialized" - x: T[int], + a: T[int], # error: [invalid-type-form] "A type variable itself cannot be specialized" - y: T[T], + b: T[T], + c: Annotated[int], ): - reveal_type(x) # revealed: Unknown - reveal_type(y) # revealed: Unknown + reveal_type(a) # revealed: Unknown + reveal_type(b) # revealed: Unknown + reveal_type(c) # revealed: int ``` ## Invalid uses