Skip to content

Commit a1e282e

Browse files
committed
Update imports + use Union syntax
1 parent f27aa23 commit a1e282e

Some content is hidden

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

84 files changed

+212
-203
lines changed

misc/analyze_cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import os.path
88
from collections import Counter
99
from collections.abc import Iterable
10-
from typing import Any, Final
11-
from typing_extensions import TypeAlias as _TypeAlias
10+
from typing import Any, Final, TypeAlias as _TypeAlias
1211

1312
ROOT: Final = ".mypy_cache/3.5"
1413

misc/incremental_checker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
import textwrap
4545
import time
4646
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
47-
from typing import Any, Final
48-
from typing_extensions import TypeAlias as _TypeAlias
47+
from typing import Any, Final, TypeAlias as _TypeAlias
4948

5049
CACHE_PATH: Final = ".incremental_checker_cache.json"
5150
MYPY_REPO_URL: Final = "https://github.com/python/mypy.git"

misc/perf_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import subprocess
99
import textwrap
1010
import time
11-
from typing import Callable
11+
from collections.abc import Callable
1212

1313

1414
class Command:

mypy/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@
4646
from __future__ import annotations
4747

4848
import sys
49+
from collections.abc import Callable
4950
from io import StringIO
50-
from typing import Callable, TextIO
51+
from typing import TextIO
5152

5253

5354
def _run(main_wrapper: Callable[[TextIO, TextIO], None]) -> tuple[str, str, int]:

mypy/applytype.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
from collections.abc import Iterable, Sequence
4-
from typing import Callable
3+
from collections.abc import Callable, Iterable, Sequence
54

65
import mypy.subtypes
76
from mypy.erasetype import erase_typevars

mypy/argmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from __future__ import annotations
44

5-
from collections.abc import Sequence
6-
from typing import TYPE_CHECKING, Callable
5+
from collections.abc import Callable, Sequence
6+
from typing import TYPE_CHECKING
77

88
from mypy import nodes
99
from mypy.maptype import map_instance_to_supertype

mypy/binder.py

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

98
from mypy.erasetype import remove_instance_last_known_values
109
from mypy.literals import Key, extract_var_from_literal_hash, literal, literal_hash, subkeys
@@ -39,7 +38,7 @@
3938
)
4039
from mypy.typevars import fill_typevars_with_any
4140

42-
BindableExpression: _TypeAlias = Union[IndexExpr, MemberExpr, NameExpr]
41+
BindableExpression: _TypeAlias = IndexExpr | MemberExpr | NameExpr
4342

4443

4544
class CurrentType(NamedTuple):
@@ -81,7 +80,7 @@ def __repr__(self) -> str:
8180
return f"Frame({self.id}, {self.types}, {self.unreachable}, {self.conditional_frame})"
8281

8382

84-
Assigns = defaultdict[Expression, list[tuple[Type, Optional[Type]]]]
83+
Assigns = defaultdict[Expression, list[tuple[Type, Type | None]]]
8584

8685

8786
class ConditionalTypeBinder:

mypy/build.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,17 @@
2424
import sys
2525
import time
2626
import types
27-
from collections.abc import Iterator, Mapping, Sequence, Set as AbstractSet
28-
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Final, NoReturn, TextIO, TypedDict
29-
from typing_extensions import TypeAlias as _TypeAlias
27+
from collections.abc import Callable, Iterator, Mapping, Sequence, Set as AbstractSet
28+
from typing import (
29+
TYPE_CHECKING,
30+
Any,
31+
ClassVar,
32+
Final,
33+
NoReturn,
34+
TextIO,
35+
TypeAlias as _TypeAlias,
36+
TypedDict,
37+
)
3038

3139
import mypy.semanal_main
3240
from mypy.cache import Buffer, CacheMeta

mypy/cache.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
from __future__ import annotations
4646

4747
from collections.abc import Sequence
48-
from typing import Any, Final, Union
49-
from typing_extensions import TypeAlias as _TypeAlias
48+
from typing import Any, Final, TypeAlias as _TypeAlias
5049

5150
from librt.internal import (
5251
Buffer as Buffer,
@@ -384,7 +383,7 @@ def write_str_opt_list(data: Buffer, value: list[str | None]) -> None:
384383
write_str_opt(data, item)
385384

386385

387-
JsonValue: _TypeAlias = Union[None, int, str, bool, list["JsonValue"], dict[str, "JsonValue"]]
386+
JsonValue: _TypeAlias = None | int | str | bool | list["JsonValue"] | dict[str, "JsonValue"]
388387

389388

390389
def read_json_value(data: Buffer) -> JsonValue:

mypy/checker.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44

55
import itertools
66
from collections import defaultdict
7-
from collections.abc import Iterable, Iterator, Mapping, Sequence, Set as AbstractSet
7+
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence, Set as AbstractSet
88
from contextlib import ExitStack, contextmanager
99
from typing import (
10-
Callable,
1110
Final,
1211
Generic,
1312
Literal,
1413
NamedTuple,
15-
Optional,
14+
TypeAlias as _TypeAlias,
15+
TypeGuard,
1616
TypeVar,
17-
Union,
1817
cast,
1918
overload,
2019
)
21-
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard
2220

2321
import mypy.checkexpr
2422
from mypy import errorcodes as codes, join, message_registry, nodes, operators
@@ -247,8 +245,8 @@
247245
# Maximum length of fixed tuple types inferred when narrowing from variadic tuples.
248246
MAX_PRECISE_TUPLE_SIZE: Final = 8
249247

250-
DeferredNodeType: _TypeAlias = Union[FuncDef, OverloadedFuncDef, Decorator]
251-
FineGrainedDeferredNodeType: _TypeAlias = Union[FuncDef, MypyFile, OverloadedFuncDef]
248+
DeferredNodeType: _TypeAlias = FuncDef | OverloadedFuncDef | Decorator
249+
FineGrainedDeferredNodeType: _TypeAlias = FuncDef | MypyFile | OverloadedFuncDef
252250

253251

254252
# A node which is postponed to be processed during the next pass.
@@ -281,7 +279,7 @@ class FineGrainedDeferredNode(NamedTuple):
281279
# (such as two references to the same variable). TODO: it would
282280
# probably be better to have the dict keyed by the nodes' literal_hash
283281
# field instead.
284-
TypeMap: _TypeAlias = Optional[dict[Expression, Type]]
282+
TypeMap: _TypeAlias = dict[Expression, Type] | None
285283

286284

287285
# Keeps track of partial types in a single scope. In fine-grained incremental

0 commit comments

Comments
 (0)