Skip to content

Commit 777b2a3

Browse files
authored
Use PEP 585 collections (#18378)
1 parent 7982761 commit 777b2a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+122
-156
lines changed

misc/analyze_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import os.path
88
from collections import Counter
99
from collections.abc import Iterable
10-
from typing import Any, Dict, Final
10+
from typing import Any, Final
1111
from typing_extensions import TypeAlias as _TypeAlias
1212

1313
ROOT: Final = ".mypy_cache/3.5"
1414

15-
JsonDict: _TypeAlias = Dict[str, Any]
15+
JsonDict: _TypeAlias = dict[str, Any]
1616

1717

1818
class CacheData:

misc/incremental_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
import textwrap
4545
import time
4646
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
47-
from typing import Any, Dict, Final
47+
from typing import Any, Final
4848
from typing_extensions import TypeAlias as _TypeAlias
4949

5050
CACHE_PATH: Final = ".incremental_checker_cache.json"
5151
MYPY_REPO_URL: Final = "https://github.com/python/mypy.git"
5252
MYPY_TARGET_FILE: Final = "mypy"
5353
DAEMON_CMD: Final = ["python3", "-m", "mypy.dmypy"]
5454

55-
JsonDict: _TypeAlias = Dict[str, Any]
55+
JsonDict: _TypeAlias = dict[str, Any]
5656

5757

5858
def print_offset(text: str, indent_length: int = 4) -> None:

mypy/binder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections import defaultdict
44
from collections.abc import Iterator
55
from contextlib import contextmanager
6-
from typing import DefaultDict, List, NamedTuple, Optional, Tuple, Union
6+
from typing import NamedTuple, Optional, Union
77
from typing_extensions import TypeAlias as _TypeAlias
88

99
from mypy.erasetype import remove_instance_last_known_values
@@ -59,7 +59,7 @@ def __repr__(self) -> str:
5959
return f"Frame({self.id}, {self.types}, {self.unreachable}, {self.conditional_frame})"
6060

6161

62-
Assigns = DefaultDict[Expression, List[Tuple[Type, Optional[Type]]]]
62+
Assigns = defaultdict[Expression, list[tuple[Type, Optional[Type]]]]
6363

6464

6565
class ConditionalTypeBinder:

mypy/build.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
Any,
3333
Callable,
3434
ClassVar,
35-
Dict,
3635
Final,
3736
NamedTuple,
3837
NoReturn,
@@ -118,7 +117,7 @@
118117
}
119118

120119

121-
Graph: _TypeAlias = Dict[str, "State"]
120+
Graph: _TypeAlias = dict[str, "State"]
122121

123122

124123
# TODO: Get rid of BuildResult. We might as well return a BuildManager.

