22
33[case testRecognizesUnparameterizedTypeFormInAnnotation]
44# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
5- from typing import TypeForm
5+ from typing_extensions import TypeForm
66typx: TypeForm = str
77reveal_type(typx) # N: Revealed type is "TypeForm[Any]"
88[builtins fixtures/primitives.pyi]
99[typing fixtures/typing-full.pyi]
1010
1111[case testRecognizesParameterizedTypeFormInAnnotation]
1212# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
13- from typing import TypeForm
13+ from typing_extensions import TypeForm
1414typx: TypeForm[str] = str
1515reveal_type(typx) # N: Revealed type is "TypeForm[builtins.str]"
1616[builtins fixtures/primitives.pyi]
@@ -21,36 +21,36 @@ reveal_type(typx) # N: Revealed type is "TypeForm[builtins.str]"
2121
2222[case testCanAssignTypeExpressionToTypeFormVariable]
2323# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
24- from typing import TypeForm
24+ from typing_extensions import TypeForm
2525typx: TypeForm[str] = str
2626[builtins fixtures/primitives.pyi]
2727[typing fixtures/typing-full.pyi]
2828
2929[case testCanAssignTypeExpressionToUnionTypeFormVariable]
3030# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
31- from typing import TypeForm
31+ from typing_extensions import TypeForm
3232typx: TypeForm[str | None] = str | None
3333[builtins fixtures/primitives.pyi]
3434[typing fixtures/typing-full.pyi]
3535
3636[case testCannotAssignTypeExpressionToTypeFormVariableWithIncompatibleItemType]
3737# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
38- from typing import TypeForm
38+ from typing_extensions import TypeForm
3939typx: TypeForm[str] = int # E: Incompatible types in assignment (expression has type "TypeForm[int]", variable has type "TypeForm[str]")
4040[builtins fixtures/primitives.pyi]
4141[typing fixtures/typing-full.pyi]
4242
4343[case testCanAssignValueExpressionToTypeFormVariableIfValueIsATypeForm1]
4444# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
45- from typing import TypeForm
45+ from typing_extensions import TypeForm
4646typx1: TypeForm = str
4747typx2: TypeForm = typx1 # looks like a type expression: name
4848[builtins fixtures/primitives.pyi]
4949[typing fixtures/typing-full.pyi]
5050
5151[case testCanAssignValueExpressionToTypeFormVariableIfValueIsATypeForm2]
5252# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
53- from typing import TypeForm
53+ from typing_extensions import TypeForm
5454def identity_tf(x: TypeForm) -> TypeForm:
5555 return x
5656typx1: TypeForm = str
@@ -60,15 +60,15 @@ typx2: TypeForm = identity_tf(typx1) # does not look like a type expression
6060
6161[case testCannotAssignValueExpressionToTypeFormVariableIfValueIsNotATypeForm]
6262# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
63- from typing import TypeForm
63+ from typing_extensions import TypeForm
6464val: int = 42
6565typx: TypeForm = val # E: Incompatible types in assignment (expression has type "int", variable has type "TypeForm[Any]")
6666[builtins fixtures/primitives.pyi]
6767[typing fixtures/typing-full.pyi]
6868
6969[case testCanAssignNoneTypeExpressionToTypeFormVariable]
7070# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
71- from typing import TypeForm
71+ from typing_extensions import TypeForm
7272typx: TypeForm = None
7373reveal_type(typx) # N: Revealed type is "TypeForm[Any]"
7474[builtins fixtures/primitives.pyi]
@@ -86,7 +86,7 @@ typx = int | None
8686
8787[case testCanAssignTypeExpressionWithStringAnnotationToTypeFormVariable]
8888# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
89- from typing import TypeForm
89+ from typing_extensions import TypeForm
9090typx: TypeForm[str | None] = 'str | None'
9191[builtins fixtures/primitives.pyi]
9292[typing fixtures/typing-full.pyi]
@@ -96,7 +96,7 @@ typx: TypeForm[str | None] = 'str | None'
9696
9797[case testCanPassTypeExpressionToTypeFormParameterInFunction]
9898# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
99- from typing import TypeForm
99+ from typing_extensions import TypeForm
100100def is_type(typx: TypeForm) -> bool:
101101 return isinstance(typx, type)
102102is_type(int | None)
@@ -113,7 +113,7 @@ is_type(int | None) # E: Argument 1 to "is_type" has incompatible type "object"
113113
114114[case testCanPassTypeExpressionToTypeFormParameterInMethod]
115115# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
116- from typing import TypeForm
116+ from typing_extensions import TypeForm
117117class C:
118118 def is_type(self, typx: TypeForm) -> bool:
119119 return isinstance(typx, type)
@@ -168,7 +168,7 @@ def sum_ints(x: int | None, y: int) -> tuple[int, int]:
168168
169169[case testCanPassTypeExpressionWithStringAnnotationToTypeFormParameter]
170170# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
171- from typing import TypeForm
171+ from typing_extensions import TypeForm
172172def is_type(typx: TypeForm) -> bool:
173173 return isinstance(typx, type)
174174is_type('int | None')
@@ -180,7 +180,7 @@ is_type('int | None')
180180
181181[case testCanReturnTypeExpressionInFunctionWithTypeFormReturnType]
182182# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
183- from typing import TypeForm
183+ from typing_extensions import TypeForm
184184def maybe_int_type() -> TypeForm:
185185 return int | None
186186reveal_type(maybe_int_type()) # N: Revealed type is "TypeForm[Any]"
@@ -189,7 +189,7 @@ reveal_type(maybe_int_type()) # N: Revealed type is "TypeForm[Any]"
189189
190190[case testCanReturnTypeExpressionWithStringAnnotationInFunctionWithTypeFormReturnType]
191191# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
192- from typing import TypeForm
192+ from typing_extensions import TypeForm
193193def maybe_int_type() -> TypeForm:
194194 return 'int | None'
195195reveal_type(maybe_int_type()) # N: Revealed type is "TypeForm[Any]"
@@ -282,7 +282,7 @@ typx2: TypeForm = no_such_module.NoSuchType # E: Name "no_such_module" is not d
282282
283283[case testAcceptsTypeFormLiteralAssignedToUnionOfTypeFormAndNonStr]
284284# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
285- from typing import TypeForm
285+ from typing_extensions import TypeForm
286286typx_or_int1: TypeForm[int | None] | int = int | None # No error; interpret as TypeForm
287287typx_or_int2: TypeForm[int | None] | int = str | None # E: Incompatible types in assignment (expression has type "object", variable has type "Union[TypeForm[Optional[int]], int]")
288288typx_or_int3: TypeForm[int | None] | int = 1
@@ -292,7 +292,7 @@ typx_or_int4: TypeForm[int | None] | int = object() # E: Incompatible types in
292292
293293[case testAcceptsTypeFormLiteralAssignedToUnionOfTypeFormAndStr]
294294# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
295- from typing import TypeForm
295+ from typing_extensions import TypeForm
296296typx_or_str1: TypeForm[int | None] | str = 'int | None'
297297typx_or_str2: TypeForm[int | None] | str = 'str | None' # No error; interpret as str
298298typx_or_str3: TypeForm[int | None] | str = 'hello'
@@ -325,7 +325,7 @@ list_of_typx4: List[TypeForm[str | None] | int] = ['str | None'] # E: TypeForm
325325# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
326326# - TypeForm[T1] is assignable to TypeForm[T2] iff T1 is assignable to T2.
327327# - In particular TypeForm[Any] is assignable to TypeForm[Any].
328- from typing import TypeForm
328+ from typing_extensions import TypeForm
329329INT_OR_STR_TF: TypeForm[int | str] = int | str
330330INT_TF: TypeForm[int] = int
331331STR_TF: TypeForm[str] = str
@@ -436,7 +436,7 @@ any3: Any = ANY_TF
436436[case testTypeFormToTypeFormJoin]
437437# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
438438# - TypeForm[T1] join TypeForm[T2] == TypeForm[T1 join T2]
439- from typing import TypeForm
439+ from typing_extensions import TypeForm
440440class AB:
441441 pass
442442class A(AB):
@@ -583,7 +583,7 @@ reveal_type(f(g)) # N: Revealed type is "type[TypedDict({'b': builtins.str, 'c'
583583
584584[case testTypeFormExpression]
585585# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
586- from typing import TypeForm
586+ from typing_extensions import TypeForm
587587tf1 = TypeForm(int | str)
588588reveal_type(tf1) # N: Revealed type is "TypeForm[Union[builtins.int, builtins.str]]"
589589tf2 = TypeForm('int | str')
@@ -601,7 +601,7 @@ tf6: TypeForm = TypeForm(TypeForm(int) | TypeForm(str)) # E: TypeForm argument
601601
602602[case testTypeFormAndTypeIsinstance]
603603# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
604- from typing import TypeForm
604+ from typing_extensions import TypeForm
605605typx: TypeForm[str] = str
606606if isinstance(typx, type):
607607 reveal_type(typx) # N: Revealed type is "type[builtins.str]"
@@ -615,7 +615,7 @@ else:
615615
616616[case testLinkTypeFormToTypeFormWithTypeVariable]
617617# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
618- from typing import TypeForm, TypeVar
618+ from typing_extensions import TypeForm, TypeVar
619619T = TypeVar('T')
620620def as_typeform(typx: TypeForm[T]) -> TypeForm[T]:
621621 return typx
@@ -639,7 +639,7 @@ reveal_type(as_type(int)) # N: Revealed type is "Union[type[builtins.int], None
639639
640640[case testLinkTypeFormToInstanceWithTypeVariable]
641641# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
642- from typing import TypeForm, TypeVar
642+ from typing_extensions import TypeForm, TypeVar
643643T = TypeVar('T')
644644def as_instance(typx: TypeForm[T]) -> T | None:
645645 if isinstance(typx, type):
@@ -653,7 +653,7 @@ reveal_type(as_instance(int)) # N: Revealed type is "Union[builtins.int, None]"
653653
654654[case testLinkTypeFormToTypeIsWithTypeVariable]
655655# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
656- from typing import TypeForm, TypeVar
656+ from typing_extensions import TypeForm, TypeVar
657657from typing_extensions import TypeIs
658658T = TypeVar('T')
659659def isassignable(value: object, typx: TypeForm[T]) -> TypeIs[T]:
@@ -668,7 +668,7 @@ else:
668668
669669[case testLinkTypeFormToTypeGuardWithTypeVariable]
670670# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
671- from typing import TypeForm, TypeVar
671+ from typing_extensions import TypeForm, TypeVar
672672from typing_extensions import TypeGuard
673673T = TypeVar('T')
674674def isassignable(value: object, typx: TypeForm[T]) -> TypeGuard[T]:
@@ -686,7 +686,7 @@ else:
686686
687687[case testTypeFormHasAllObjectAttributesAndMethods]
688688# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
689- from typing import TypeForm
689+ from typing_extensions import TypeForm
690690typx: TypeForm[int | str] = int | str
691691print(typx.__class__) # OK
692692print(typx.__hash__()) # OK
@@ -710,7 +710,7 @@ class float: pass
710710
711711[case testDottedTypeFormsAreRecognized]
712712# flags: --python-version 3.14 --enable-incomplete-feature=TypeForm
713- from typing import TypeForm
713+ from typing_extensions import TypeForm
714714import typing
715715class C1:
716716 class C2:
0 commit comments