Skip to content

Commit 64a5ccc

Browse files
authored
Update TypedDict imports in tests (2) (#18646)
Followup to #18528 Replace most `typing_extensions.TypedDict` imports in tests with `typing.TypedDict`.
1 parent f946af4 commit 64a5ccc

28 files changed

+225
-161
lines changed

mypyc/test-data/irbuild-dict.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ L0:
218218
return r2
219219

220220
[case testDictIterationMethods]
221-
from typing import Dict, Union
222-
from typing_extensions import TypedDict
221+
from typing import Dict, TypedDict, Union
223222

224223
class Person(TypedDict):
225224
name: str
@@ -239,6 +238,7 @@ def typeddict(d: Person) -> None:
239238
for k, v in d.items():
240239
if k == "name":
241240
name = v
241+
[typing fixtures/typing-full.pyi]
242242
[out]
243243
def print_dict_methods(d1, d2):
244244
d1, d2 :: dict

mypyc/test-data/run-classes.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,15 @@ assert hasattr(c, 'x')
7878

7979
[case testTypedDictWithFields]
8080
import collections
81-
from typing_extensions import TypedDict
81+
from typing import TypedDict
8282
class C(TypedDict):
8383
x: collections.deque
8484
[file driver.py]
8585
from native import C
8686
from collections import deque
8787

8888
print(C.__annotations__["x"] is deque)
89+
[typing fixtures/typing-full.pyi]
8990
[out]
9091
True
9192

mypyc/test-data/run-dicts.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ assert get_content_set(od) == ({1, 3}, {2, 4}, {(1, 2), (3, 4)})
9595
[typing fixtures/typing-full.pyi]
9696

9797
[case testDictIterationMethodsRun]
98-
from typing import Dict, Union
99-
from typing_extensions import TypedDict
98+
from typing import Dict, TypedDict, Union
10099

101100
class ExtensionDict(TypedDict):
102101
python: str
@@ -188,6 +187,7 @@ except TypeError as e:
188187
assert str(e) == "a tuple of length 2 expected"
189188
else:
190189
assert False
190+
[typing fixtures/typing-full.pyi]
191191
[out]
192192
1
193193
3

mypyc/test-data/run-functions.test

+3-1
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,8 @@ def g() -> None:
12431243
g()
12441244

12451245
[case testUnpackKwargsCompiled]
1246-
from typing_extensions import Unpack, TypedDict
1246+
from typing import TypedDict
1247+
from typing_extensions import Unpack
12471248

12481249
class Person(TypedDict):
12491250
name: str
@@ -1254,6 +1255,7 @@ def foo(**kwargs: Unpack[Person]) -> None:
12541255

12551256
# This is not really supported yet, just test that we behave reasonably.
12561257
foo(name='Jennifer', age=38)
1258+
[typing fixtures/typing-full.pyi]
12571259
[out]
12581260
Jennifer
12591261

mypyc/test-data/run-misc.test

+5-3
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ for a in sorted(s):
612612
9 8 72
613613

614614
[case testDummyTypes]
615-
from typing import Tuple, List, Dict, Literal, NamedTuple
616-
from typing_extensions import TypedDict, NewType
615+
from typing import Tuple, List, Dict, Literal, NamedTuple, TypedDict
616+
from typing_extensions import NewType
617617

618618
class A:
619619
pass
@@ -664,6 +664,7 @@ except Exception as e:
664664
print(type(e).__name__)
665665
# ... but not that it is a valid literal value
666666
take_literal(10)
667+
[typing fixtures/typing-full.pyi]
667668
[out]
668669
Lol(a=1, b=[])
669670
10
@@ -675,7 +676,7 @@ TypeError
675676
10
676677

677678
[case testClassBasedTypedDict]
678-
from typing_extensions import TypedDict
679+
from typing import TypedDict
679680

680681
class TD(TypedDict):
681682
a: int
@@ -707,6 +708,7 @@ def test_non_total_typed_dict() -> None:
707708
d4 = TD4(a=1, b=2, c=3, d=4)
708709
assert d3['c'] == 3
709710
assert d4['d'] == 4
711+
[typing fixtures/typing-full.pyi]
710712

711713
[case testClassBasedNamedTuple]
712714
from typing import NamedTuple

test-data/unit/check-basic.test

+4-5
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ y = x # E: Incompatible types in assignment (expression has type "Dict[str, int]
396396
import b
397397

398398
[file a.py]
399-
from typing import NamedTuple
400-
from typing_extensions import TypedDict
399+
from typing import NamedTuple, TypedDict
401400
from enum import Enum
402401
class A: pass
403402
N = NamedTuple('N', [('x', int)])
@@ -406,8 +405,8 @@ class B(Enum):
406405
b = 10
407406

408407
[file b.py]
409-
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type
410-
from typing_extensions import Final, TypedDict
408+
from typing import List, Literal, Optional, Union, Sequence, NamedTuple, Tuple, Type, TypedDict
409+
from typing_extensions import Final
411410
from enum import Enum
412411
import a
413412
class A: pass
@@ -464,8 +463,8 @@ def typeddict() -> Sequence[D]:
464463

465464
a = (a.A(), A())
466465
a.x # E: "Tuple[a.A, b.A]" has no attribute "x"
467-
468466
[builtins fixtures/dict.pyi]
467+
[typing fixtures/typing-full.pyi]
469468

470469
[case testReturnAnyFromFunctionDeclaredToReturnObject]
471470
# flags: --warn-return-any

test-data/unit/check-dataclasses.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ class C:
14081408

14091409
[case testDataclassFieldWithTypedDictUnpacking]
14101410
from dataclasses import dataclass, field
1411-
from typing_extensions import TypedDict
1411+
from typing import TypedDict
14121412

14131413
class FieldKwargs(TypedDict):
14141414
repr: bool
@@ -1421,6 +1421,7 @@ class Foo:
14211421

14221422
reveal_type(Foo(bar=1.5)) # N: Revealed type is "__main__.Foo"
14231423
[builtins fixtures/dataclasses.pyi]
1424+
[typing fixtures/typing-typeddict.pyi]
14241425

14251426
[case testDataclassWithSlotsArg]
14261427
# flags: --python-version 3.10

test-data/unit/check-errorcodes.test

+6-5
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ y: Dict[int, int] = {1: ''} # E: Dict entry 0 has incompatible type "int": "str
449449
[builtins fixtures/dict.pyi]
450450

451451
[case testErrorCodeTypedDict]
452-
from typing_extensions import TypedDict
452+
from typing import TypedDict
453453
class D(TypedDict):
454454
x: int
455455
class E(TypedDict):
@@ -472,7 +472,7 @@ a['y'] # E: TypedDict "D" has no key "y" [typeddict-item]
472472
[typing fixtures/typing-typeddict.pyi]
473473

474474
[case testErrorCodeTypedDictNoteIgnore]
475-
from typing_extensions import TypedDict
475+
from typing import TypedDict
476476
class A(TypedDict):
477477
one_commonpart: int
478478
two_commonparts: int
@@ -484,7 +484,7 @@ not_exist = a['not_exist'] # type: ignore[typeddict-item]
484484
[typing fixtures/typing-typeddict.pyi]
485485

486486
[case testErrorCodeTypedDictSubCodeIgnore]
487-
from typing_extensions import TypedDict
487+
from typing import TypedDict
488488
class D(TypedDict):
489489
x: int
490490
d: D = {'x': 1, 'y': 2} # type: ignore[typeddict-item]
@@ -831,10 +831,11 @@ Foo = NamedTuple("Bar", []) # E: First argument to namedtuple() should be "Foo"
831831
[builtins fixtures/tuple.pyi]
832832

833833
[case testTypedDictNameMismatch]
834-
from typing_extensions import TypedDict
834+
from typing import TypedDict
835835

836836
Foo = TypedDict("Bar", {}) # E: First argument "Bar" to TypedDict() does not match variable name "Foo" [name-match]
837837
[builtins fixtures/dict.pyi]
838+
[typing fixtures/typing-typeddict.pyi]
838839

839840
[case testTruthyBool]
840841
# flags: --enable-error-code truthy-bool --no-local-partial-types
@@ -993,7 +994,7 @@ reveal_type(t) # N: Revealed type is "__main__.TensorType"
993994
[builtins fixtures/tuple.pyi]
994995

995996
[case testNoteAboutChangedTypedDictErrorCode]
996-
from typing_extensions import TypedDict
997+
from typing import TypedDict
997998
class D(TypedDict):
998999
x: int
9991000

test-data/unit/check-formatting.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ x: Any
542542
[builtins fixtures/primitives.pyi]
543543

544544
[case testFormatCallAccessorsIndices]
545-
from typing_extensions import TypedDict
545+
from typing import TypedDict
546546

547547
class User(TypedDict):
548548
id: int
@@ -554,6 +554,7 @@ u: User
554554
def f() -> str: ...
555555
'{[f()]}'.format(u) # E: Invalid index expression in format field accessor "[f()]"
556556
[builtins fixtures/primitives.pyi]
557+
[typing fixtures/typing-typeddict.pyi]
557558

558559
[case testFormatCallFlags]
559560
from typing import Union

test-data/unit/check-functions.test

+3-4
Original file line numberDiff line numberDiff line change
@@ -3399,8 +3399,7 @@ class Bar(Foo):
33993399
[builtins fixtures/property.pyi]
34003400

34013401
[case testNoCrashOnUnpackOverride]
3402-
from typing import Unpack
3403-
from typing_extensions import TypedDict
3402+
from typing import TypedDict, Unpack
34043403

34053404
class Params(TypedDict):
34063405
x: int
@@ -3419,9 +3418,9 @@ class C(B):
34193418
# N: def meth(*, x: int, y: str) -> None \
34203419
# N: Subclass: \
34213420
# N: def meth(*, x: int, y: int) -> None
3422-
34233421
...
3424-
[builtins fixtures/tuple.pyi]
3422+
[builtins fixtures/dict.pyi]
3423+
[typing fixtures/typing-full.pyi]
34253424

34263425
[case testOverrideErrorLocationNamed]
34273426
class B:

test-data/unit/check-functools.test

+3-2
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,8 @@ def foo(cls3: Type[B[T]]):
433433
[builtins fixtures/tuple.pyi]
434434

435435
[case testFunctoolsPartialTypedDictUnpack]
436-
from typing_extensions import TypedDict, Unpack
436+
from typing import TypedDict
437+
from typing_extensions import Unpack
437438
from functools import partial
438439

439440
class D1(TypedDict, total=False):
@@ -509,8 +510,8 @@ def main6(a2good: A2Good, a2bad: A2Bad, **d1: Unpack[D1]) -> None:
509510
partial(fn4, **d1)(a2="asdf")
510511
partial(fn4, **d1)(**a2good)
511512
partial(fn4, **d1)(**a2bad) # E: Argument "a2" to "fn4" has incompatible type "int"; expected "str"
512-
513513
[builtins fixtures/dict.pyi]
514+
[typing fixtures/typing-typeddict.pyi]
514515

515516

516517
[case testFunctoolsPartialNestedGeneric]

test-data/unit/check-incremental.test

+16-9
Original file line numberDiff line numberDiff line change
@@ -5740,8 +5740,8 @@ import b
57405740
b.xyz
57415741

57425742
[file b.py]
5743-
from typing import NamedTuple, NewType
5744-
from typing_extensions import TypedDict, TypeAlias
5743+
from typing import NamedTuple, NewType, TypedDict
5744+
from typing_extensions import TypeAlias
57455745
from enum import Enum
57465746
from dataclasses import dataclass
57475747

@@ -5777,6 +5777,7 @@ class C:
57775777
n: N = N(NT1(c=1))
57785778

57795779
[builtins fixtures/dict.pyi]
5780+
[typing fixtures/typing-typeddict.pyi]
57805781
[out2]
57815782
tmp/a.py:2: error: "object" has no attribute "xyz"
57825783

@@ -6079,7 +6080,8 @@ tmp/b.py:3: error: Incompatible types in assignment (expression has type "int",
60796080
[case testUnpackKwargsSerialize]
60806081
import m
60816082
[file lib.py]
6082-
from typing_extensions import Unpack, TypedDict
6083+
from typing import TypedDict
6084+
from typing_extensions import Unpack
60836085

60846086
class Person(TypedDict):
60856087
name: str
@@ -6095,6 +6097,7 @@ foo(name='Jennifer', age=38)
60956097
from lib import foo
60966098
foo(name='Jennifer', age="38")
60976099
[builtins fixtures/dict.pyi]
6100+
[typing fixtures/typing-typeddict.pyi]
60986101
[out]
60996102
[out2]
61006103
tmp/m.py:2: error: Argument "age" to "foo" has incompatible type "str"; expected "int"
@@ -6276,7 +6279,7 @@ import f
62766279
# modify
62776280

62786281
[file f.py]
6279-
from typing_extensions import TypedDict
6282+
from typing import TypedDict
62806283
import c
62816284
class D(TypedDict):
62826285
x: c.C
@@ -6297,6 +6300,7 @@ class C: ...
62976300
class C: ...
62986301
[file pb1.py.2]
62996302
[builtins fixtures/dict.pyi]
6303+
[typing fixtures/typing-typeddict.pyi]
63006304
[out]
63016305
[out2]
63026306
[out3]
@@ -6464,8 +6468,7 @@ y: int = x
64646468
[case testGenericTypedDictWithError]
64656469
import b
64666470
[file a.py]
6467-
from typing import Generic, TypeVar
6468-
from typing_extensions import TypedDict
6471+
from typing import Generic, TypeVar, TypedDict
64696472

64706473
TValue = TypeVar("TValue")
64716474
class Dict(TypedDict, Generic[TValue]):
@@ -6487,6 +6490,7 @@ def f(d: Dict[TValue]) -> TValue:
64876490
def g(d: Dict[TValue]) -> TValue:
64886491
return d["y"]
64896492
[builtins fixtures/dict.pyi]
6493+
[typing fixtures/typing-typeddict.pyi]
64906494
[out]
64916495
tmp/b.py:6: error: TypedDict "a.Dict[TValue]" has no key "x"
64926496
[out2]
@@ -6588,9 +6592,10 @@ import counts
65886592
import counts
65896593
# touch
65906594
[file counts.py]
6591-
from typing_extensions import TypedDict
6595+
from typing import TypedDict
65926596
Counts = TypedDict("Counts", {k: int for k in "abc"}) # type: ignore
65936597
[builtins fixtures/dict.pyi]
6598+
[typing fixtures/typing-typeddict.pyi]
65946599

65956600
[case testNoIncrementalCrashOnInvalidTypedDictFunc]
65966601
import m
@@ -6600,10 +6605,11 @@ import counts
66006605
import counts
66016606
# touch
66026607
[file counts.py]
6603-
from typing_extensions import TypedDict
6608+
from typing import TypedDict
66046609
def test() -> None:
66056610
Counts = TypedDict("Counts", {k: int for k in "abc"}) # type: ignore
66066611
[builtins fixtures/dict.pyi]
6612+
[typing fixtures/typing-typeddict.pyi]
66076613

66086614
[case testNoIncrementalCrashOnTypedDictMethod]
66096615
import a
@@ -6615,13 +6621,14 @@ from b import C
66156621
x: C
66166622
reveal_type(x.h)
66176623
[file b.py]
6618-
from typing_extensions import TypedDict
6624+
from typing import TypedDict
66196625
class C:
66206626
def __init__(self) -> None:
66216627
self.h: Hidden
66226628
class Hidden(TypedDict):
66236629
x: int
66246630
[builtins fixtures/dict.pyi]
6631+
[typing fixtures/typing-typeddict.pyi]
66256632
[out]
66266633
[out2]
66276634
tmp/a.py:3: note: Revealed type is "TypedDict('b.C.Hidden@5', {'x': builtins.int})"

test-data/unit/check-inference.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ class B: pass
12391239
[out]
12401240

12411241
[case testForStatementIndexNarrowing]
1242-
from typing_extensions import TypedDict
1242+
from typing import TypedDict
12431243

12441244
class X(TypedDict):
12451245
hourly: int
@@ -1266,6 +1266,7 @@ for b in ("hourly", "daily"):
12661266
reveal_type(b) # N: Revealed type is "builtins.str"
12671267
reveal_type(b.upper()) # N: Revealed type is "builtins.str"
12681268
[builtins fixtures/for.pyi]
1269+
[typing fixtures/typing-full.pyi]
12691270

12701271

12711272
-- Regression tests

0 commit comments

Comments
 (0)