mypy/checker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
from typing import (
1010
AbstractSet,
1111
Callable,
12-
Dict,
1312
Final,
1413
Generic,
1514
NamedTuple,
1615
Optional,
17-
Tuple,
1816
TypeVar,
1917
Union,
2018
cast,
@@ -265,7 +263,7 @@ class FineGrainedDeferredNode(NamedTuple):
265263
# (such as two references to the same variable). TODO: it would
266264
# probably be better to have the dict keyed by the nodes' literal_hash
267265
# field instead.
268-
TypeMap: _TypeAlias = Optional[Dict[Expression, Type]]
266+
TypeMap: _TypeAlias = Optional[dict[Expression, Type]]
269267

270268

271269
# An object that represents either a precise type or a type with an upper bound;
@@ -7813,7 +7811,7 @@ def conditional_types_to_typemaps(
78137811
assert typ is not None
78147812
maps.append({expr: typ})
78157813

7816-
return cast(Tuple[TypeMap, TypeMap], tuple(maps))
7814+
return cast(tuple[TypeMap, TypeMap], tuple(maps))
78177815

78187816

78197817
def gen_unique_name(base: str, table: SymbolTable) -> str:

mypy/checkexpr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from collections import defaultdict
99
from collections.abc import Iterable, Iterator, Sequence
1010
from contextlib import contextmanager
11-
from typing import Callable, ClassVar, Final, List, Optional, cast
11+
from typing import Callable, ClassVar, Final, Optional, cast
1212
from typing_extensions import TypeAlias as _TypeAlias, assert_never, overload
1313

1414
import mypy.checker
@@ -1966,7 +1966,7 @@ def infer_arg_types_in_context(
19661966
if not t:
19671967
res[i] = self.accept(args[i])
19681968
assert all(tp is not None for tp in res)
1969-
return cast(List[Type], res)
1969+
return cast(list[Type], res)
19701970

19711971
def infer_function_type_arguments_using_context(
19721972
self, callable: CallableType, error_context: Context

mypy/checkstrformat.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import re
1616
from re import Match, Pattern
17-
from typing import TYPE_CHECKING, Callable, Dict, Final, Tuple, Union, cast
17+
from typing import TYPE_CHECKING, Callable, Final, Union, cast
1818
from typing_extensions import TypeAlias as _TypeAlias
1919

2020
import mypy.errorcodes as codes
@@ -70,8 +70,8 @@
7070
from mypy.typeops import custom_special_method
7171

7272
FormatStringExpr: _TypeAlias = Union[StrExpr, BytesExpr]
73-
Checkers: _TypeAlias = Tuple[Callable[[Expression], None], Callable[[Type], bool]]
74-
MatchMap: _TypeAlias = Dict[Tuple[int, int], Match[str]] # span -> match
73+
Checkers: _TypeAlias = tuple[Callable[[Expression], None], Callable[[Type], bool]]
74+
MatchMap: _TypeAlias = dict[tuple[int, int], Match[str]] # span -> match
7575

7676

7777
def compile_format_re() -> Pattern[str]:

mypy/config_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
import tomli as tomllib
1717

1818
from collections.abc import Iterable, Mapping, MutableMapping, Sequence
19-
from typing import Any, Callable, Dict, Final, List, TextIO, Tuple, Union
19+
from typing import Any, Callable, Final, TextIO, Union
2020
from typing_extensions import TypeAlias as _TypeAlias
2121

2222
from mypy import defaults
2323
from mypy.options import PER_MODULE_OPTIONS, Options
2424

2525
_CONFIG_VALUE_TYPES: _TypeAlias = Union[
26-
str, bool, int, float, Dict[str, str], List[str], Tuple[int, int]
26+
str, bool, int, float, dict[str, str], list[str], tuple[int, int]
2727
]
2828
_INI_PARSER_CALLABLE: _TypeAlias = Callable[[Any], _CONFIG_VALUE_TYPES]
2929

mypy/constraints.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from collections.abc import Iterable, Sequence
6-
from typing import TYPE_CHECKING, Final, List
6+
from typing import TYPE_CHECKING, Final
77

88
import mypy.subtypes
99
import mypy.typeops
@@ -627,7 +627,7 @@ def visit_uninhabited_type(self, t: UninhabitedType) -> bool:
627627
return False
628628

629629

630-
class ConstraintBuilderVisitor(TypeVisitor[List[Constraint]]):
630+
class ConstraintBuilderVisitor(TypeVisitor[list[Constraint]]):
631631
"""Visitor class for inferring type constraints."""
632632

633633
# The type that is compared against a template

mypy/dmypy_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import traceback
1919
from collections.abc import Sequence
2020
from contextlib import redirect_stderr, redirect_stdout
21-
from typing import AbstractSet, Any, Callable, Final, List, Tuple
21+
from typing import AbstractSet, Any, Callable, Final
2222
from typing_extensions import TypeAlias as _TypeAlias
2323

2424
import mypy.build
@@ -162,9 +162,9 @@ def ignore_suppressed_imports(module: str) -> bool:
162162
return module.startswith("encodings.")
163163

164164

165-
ModulePathPair: _TypeAlias = Tuple[str, str]
166-
ModulePathPairs: _TypeAlias = List[ModulePathPair]
167-
ChangesAndRemovals: _TypeAlias = Tuple[ModulePathPairs, ModulePathPairs]
165+
ModulePathPair: _TypeAlias = tuple[str, str]
166+
ModulePathPairs: _TypeAlias = list[ModulePathPair]
167+
ChangesAndRemovals: _TypeAlias = tuple[ModulePathPairs, ModulePathPairs]
168168

169169

170170
class Server:

0 commit comments

Comments
 (0)