Skip to content

Commit 51bceb7

Browse files
committed
Use PEP 604 annotations everywhere
1 parent 1a6ff59 commit 51bceb7

32 files changed

+54
-56
lines changed

mypy/binder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
)
4040
from mypy.typevars import fill_typevars_with_any
4141

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

4444

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

8383

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

8686

8787
class ConditionalTypeBinder:

mypy/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ def write_str_opt_list(data: WriteBuffer, value: list[str | None]) -> None:
391391
write_str_opt(data, item)
392392

393393

394-
JsonValue: _TypeAlias = Union[None, int, str, bool, list["JsonValue"], dict[str, "JsonValue"]]
394+
JsonValue: _TypeAlias = None | int | str | bool | list["JsonValue"] | dict[str, "JsonValue"]
395395

396396

397397
def read_json_value(data: ReadBuffer) -> JsonValue:

mypy/checker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@
249249
# Maximum length of fixed tuple types inferred when narrowing from variadic tuples.
250250
MAX_PRECISE_TUPLE_SIZE: Final = 8
251251

252-
DeferredNodeType: _TypeAlias = Union[FuncDef, OverloadedFuncDef, Decorator]
253-
FineGrainedDeferredNodeType: _TypeAlias = Union[FuncDef, MypyFile, OverloadedFuncDef]
252+
DeferredNodeType: _TypeAlias = FuncDef | OverloadedFuncDef | Decorator
253+
FineGrainedDeferredNodeType: _TypeAlias = FuncDef | MypyFile | OverloadedFuncDef
254254

255255

256256
# A node which is postponed to be processed during the next pass.
@@ -283,7 +283,7 @@ class FineGrainedDeferredNode(NamedTuple):
283283
# (such as two references to the same variable). TODO: it would
284284
# probably be better to have the dict keyed by the nodes' literal_hash
285285
# field instead.
286-
TypeMap: _TypeAlias = Optional[dict[Expression, Type]]
286+
TypeMap: _TypeAlias = dict[Expression, Type] | None
287287

288288

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

mypy/checkexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
# Type of callback user for checking individual function arguments. See
218218
# check_args() below for details.
219219
ArgChecker: _TypeAlias = Callable[
220-
[Type, Type, ArgKind, Type, int, int, CallableType, Optional[Type], Context, Context], None
220+
[Type, Type, ArgKind, Type, int, int, CallableType, Type | None, Context, Context], None
221221
]
222222

223223
# Maximum nesting level for math union in overloads, setting this to large values

mypy/checkstrformat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
get_proper_types,
6565
)
6666

67-
FormatStringExpr: _TypeAlias = Union[StrExpr, BytesExpr]
67+
FormatStringExpr: _TypeAlias = StrExpr | BytesExpr
6868
Checkers: _TypeAlias = tuple[Callable[[Expression], None], Callable[[Type], bool]]
6969
MatchMap: _TypeAlias = dict[tuple[int, int], Match[str]] # span -> match
7070

mypy/config_parser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
from mypy import defaults
2121
from mypy.options import PER_MODULE_OPTIONS, Options
2222

23-
_CONFIG_VALUE_TYPES: TypeAlias = Union[
24-
str, bool, int, float, dict[str, str], list[str], tuple[int, int]
25-
]
23+
_CONFIG_VALUE_TYPES: TypeAlias = str | bool | int | float | dict[str, str] | list[str] | tuple[int, int]
2624
_INI_PARSER_CALLABLE: TypeAlias = Callable[[Any], _CONFIG_VALUE_TYPES]
2725

2826

mypy/constant_fold.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from __future__ import annotations
77

8-
from typing import Final, Union
8+
from typing import Final
99

1010
from mypy.nodes import (
1111
ComplexExpr,
@@ -20,7 +20,7 @@
2020
)
2121

2222
# All possible result types of constant folding
23-
ConstantValue = Union[int, bool, float, complex, str]
23+
ConstantValue = int | bool | float | complex | str
2424
CONST_TYPES: Final = (int, bool, float, complex, str)
2525

2626

mypy/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def __init__(
155155

156156
# Type used internally to represent errors:
157157
# (path, line, column, end_line, end_column, severity, message, code)
158-
ErrorTuple: _TypeAlias = tuple[Optional[str], int, int, int, int, str, str, Optional[ErrorCode]]
158+
ErrorTuple: _TypeAlias = tuple[str | None, int, int, int, int, str, str, ErrorCode | None]
159159

160160

161161
class ErrorWatcher:

mypy/exportjson.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
get_proper_type,
7070
)
7171

72-
Json: _TypeAlias = Union[dict[str, Any], str]
72+
Json: _TypeAlias = dict[str, Any] | str
7373

7474

7575
class Config:

mypy/fastparse.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def fix_function_overloads(self, stmts: list[Statement]) -> list[Statement]:
714714
current_overload.extend(if_block_with_overload.body[-1].items)
715715
else:
716716
current_overload.append(
717-
cast(Union[Decorator, FuncDef], if_block_with_overload.body[0])
717+
cast(Decorator | FuncDef, if_block_with_overload.body[0])
718718
)
719719
else:
720720
if last_if_stmt is not None:
@@ -760,7 +760,7 @@ def fix_function_overloads(self, stmts: list[Statement]) -> list[Statement]:
760760
cast(list[IfStmt], if_block_with_overload.body[:-1])
761761
)
762762
last_if_overload = cast(
763-
Union[Decorator, FuncDef, OverloadedFuncDef],
763+
Decorator | FuncDef | OverloadedFuncDef,
764764
if_block_with_overload.body[-1],
765765
)
766766
last_if_unknown_truth_value = if_unknown_truth_value
@@ -807,7 +807,7 @@ def _check_ifstmt_for_overloads(
807807
return None
808808

809809
overload_name = cast(
810-
Union[Decorator, FuncDef, OverloadedFuncDef], stmt.body[0].body[-1]
810+
Decorator | FuncDef | OverloadedFuncDef, stmt.body[0].body[-1]
811811
).name
812812
if stmt.else_body is None:
813813
return overload_name
@@ -991,7 +991,7 @@ def do_func_def(
991991
self.errors, line=lineno, override_column=n.col_offset
992992
).translate_expr_list(func_type_ast.argtypes)
993993
# Use a cast to work around `list` invariance
994-
arg_types = cast(list[Optional[Type]], translated_args)
994+
arg_types = cast(list[Type | None], translated_args)
995995
return_type = TypeConverter(self.errors, line=lineno).visit(func_type_ast.returns)
996996

997997
# add implicit self type
@@ -1646,7 +1646,7 @@ def visit_Call(self, n: Call) -> CallExpr:
16461646
self.visit(n.func),
16471647
arg_types,
16481648
arg_kinds,
1649-
cast("list[Optional[str]]", [None] * len(args)) + keyword_names,
1649+
cast("list[str | None]", [None] * len(args)) + keyword_names,
16501650
)
16511651
return self.set_line(e, n)
16521652

0 commit comments

Comments
 (0)