| 1 |
[case testAnnotated0] |
| 2 |
from typing_extensions import Annotated |
| 3 |
x: Annotated[int, ...] |
| 4 |
reveal_type(x) # N: Revealed type is "builtins.int" |
| 5 |
[builtins fixtures/tuple.pyi] |
| 6 |
|
| 7 |
[case testAnnotated1] |
| 8 |
from typing import Union |
| 9 |
from typing_extensions import Annotated |
| 10 |
x: Annotated[Union[int, str], ...] |
| 11 |
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str" |
| 12 |
[builtins fixtures/tuple.pyi] |
| 13 |
|
| 14 |
[case testAnnotated2] |
| 15 |
from typing_extensions import Annotated |
| 16 |
x: Annotated[int, THESE, ARE, IGNORED, FOR, NOW] |
| 17 |
reveal_type(x) # N: Revealed type is "builtins.int" |
| 18 |
[builtins fixtures/tuple.pyi] |
| 19 |
|
| 20 |
[case testAnnotated3] |
| 21 |
from typing_extensions import Annotated |
| 22 |
x: Annotated[int, -+~12.3, "som"[e], more(anno+a+ions, that=[are]), (b"ignored",), 4, N.O.W, ...] |
| 23 |
reveal_type(x) # N: Revealed type is "builtins.int" |
| 24 |
[builtins fixtures/tuple.pyi] |
| 25 |
|
| 26 |
[case testAnnotatedBadType] |
| 27 |
from typing_extensions import Annotated |
| 28 |
x: Annotated[XXX, ...] # E: Name "XXX" is not defined |
| 29 |
reveal_type(x) # N: Revealed type is "Any" |
| 30 |
[builtins fixtures/tuple.pyi] |
| 31 |
|
| 32 |
[case testAnnotatedBadNoArgs] |
| 33 |
from typing_extensions import Annotated |
| 34 |
x: Annotated # E: Annotated[...] must have exactly one type argument and at least one annotation |
| 35 |
reveal_type(x) # N: Revealed type is "Any" |
| 36 |
[builtins fixtures/tuple.pyi] |
| 37 |
|
| 38 |
[case testAnnotatedBadOneArg] |
| 39 |
from typing_extensions import Annotated |
| 40 |
x: Annotated[int] # E: Annotated[...] must have exactly one type argument and at least one annotation |
| 41 |
reveal_type(x) # N: Revealed type is "Any" |
| 42 |
[builtins fixtures/tuple.pyi] |
| 43 |
|
| 44 |
[case testAnnotatedBadEmptyTupleIndexInTypeApplication] |
| 45 |
from typing_extensions import Annotated |
| 46 |
list[Annotated[()]] # E: Annotated[...] must have exactly one type argument and at least one annotation |
| 47 |
[builtins fixtures/list.pyi] |
| 48 |
|
| 49 |
[case testAnnotatedNested0] |
| 50 |
from typing_extensions import Annotated |
| 51 |
x: Annotated[Annotated[int, ...], ...] |
| 52 |
reveal_type(x) # N: Revealed type is "builtins.int" |
| 53 |
[builtins fixtures/tuple.pyi] |
| 54 |
|
| 55 |
[case testAnnotatedNested1] |
| 56 |
from typing import Union |
| 57 |
from typing_extensions import Annotated |
| 58 |
x: Annotated[Annotated[Union[int, str], ...], ...] |
| 59 |
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str" |
| 60 |
[builtins fixtures/tuple.pyi] |
| 61 |
|
| 62 |
[case testAnnotatedNestedBadType] |
| 63 |
from typing_extensions import Annotated |
| 64 |
x: Annotated[Annotated[XXX, ...], ...] # E: Name "XXX" is not defined |
| 65 |
reveal_type(x) # N: Revealed type is "Any" |
| 66 |
[builtins fixtures/tuple.pyi] |
| 67 |
|
| 68 |
[case testAnnotatedNestedBadNoArgs] |
| 69 |
from typing_extensions import Annotated |
| 70 |
x: Annotated[Annotated, ...] # E: Annotated[...] must have exactly one type argument and at least one annotation |
| 71 |
reveal_type(x) # N: Revealed type is "Any" |
| 72 |
[builtins fixtures/tuple.pyi] |
| 73 |
|
| 74 |
[case testAnnotatedNestedBadOneArg] |
| 75 |
from typing_extensions import Annotated |
| 76 |
x: Annotated[Annotated[int], ...] # E: Annotated[...] must have exactly one type argument and at least one annotation |
| 77 |
reveal_type(x) # N: Revealed type is "Any" |
| 78 |
[builtins fixtures/tuple.pyi] |
| 79 |
|
| 80 |
[case testAnnotatedNoImport] |
| 81 |
x: Annotated[int, ...] # E: Name "Annotated" is not defined |
| 82 |
reveal_type(x) # N: Revealed type is "Any" |
| 83 |
|
| 84 |
[case testAnnotatedDifferentName] |
| 85 |
from typing_extensions import Annotated as An |
| 86 |
x: An[int, ...] |
| 87 |
reveal_type(x) # N: Revealed type is "builtins.int" |
| 88 |
[builtins fixtures/tuple.pyi] |
| 89 |
|
| 90 |
[case testAnnotatedAliasSimple] |
| 91 |
from typing import Tuple |
| 92 |
from typing_extensions import Annotated |
| 93 |
Alias = Annotated[Tuple[int, ...], ...] |
| 94 |
x: Alias |
| 95 |
reveal_type(x) # N: Revealed type is "builtins.tuple[builtins.int, ...]" |
| 96 |
[builtins fixtures/tuple.pyi] |
| 97 |
|
| 98 |
[case testAnnotatedAliasTypeVar] |
| 99 |
from typing import TypeVar |
| 100 |
from typing_extensions import Annotated |
| 101 |
T = TypeVar('T') |
| 102 |
Alias = Annotated[T, ...] |
| 103 |
x: Alias[int] |
| 104 |
reveal_type(x) # N: Revealed type is "builtins.int" |
| 105 |
[builtins fixtures/tuple.pyi] |
| 106 |
|
| 107 |
[case testAnnotatedAliasGenericTuple] |
| 108 |
from typing import TypeVar, Tuple |
| 109 |
from typing_extensions import Annotated |
| 110 |
T = TypeVar('T') |
| 111 |
Alias = Annotated[Tuple[T, T], ...] |
| 112 |
x: Alias[int] |
| 113 |
reveal_type(x) # N: Revealed type is "tuple[builtins.int, builtins.int]" |
| 114 |
[builtins fixtures/tuple.pyi] |
| 115 |
|
| 116 |
[case testAnnotatedAliasGenericUnion] |
| 117 |
from typing import TypeVar, Union |
| 118 |
from typing_extensions import Annotated |
| 119 |
T = TypeVar('T') |
| 120 |
Alias = Annotated[Union[T, str], ...] |
| 121 |
x: Alias[int] |
| 122 |
reveal_type(x) # N: Revealed type is "builtins.int | builtins.str" |
| 123 |
[builtins fixtures/tuple.pyi] |
| 124 |
|
| 125 |
[case testAnnotatedSecondParamNonType] |
| 126 |
from typing_extensions import Annotated |
| 127 |
|
| 128 |
class Meta: |
| 129 |
... |
| 130 |
|
| 131 |
x = Annotated[int, Meta()] |
| 132 |
reveal_type(x) # N: Revealed type is "def () -> builtins.int" |
| 133 |
[builtins fixtures/tuple.pyi] |
| 134 |
|
| 135 |
[case testAnnotatedStringLiteralInFunc] |
| 136 |
from typing import TypeVar |
| 137 |
from typing_extensions import Annotated |
| 138 |
def f1(a: Annotated[str, "metadata"]): |
| 139 |
pass |
| 140 |
reveal_type(f1) # N: Revealed type is "def (a: builtins.str) -> Any" |
| 141 |
def f2(a: Annotated["str", "metadata"]): |
| 142 |
pass |
| 143 |
reveal_type(f2) # N: Revealed type is "def (a: builtins.str) -> Any" |
| 144 |
def f3(a: Annotated["notdefined", "metadata"]): # E: Name "notdefined" is not defined |
| 145 |
pass |
| 146 |
T = TypeVar('T') |
| 147 |
def f4(a: Annotated[T, "metadata"]): |
| 148 |
pass |
| 149 |
reveal_type(f4) # N: Revealed type is "def [T] (a: T`-1) -> Any" |
| 150 |
[builtins fixtures/tuple.pyi] |
| 151 |
|
| 152 |
[case testSliceAnnotated] |
| 153 |
from typing_extensions import Annotated |
| 154 |
a: Annotated[int, 1:2] |
| 155 |
reveal_type(a) # N: Revealed type is "builtins.int" |
| 156 |
[builtins fixtures/tuple.pyi] |