Skip to content

Commit 6347ba7

Browse files
authored
Add tests for PEP 593 annotated generic aliases (python#7985)
Fixes python#7729
1 parent 7de735c commit 6347ba7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test-data/unit/check-annotated.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,39 @@ reveal_type(x) # N: Revealed type is 'Any'
6363
[case testAnnotatedNoImport]
6464
x: Annotated[int, ...] # E: Name 'Annotated' is not defined
6565
reveal_type(x) # N: Revealed type is 'Any'
66+
67+
[case testAnnotatedDifferentName]
68+
from typing_extensions import Annotated as An
69+
x: An[int, ...]
70+
reveal_type(x) # N: Revealed type is 'builtins.int'
71+
72+
[case testAnnotatedAliasSimple]
73+
from typing import Tuple
74+
from typing_extensions import Annotated
75+
Alias = Annotated[Tuple[int, ...], ...]
76+
x: Alias
77+
reveal_type(x) # N: Revealed type is 'builtins.tuple[builtins.int]'
78+
79+
[case testAnnotatedAliasTypeVar]
80+
from typing import TypeVar
81+
from typing_extensions import Annotated
82+
T = TypeVar('T')
83+
Alias = Annotated[T, ...]
84+
x: Alias[int]
85+
reveal_type(x) # N: Revealed type is 'builtins.int'
86+
87+
[case testAnnotatedAliasGenericTuple]
88+
from typing import TypeVar, Tuple
89+
from typing_extensions import Annotated
90+
T = TypeVar('T')
91+
Alias = Annotated[Tuple[T, T], ...]
92+
x: Alias[int]
93+
reveal_type(x) # N: Revealed type is 'Tuple[builtins.int, builtins.int]'
94+
95+
[case testAnnotatedAliasGenericUnion]
96+
from typing import TypeVar, Union
97+
from typing_extensions import Annotated
98+
T = TypeVar('T')
99+
Alias = Annotated[Union[T, str], ...]
100+
x: Alias[int]
101+
reveal_type(x) # N: Revealed type is 'Union[builtins.int, builtins.str]'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy