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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 5 additions & 3 deletions
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

Lines changed: 4 additions & 5 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 5 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 4 deletions
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:

0 commit comments

Comments
 (0)