Skip to content

Commit 0c60548

Browse files
authored
Update TypedDict imports in tests (#18528)
`mypy_extensions.TypedDict` has been redundant for a while now. With the next mypy_extensions release, it will raise a `DeprecationWarning` when imported. Replace existing imports in tests with `typing.TypedDict`.
1 parent 1b24bf7 commit 0c60548

21 files changed

+412
-349
lines changed

test-data/unit/check-classes.test

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5184,11 +5184,12 @@ def test() -> None:
51845184
[builtins fixtures/tuple.pyi]
51855185

51865186
[case testCrashOnSelfRecursiveTypedDictVar]
5187-
from mypy_extensions import TypedDict
5187+
from typing import TypedDict
51885188

51895189
A = TypedDict('A', {'a': 'A'}) # type: ignore
51905190
a: A
51915191
[builtins fixtures/isinstancelist.pyi]
5192+
[typing fixtures/typing-typeddict.pyi]
51925193

51935194
[case testCrashInJoinOfSelfRecursiveNamedTuples]
51945195

@@ -5205,7 +5206,7 @@ lst = [n, m]
52055206
[builtins fixtures/isinstancelist.pyi]
52065207

52075208
[case testCorrectJoinOfSelfRecursiveTypedDicts]
5208-
from mypy_extensions import TypedDict
5209+
from typing import TypedDict
52095210

52105211
def test() -> None:
52115212
class N(TypedDict):
@@ -5220,6 +5221,7 @@ def test() -> None:
52205221
lst = [n, m]
52215222
reveal_type(lst[0]['x']) # N: Revealed type is "Any"
52225223
[builtins fixtures/isinstancelist.pyi]
5224+
[typing fixtures/typing-typeddict.pyi]
52235225

52245226
[case testCrashInForwardRefToNamedTupleWithIsinstance]
52255227
from typing import Dict, NamedTuple
@@ -5236,8 +5238,7 @@ def parse_ast(name_dict: NameDict) -> None:
52365238
[typing fixtures/typing-medium.pyi]
52375239

52385240
[case testCrashInForwardRefToTypedDictWithIsinstance]
5239-
from mypy_extensions import TypedDict
5240-
from typing import Dict
5241+
from typing import Dict, TypedDict
52415242

52425243
NameDict = Dict[str, 'NameInfo']
52435244
class NameInfo(TypedDict):
@@ -5248,7 +5249,7 @@ def parse_ast(name_dict: NameDict) -> None:
52485249
pass
52495250
reveal_type(name_dict['']['ast']) # N: Revealed type is "builtins.bool"
52505251
[builtins fixtures/isinstancelist.pyi]
5251-
[typing fixtures/typing-medium.pyi]
5252+
[typing fixtures/typing-typeddict.pyi]
52525253

52535254
[case testCorrectIsinstanceInForwardRefToNewType]
52545255
from typing import Dict, NewType
@@ -5313,13 +5314,13 @@ x = NT(N(1))
53135314

53145315
[case testNewTypeFromForwardTypedDict]
53155316

5316-
from typing import NewType, Tuple
5317-
from mypy_extensions import TypedDict
5317+
from typing import NewType, Tuple, TypedDict
53185318

53195319
NT = NewType('NT', 'N') # E: Argument 2 to NewType(...) must be subclassable (got "N")
53205320
class N(TypedDict):
53215321
x: int
53225322
[builtins fixtures/dict.pyi]
5323+
[typing fixtures/typing-typeddict.pyi]
53235324
[out]
53245325

53255326
[case testCorrectAttributeInForwardRefToNamedTuple]
@@ -5335,7 +5336,7 @@ class Process(NamedTuple):
53355336
[out]
53365337

53375338
[case testCorrectItemTypeInForwardRefToTypedDict]
5338-
from mypy_extensions import TypedDict
5339+
from typing import TypedDict
53395340
proc: Process
53405341
reveal_type(proc['state']) # N: Revealed type is "builtins.int"
53415342

@@ -5344,6 +5345,7 @@ def get_state(proc: 'Process') -> int:
53445345
class Process(TypedDict):
53455346
state: int
53465347
[builtins fixtures/isinstancelist.pyi]
5348+
[typing fixtures/typing-typeddict.pyi]
53475349
[out]
53485350

53495351
[case testCorrectDoubleForwardNamedTuple]
@@ -5362,7 +5364,7 @@ reveal_type(x.one.attr) # N: Revealed type is "builtins.str"
53625364
[out]
53635365

53645366
[case testCrashOnDoubleForwardTypedDict]
5365-
from mypy_extensions import TypedDict
5367+
from typing import TypedDict
53665368

53675369
x: A
53685370
class A(TypedDict):
@@ -5373,6 +5375,7 @@ class B(TypedDict):
53735375

53745376
reveal_type(x['one']['attr']) # N: Revealed type is "builtins.str"
53755377
[builtins fixtures/isinstancelist.pyi]
5378+
[typing fixtures/typing-typeddict.pyi]
53765379
[out]
53775380

53785381
[case testCrashOnForwardUnionOfNamedTuples]
@@ -5392,8 +5395,7 @@ def foo(node: Node) -> int:
53925395
[out]
53935396

53945397
[case testCrashOnForwardUnionOfTypedDicts]
5395-
from mypy_extensions import TypedDict
5396-
from typing import Union
5398+
from typing import TypedDict, Union
53975399

53985400
NodeType = Union['Foo', 'Bar']
53995401
class Foo(TypedDict):
@@ -5405,6 +5407,7 @@ def foo(node: NodeType) -> int:
54055407
x = node
54065408
return x['x']
54075409
[builtins fixtures/isinstancelist.pyi]
5410+
[typing fixtures/typing-typeddict.pyi]
54085411
[out]
54095412

54105413
[case testSupportForwardUnionOfNewTypes]
@@ -5471,8 +5474,7 @@ def f(x: ForwardUnion) -> None:
54715474
[out]
54725475

54735476
[case testCrashInvalidArgsSyntheticClassSyntax]
5474-
from typing import List, NamedTuple
5475-
from mypy_extensions import TypedDict
5477+
from typing import List, NamedTuple, TypedDict
54765478
class TD(TypedDict):
54775479
x: List[int, str] # E: "list" expects 1 type argument, but 2 given
54785480
class NM(NamedTuple):
@@ -5482,11 +5484,11 @@ class NM(NamedTuple):
54825484
TD({'x': []})
54835485
NM(x=[])
54845486
[builtins fixtures/dict.pyi]
5487+
[typing fixtures/typing-typeddict.pyi]
54855488
[out]
54865489

54875490
[case testCrashInvalidArgsSyntheticClassSyntaxReveals]
5488-
from typing import List, NamedTuple
5489-
from mypy_extensions import TypedDict
5491+
from typing import List, NamedTuple, TypedDict
54905492
class TD(TypedDict):
54915493
x: List[int, str] # E: "list" expects 1 type argument, but 2 given
54925494
class NM(NamedTuple):
@@ -5501,11 +5503,11 @@ reveal_type(x1) # N: Revealed type is "TypedDict('__main__.TD', {'x': builtins.l
55015503
reveal_type(y) # N: Revealed type is "Tuple[builtins.list[Any], fallback=__main__.NM]"
55025504
reveal_type(y1) # N: Revealed type is "Tuple[builtins.list[Any], fallback=__main__.NM]"
55035505
[builtins fixtures/dict.pyi]
5506+
[typing fixtures/typing-typeddict.pyi]
55045507
[out]
55055508

55065509
[case testCrashInvalidArgsSyntheticFunctionSyntax]
5507-
from typing import List, NewType, NamedTuple
5508-
from mypy_extensions import TypedDict
5510+
from typing import List, NewType, NamedTuple, TypedDict
55095511
TD = TypedDict('TD', {'x': List[int, str]}) # E: "list" expects 1 type argument, but 2 given
55105512
NM = NamedTuple('NM', [('x', List[int, str])]) # E: "list" expects 1 type argument, but 2 given
55115513
NT = NewType('NT', List[int, str]) # E: "list" expects 1 type argument, but 2 given
@@ -5515,11 +5517,11 @@ TD({'x': []})
55155517
NM(x=[])
55165518
NT([])
55175519
[builtins fixtures/dict.pyi]
5520+
[typing fixtures/typing-typeddict.pyi]
55185521
[out]
55195522

55205523
[case testCrashForwardSyntheticClassSyntax]
5521-
from typing import NamedTuple
5522-
from mypy_extensions import TypedDict
5524+
from typing import NamedTuple, TypedDict
55235525
class A1(NamedTuple):
55245526
b: 'B'
55255527
x: int
@@ -5533,11 +5535,11 @@ y: A2
55335535
reveal_type(x.b) # N: Revealed type is "__main__.B"
55345536
reveal_type(y['b']) # N: Revealed type is "__main__.B"
55355537
[builtins fixtures/dict.pyi]
5538+
[typing fixtures/typing-typeddict.pyi]
55365539
[out]
55375540

55385541
[case testCrashForwardSyntheticFunctionSyntax]
5539-
from typing import NamedTuple
5540-
from mypy_extensions import TypedDict
5542+
from typing import NamedTuple, TypedDict
55415543
A1 = NamedTuple('A1', [('b', 'B'), ('x', int)])
55425544
A2 = TypedDict('A2', {'b': 'B', 'x': int})
55435545
class B:
@@ -5547,6 +5549,7 @@ y: A2
55475549
reveal_type(x.b) # N: Revealed type is "__main__.B"
55485550
reveal_type(y['b']) # N: Revealed type is "__main__.B"
55495551
[builtins fixtures/dict.pyi]
5552+
[typing fixtures/typing-typeddict.pyi]
55505553
[out]
55515554

55525555
-- Special support for six

test-data/unit/check-custom-plugin.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,7 @@ plugins=<ROOT>/test-data/unit/plugins/method_sig_hook.py
579579

580580
[case testMethodSignatureHookNamesFullyQualified]
581581
# flags: --config-file tmp/mypy.ini
582-
from mypy_extensions import TypedDict
583-
from typing import NamedTuple
582+
from typing import NamedTuple, TypedDict
584583

585584
class FullyQualifiedTestClass:
586585
@classmethod
@@ -601,6 +600,7 @@ reveal_type(FullyQualifiedTestNamedTuple('')._asdict()) # N: Revealed type is "b
601600
\[mypy]
602601
plugins=<ROOT>/test-data/unit/plugins/fully_qualified_test_hook.py
603602
[builtins fixtures/classmethod.pyi]
603+
[typing fixtures/typing-typeddict.pyi]
604604

605605
[case testDynamicClassPlugin]
606606
# flags: --config-file tmp/mypy.ini

test-data/unit/check-flags.test

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,25 +1082,25 @@ main:6: error: A type on this line becomes "Any" due to an unfollowed import
10821082

10831083
[case testDisallowUnimportedAnyTypedDictSimple]
10841084
# flags: --ignore-missing-imports --disallow-any-unimported
1085-
from mypy_extensions import TypedDict
1085+
from typing import TypedDict
10861086
from x import Unchecked
10871087

10881088
M = TypedDict('M', {'x': str, 'y': Unchecked}) # E: Type of a TypedDict key becomes "Any" due to an unfollowed import
10891089

10901090
def f(m: M) -> M: pass # no error
10911091
[builtins fixtures/dict.pyi]
1092+
[typing fixtures/typing-typeddict.pyi]
10921093

10931094
[case testDisallowUnimportedAnyTypedDictGeneric]
10941095
# flags: --ignore-missing-imports --disallow-any-unimported
1095-
1096-
from mypy_extensions import TypedDict
1097-
from typing import List
1096+
from typing import List, TypedDict
10981097
from x import Unchecked
10991098

11001099
M = TypedDict('M', {'x': str, 'y': List[Unchecked]}) # E: Type of a TypedDict key becomes "List[Any]" due to an unfollowed import
11011100

11021101
def f(m: M) -> M: pass # no error
11031102
[builtins fixtures/dict.pyi]
1103+
[typing fixtures/typing-typeddict.pyi]
11041104

11051105
[case testDisallowAnyDecoratedUnannotatedDecorator]
11061106
# flags: --disallow-any-decorated
@@ -1337,13 +1337,14 @@ def k(s: E) -> None: pass
13371337

13381338
[case testDisallowAnyExprTypedDict]
13391339
# flags: --disallow-any-expr
1340-
from mypy_extensions import TypedDict
1340+
from typing import TypedDict
13411341

13421342
Movie = TypedDict('Movie', {'name': str, 'year': int})
13431343

13441344
def g(m: Movie) -> Movie:
13451345
return m
13461346
[builtins fixtures/dict.pyi]
1347+
[typing fixtures/typing-typeddict.pyi]
13471348

13481349
[case testDisallowIncompleteDefs]
13491350
# flags: --disallow-incomplete-defs
@@ -1483,8 +1484,7 @@ n: N
14831484

14841485
[case testCheckDisallowAnyGenericsTypedDict]
14851486
# flags: --disallow-any-generics
1486-
from typing import Dict, Any, Optional
1487-
from mypy_extensions import TypedDict
1487+
from typing import Dict, Any, Optional, TypedDict
14881488

14891489
VarsDict = Dict[str, Any]
14901490
HostsDict = Dict[str, Optional[VarsDict]]
@@ -1497,6 +1497,7 @@ GroupDataDict = TypedDict(
14971497

14981498
GroupsDict = Dict[str, GroupDataDict] # type: ignore
14991499
[builtins fixtures/dict.pyi]
1500+
[typing fixtures/typing-typeddict.pyi]
15001501

15011502

15021503
[case testCheckDisallowAnyGenericsStubOnly]
@@ -1929,22 +1930,22 @@ Bar = NewType('Bar', List[Any]) # E: Explicit "Any" is not allowed [explicit-a
19291930

19301931
[case testDisallowAnyExplicitTypedDictSimple]
19311932
# flags: --disallow-any-explicit --show-error-codes
1932-
from mypy_extensions import TypedDict
1933-
from typing import Any
1933+
from typing import Any, TypedDict
19341934

19351935
M = TypedDict('M', {'x': str, 'y': Any}) # E: Explicit "Any" is not allowed [explicit-any]
19361936
M(x='x', y=2) # no error
19371937
def f(m: M) -> None: pass # no error
19381938
[builtins fixtures/dict.pyi]
1939+
[typing fixtures/typing-typeddict.pyi]
19391940

19401941
[case testDisallowAnyExplicitTypedDictGeneric]
19411942
# flags: --disallow-any-explicit --show-error-codes
1942-
from mypy_extensions import TypedDict
1943-
from typing import Any, List
1943+
from typing import Any, List, TypedDict
19441944

19451945
M = TypedDict('M', {'x': str, 'y': List[Any]}) # E: Explicit "Any" is not allowed [explicit-any]
19461946
N = TypedDict('N', {'x': str, 'y': List}) # no error
19471947
[builtins fixtures/dict.pyi]
1948+
[typing fixtures/typing-typeddict.pyi]
19481949

19491950
[case testDisallowAnyGenericsTupleNoTypeParams]
19501951
# flags: --disallow-any-generics

0 commit comments

Comments
 (0)