@@ -191,13 +191,13 @@ def _(
191191 reveal_type(int_or_callable) # revealed: int | ((str, /) -> bytes)
192192 reveal_type(callable_or_int) # revealed: ((str, /) -> bytes) | int
193193 # TODO should be Unknown | int
194- reveal_type(type_var_or_int) # revealed: typing.TypeVar | int
194+ reveal_type(type_var_or_int) # revealed: T@TypeVarOrInt | int
195195 # TODO should be int | Unknown
196- reveal_type(int_or_type_var) # revealed: int | typing.TypeVar
196+ reveal_type(int_or_type_var) # revealed: int | T@IntOrTypeVar
197197 # TODO should be Unknown | None
198- reveal_type(type_var_or_none) # revealed: typing.TypeVar | None
198+ reveal_type(type_var_or_none) # revealed: T@TypeVarOrNone | None
199199 # TODO should be None | Unknown
200- reveal_type(none_or_type_var) # revealed: None | typing.TypeVar
200+ reveal_type(none_or_type_var) # revealed: None | T@NoneOrTypeVar
201201```
202202
203203If a type is unioned with itself in a value expression, the result is just that type. No
@@ -391,17 +391,17 @@ AnnotatedType = Annotated[T, "tag"]
391391TransparentAlias = T
392392MyOptional = T | None
393393
394- # TODO : Consider displaying this as `<class 'list[T]'>`, … instead? (and similar for some others below)
395- reveal_type(MyList) # revealed: <class 'list[typing.TypeVar]'>
396- reveal_type(MyDict) # revealed: <class 'dict[typing.TypeVar, typing.TypeVar]'>
394+ reveal_type(MyList) # revealed: <class 'list[T@MyList]'>
395+ reveal_type(MyDict) # revealed: <class 'dict[T@MyDict, U@MyDict]'>
397396reveal_type(MyType) # revealed: GenericAlias
398- reveal_type(IntAndType) # revealed: <class 'tuple[int, typing.TypeVar ]'>
399- reveal_type(Pair) # revealed: <class 'tuple[typing.TypeVar, typing.TypeVar ]'>
400- reveal_type(Sum) # revealed: <class 'tuple[typing.TypeVar, typing.TypeVar ]'>
397+ reveal_type(IntAndType) # revealed: <class 'tuple[int, T@IntAndType ]'>
398+ reveal_type(Pair) # revealed: <class 'tuple[T@Pair, T@Pair ]'>
399+ reveal_type(Sum) # revealed: <class 'tuple[T@Sum, U@Sum ]'>
401400reveal_type(ListOrTuple) # revealed: types.UnionType
402401reveal_type(ListOrTupleLegacy) # revealed: types.UnionType
403402reveal_type(MyCallable) # revealed: GenericAlias
404403reveal_type(AnnotatedType) # revealed: <typing.Annotated special form>
404+ # TODO : This should ideally be `T@TransparentAlias`
405405reveal_type(TransparentAlias) # revealed: typing.TypeVar
406406reveal_type(MyOptional) # revealed: types.UnionType
407407
@@ -445,7 +445,7 @@ U = TypeVar("U")
445445
446446DictStrTo = MyDict[str , U]
447447
448- reveal_type(DictStrTo) # revealed: <class 'dict[str, typing.TypeVar ]'>
448+ reveal_type(DictStrTo) # revealed: <class 'dict[str, U@DictStrTo ]'>
449449
450450def _ (
451451 dict_str_to_int : DictStrTo[int ],
@@ -480,7 +480,7 @@ A generic implicit type alias can also be used in another generic implicit type
480480``` py
481481MyOtherList = MyList[T]
482482
483- reveal_type(MyOtherList) # revealed: <class 'list[typing.TypeVar ]'>
483+ reveal_type(MyOtherList) # revealed: <class 'list[T@MyOtherList ]'>
484484
485485def _ (
486486 list_of_ints : MyOtherList[int ],
@@ -498,11 +498,11 @@ def _(
498498 my_callable : MyCallable,
499499):
500500 # TODO : Should be `list[Unknown]`
501- reveal_type(my_list) # revealed: list[typing.TypeVar ]
501+ reveal_type(my_list) # revealed: list[T@MyList ]
502502 # TODO : Should be `dict[Unknown, Unknown]`
503- reveal_type(my_dict) # revealed: dict[typing.TypeVar, typing.TypeVar ]
503+ reveal_type(my_dict) # revealed: dict[T@MyDict, U@MyDict ]
504504 # TODO : Should be `(...) -> Unknown`
505- reveal_type(my_callable) # revealed: (...) -> typing.TypeVar
505+ reveal_type(my_callable) # revealed: (...) -> T@MyCallable
506506```
507507
508508(Generic) implicit type aliases can be used as base classes:
@@ -552,6 +552,23 @@ def _(
552552 reveal_type(dict_too_few_args) # revealed: Unknown
553553```
554554
555+ Trying to specialize a non-name node results in an error:
556+
557+ ``` py
558+ from ty_extensions import TypeOf
559+
560+ IntOrStr = int | str
561+
562+ def this_does_not_work () -> TypeOf[IntOrStr]:
563+ raise NotImplementedError ()
564+
565+ def _ (
566+ # error: [invalid-type-form] "Cannot specialize a non-name node in a type expression"
567+ specialized : this_does_not_work()[int ],
568+ ):
569+ reveal_type(specialized) # revealed: Unknown
570+ ```
571+
555572## ` Literal ` s
556573
557574We also support ` typing.Literal ` in implicit type aliases.
0 commit comments