Skip to content

Commit f191c95

Browse files
committed
Alter TypeForm tests to import TypeForm from typing_extensions
1 parent 80d84b6 commit f191c95

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

mypy/typeshed/stdlib/typing.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ Generic: _SpecialForm
239239
Protocol: _SpecialForm
240240
Callable: _SpecialForm
241241
Type: _SpecialForm
242-
TypeForm: _SpecialForm
243242
NoReturn: _SpecialForm
244243
ClassVar: _SpecialForm
245244

test-data/unit/check-typeform.test

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
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
66
typx: TypeForm = str
77
reveal_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
1414
typx: TypeForm[str] = str
1515
reveal_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
2525
typx: 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
3232
typx: 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
3939
typx: 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
4646
typx1: TypeForm = str
4747
typx2: 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
5454
def identity_tf(x: TypeForm) -> TypeForm:
5555
return x
5656
typx1: 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
6464
val: int = 42
6565
typx: 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
7272
typx: TypeForm = None
7373
reveal_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
9090
typx: 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
100100
def is_type(typx: TypeForm) -> bool:
101101
return isinstance(typx, type)
102102
is_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
117117
class 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
172172
def is_type(typx: TypeForm) -> bool:
173173
return isinstance(typx, type)
174174
is_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
184184
def maybe_int_type() -> TypeForm:
185185
return int | None
186186
reveal_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
193193
def maybe_int_type() -> TypeForm:
194194
return 'int | None'
195195
reveal_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
286286
typx_or_int1: TypeForm[int | None] | int = int | None # No error; interpret as TypeForm
287287
typx_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]")
288288
typx_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
296296
typx_or_str1: TypeForm[int | None] | str = 'int | None'
297297
typx_or_str2: TypeForm[int | None] | str = 'str | None' # No error; interpret as str
298298
typx_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
329329
INT_OR_STR_TF: TypeForm[int | str] = int | str
330330
INT_TF: TypeForm[int] = int
331331
STR_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
440440
class AB:
441441
pass
442442
class 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
587587
tf1 = TypeForm(int | str)
588588
reveal_type(tf1) # N: Revealed type is "TypeForm[Union[builtins.int, builtins.str]]"
589589
tf2 = 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
605605
typx: TypeForm[str] = str
606606
if 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
619619
T = TypeVar('T')
620620
def 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
643643
T = TypeVar('T')
644644
def 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
657657
from typing_extensions import TypeIs
658658
T = TypeVar('T')
659659
def 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
672672
from typing_extensions import TypeGuard
673673
T = TypeVar('T')
674674
def 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
690690
typx: TypeForm[int | str] = int | str
691691
print(typx.__class__) # OK
692692
print(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
714714
import typing
715715
class C1:
716716
class C2:

test-data/unit/lib-stub/typing_extensions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Concatenate: _SpecialForm
3333

3434
TypeAlias: _SpecialForm
3535

36+
TypeForm: _SpecialForm
37+
3638
TypeGuard: _SpecialForm
3739
TypeIs: _SpecialForm
3840
Never: _SpecialForm

0 commit comments

Comments
 (0)