1
- from typing import Any , Dict , Generic , List , Optional , Sequence , Tuple , TypeVar , Union
1
+ from typing import Any , ClassVar , Dict , Generic , List , Optional , Sequence , Tuple , TypeVar , Union
2
2
3
3
from pytest import mark
4
- from typing_extensions import Annotated , Literal
4
+ from typing_extensions import Annotated , Literal , TypeAlias
5
5
6
6
from typeapi .typehint import (
7
7
AnnotatedTypeHint ,
8
8
ClassTypeHint ,
9
+ ClassVarTypeHint ,
9
10
ForwardRefTypeHint ,
10
11
LiteralTypeHint ,
11
12
TupleTypeHint ,
13
+ TypeAliasTypeHint ,
12
14
TypeHint ,
13
15
TypeVarTypeHint ,
14
16
UnionTypeHint ,
@@ -543,7 +545,7 @@ class D(C[T]):
543
545
hint = TypeHint (D [int ])
544
546
assert isinstance (hint , ClassTypeHint )
545
547
assert hint .type is D
546
- assert hint .bases == (C [T ],)
548
+ assert hint .bases == (C [T ],) # type: ignore[valid-type]
547
549
assert list (hint .recurse_bases ("bfs" )) == [
548
550
TypeHint (D [int ]),
549
551
TypeHint (C [int ]),
@@ -564,19 +566,39 @@ class CustomList(List[T]):
564
566
hint = TypeHint (CustomList )
565
567
assert isinstance (hint , ClassTypeHint )
566
568
assert hint .type is CustomList
567
- assert hint .bases == (List [T ],)
569
+ assert hint .bases == (List [T ],) # type: ignore[valid-type]
568
570
assert list (hint .recurse_bases ("bfs" )) == [
569
571
TypeHint (CustomList ),
570
- TypeHint (List [T ]),
572
+ TypeHint (List [T ]), # type: ignore[valid-type]
571
573
TypeHint (object ),
572
574
]
573
575
574
576
hint = TypeHint (CustomList [int ])
575
577
assert isinstance (hint , ClassTypeHint )
576
578
assert hint .type is CustomList
577
- assert hint .bases == (List [T ],)
579
+ assert hint .bases == (List [T ],) # type: ignore[valid-type]
578
580
assert list (hint .recurse_bases ("bfs" )) == [
579
581
TypeHint (CustomList [int ]),
580
582
TypeHint (List [int ]),
581
583
TypeHint (object ),
582
584
]
585
+
586
+
587
+ def test__TypeHint__with_TypeAlias () -> None :
588
+ hint = TypeHint (TypeAlias )
589
+ assert isinstance (hint , TypeAliasTypeHint )
590
+ assert hint .hint == TypeAlias
591
+ assert hint .args == ()
592
+
593
+
594
+ def test__TypeHint__with_ClassVar () -> None :
595
+ hint = TypeHint (ClassVar )
596
+ assert isinstance (hint , ClassVarTypeHint )
597
+ assert hint .hint == ClassVar
598
+ assert hint .args == ()
599
+
600
+ hint = TypeHint (ClassVar [Union [int , str ]])
601
+ assert isinstance (hint , ClassVarTypeHint )
602
+ assert hint .hint == ClassVar [Union [int , str ]]
603
+ assert hint .args == (Union [int , str ],)
604
+ assert hint [0 ] == TypeHint (Union [int , str ])
0 commit comments