Skip to content

Commit dcdcc60

Browse files
authored
Run pyupgrade --py38-plus on the source code (#15575)
1 parent 49d95cf commit dcdcc60

Some content is hidden

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

80 files changed

+137
-168
lines changed

misc/analyze_cache.py

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

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

misc/incremental_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
import textwrap
4545
import time
4646
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
47-
from typing import Any, Dict
48-
from typing_extensions import Final, TypeAlias as _TypeAlias
47+
from typing import Any, Dict, Final
48+
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"

mypy/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
Callable,
3232
ClassVar,
3333
Dict,
34+
Final,
3435
Iterator,
3536
Mapping,
3637
NamedTuple,
3738
NoReturn,
3839
Sequence,
3940
TextIO,
4041
)
41-
from typing_extensions import Final, TypeAlias as _TypeAlias, TypedDict
42+
from typing_extensions import TypeAlias as _TypeAlias, TypedDict
4243

4344
import mypy.semanal_main
4445
from mypy.checker import TypeChecker

mypy/checker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
AbstractSet,
1010
Callable,
1111
Dict,
12+
Final,
1213
Generic,
1314
Iterable,
1415
Iterator,
@@ -22,7 +23,7 @@
2223
cast,
2324
overload,
2425
)
25-
from typing_extensions import Final, TypeAlias as _TypeAlias
26+
from typing_extensions import TypeAlias as _TypeAlias
2627

2728
import mypy.checkexpr
2829
from mypy import errorcodes as codes, message_registry, nodes, operators
@@ -1546,7 +1547,7 @@ def check_reverse_op_method(
15461547
if opt_meta is not None:
15471548
forward_inst = opt_meta
15481549

1549-
def has_readable_member(typ: Union[UnionType, Instance], name: str) -> bool:
1550+
def has_readable_member(typ: UnionType | Instance, name: str) -> bool:
15501551
# TODO: Deal with attributes of TupleType etc.
15511552
if isinstance(typ, Instance):
15521553
return typ.type.has_readable_member(name)

mypy/checkexpr.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import time
77
from collections import defaultdict
88
from contextlib import contextmanager
9-
from typing import Callable, ClassVar, Iterable, Iterator, List, Optional, Sequence, cast
10-
from typing_extensions import Final, TypeAlias as _TypeAlias, overload
9+
from typing import Callable, ClassVar, Final, Iterable, Iterator, List, Optional, Sequence, cast
10+
from typing_extensions import TypeAlias as _TypeAlias, overload
1111

1212
import mypy.checker
1313
import mypy.errorcodes as codes
@@ -5581,7 +5581,7 @@ def replace_callable_return_type(c: CallableType, new_ret_type: Type) -> Callabl
55815581
return c.copy_modified(ret_type=new_ret_type)
55825582

55835583

5584-
def apply_poly(tp: CallableType, poly_tvars: Sequence[TypeVarLikeType]) -> Optional[CallableType]:
5584+
def apply_poly(tp: CallableType, poly_tvars: Sequence[TypeVarLikeType]) -> CallableType | None:
55855585
"""Make free type variables generic in the type if possible.
55865586
55875587
This will translate the type `tp` while trying to create valid bindings for

mypy/checkpattern.py

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

55
from collections import defaultdict
6-
from typing import NamedTuple
7-
from typing_extensions import Final
6+
from typing import Final, NamedTuple
87

98
import mypy.checker
109
from mypy import message_registry

mypy/checkstrformat.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from __future__ import annotations
1414

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

1919
import mypy.errorcodes as codes
2020
from mypy.errors import Errors

mypy/config_parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Any,
2020
Callable,
2121
Dict,
22+
Final,
2223
Iterable,
2324
List,
2425
Mapping,
@@ -28,7 +29,7 @@
2829
Tuple,
2930
Union,
3031
)
31-
from typing_extensions import Final, TypeAlias as _TypeAlias
32+
from typing_extensions import TypeAlias as _TypeAlias
3233

3334
from mypy import defaults
3435
from mypy.options import PER_MODULE_OPTIONS, Options

mypy/constant_fold.py

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

66
from __future__ import annotations
77

8-
from typing import Union
9-
from typing_extensions import Final
8+
from typing import Final, Union
109

1110
from mypy.nodes import (
1211
ComplexExpr,

mypy/constraints.py

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

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, Iterable, List, Sequence, cast
6-
from typing_extensions import Final
5+
from typing import TYPE_CHECKING, Final, Iterable, List, Sequence, cast
76

87
import mypy.subtypes
98
import mypy.typeops

mypy/defaults.py

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

33
import os
4-
from typing_extensions import Final
4+
from typing import Final
55

66
PYTHON2_VERSION: Final = (2, 7)
77

mypy/dmypy_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import time
1818
import traceback
1919
from contextlib import redirect_stderr, redirect_stdout
20-
from typing import AbstractSet, Any, Callable, List, Sequence, Tuple
21-
from typing_extensions import Final, TypeAlias as _TypeAlias
20+
from typing import AbstractSet, Any, Callable, Final, List, Sequence, Tuple
21+
from typing_extensions import TypeAlias as _TypeAlias
2222

2323
import mypy.build
2424
import mypy.errors

mypy/dmypy_util.py

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

88
import json
9-
from typing import Any
10-
from typing_extensions import Final
9+
from typing import Any, Final
1110

1211
from mypy.ipc import IPCBase
1312

mypy/errorcodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from __future__ import annotations
77

88
from collections import defaultdict
9-
from typing_extensions import Final
9+
from typing import Final
1010

1111
from mypy_extensions import mypyc_attr
1212

mypy/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import sys
55
import traceback
66
from collections import defaultdict
7-
from typing import Callable, Iterable, NoReturn, Optional, TextIO, Tuple, TypeVar
8-
from typing_extensions import Final, Literal, TypeAlias as _TypeAlias
7+
from typing import Callable, Final, Iterable, NoReturn, Optional, TextIO, Tuple, TypeVar
8+
from typing_extensions import Literal, TypeAlias as _TypeAlias
99

1010
from mypy import errorcodes as codes
1111
from mypy.errorcodes import IMPORT, ErrorCode

mypy/evalexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
"""
99
import ast
10-
from typing_extensions import Final
10+
from typing import Final
1111

1212
import mypy.nodes
1313
from mypy.visitor import ExpressionVisitor

mypy/expandtype.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 typing import Iterable, Mapping, Sequence, TypeVar, cast, overload
4-
from typing_extensions import Final
3+
from typing import Final, Iterable, Mapping, Sequence, TypeVar, cast, overload
54

65
from mypy.nodes import ARG_POS, ARG_STAR, ArgKind, Var
76
from mypy.state import state

mypy/fastparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import re
55
import sys
66
import warnings
7-
from typing import Any, Callable, List, Optional, Sequence, TypeVar, Union, cast
8-
from typing_extensions import Final, Literal, overload
7+
from typing import Any, Callable, Final, List, Optional, Sequence, TypeVar, Union, cast
8+
from typing_extensions import Literal, overload
99

1010
from mypy import defaults, errorcodes as codes, message_registry
1111
from mypy.errors import Errors

mypy/find_sources.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import functools
66
import os
7-
from typing import Sequence
8-
from typing_extensions import Final
7+
from typing import Final, Sequence
98

109
from mypy.fscache import FileSystemCache
1110
from mypy.modulefinder import PYTHON_EXTENSIONS, BuildSource, matches_exclude, mypy_path
@@ -160,7 +159,7 @@ def crawl_up(self, path: str) -> tuple[str, str]:
160159
def crawl_up_dir(self, dir: str) -> tuple[str, str]:
161160
return self._crawl_up_helper(dir) or ("", dir)
162161

163-
@functools.lru_cache() # noqa: B019
162+
@functools.lru_cache # noqa: B019
164163
def _crawl_up_helper(self, dir: str) -> tuple[str, str] | None:
165164
"""Given a directory, maybe returns module and base directory.
166165

mypy/fixup.py

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

33
from __future__ import annotations
44

5-
from typing import Any
6-
from typing_extensions import Final
5+
from typing import Any, Final
76

87
from mypy.lookup import lookup_fully_qualified
98
from mypy.nodes import (

mypy/ipc.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import sys
1313
import tempfile
1414
from types import TracebackType
15-
from typing import Callable
16-
from typing_extensions import Final
15+
from typing import Callable, Final
1716

1817
if sys.platform == "win32":
1918
# This may be private, but it is needed for IPC on Windows, and is basically stable

mypy/literals.py

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

3-
from typing import Any, Iterable, Optional, Tuple
4-
from typing_extensions import Final, TypeAlias as _TypeAlias
3+
from typing import Any, Final, Iterable, Optional, Tuple
4+
from typing_extensions import TypeAlias as _TypeAlias
55

66
from mypy.nodes import (
77
LITERAL_NO,

mypy/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
import sys
99
import time
1010
from gettext import gettext
11-
from typing import IO, Any, NoReturn, Sequence, TextIO
12-
from typing_extensions import Final
11+
from typing import IO, Any, Final, NoReturn, Sequence, TextIO
1312

1413
from mypy import build, defaults, state, util
1514
from mypy.config_parser import get_config_module_names, parse_config_file, parse_version

mypy/message_registry.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
from __future__ import annotations
1010

11-
from typing import NamedTuple
12-
from typing_extensions import Final
11+
from typing import Final, NamedTuple
1312

1413
from mypy import errorcodes as codes
1514

mypy/messages.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import re
1717
from contextlib import contextmanager
1818
from textwrap import dedent
19-
from typing import Any, Callable, Collection, Iterable, Iterator, List, Sequence, cast
20-
from typing_extensions import Final
19+
from typing import Any, Callable, Collection, Final, Iterable, Iterator, List, Sequence, cast
2120

2221
import mypy.typeops
2322
from mypy import errorcodes as codes, message_registry

mypy/modulefinder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
else:
2222
import tomli as tomllib
2323

24-
from typing import Dict, List, NamedTuple, Optional, Tuple, Union
25-
from typing_extensions import Final, TypeAlias as _TypeAlias
24+
from typing import Dict, Final, List, NamedTuple, Optional, Tuple, Union
25+
from typing_extensions import TypeAlias as _TypeAlias
2626

2727
from mypy import pyinfo
2828
from mypy.fscache import FileSystemCache

mypy/nodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Any,
1212
Callable,
1313
Dict,
14+
Final,
1415
Iterator,
1516
List,
1617
Optional,
@@ -20,7 +21,7 @@
2021
Union,
2122
cast,
2223
)
23-
from typing_extensions import Final, TypeAlias as _TypeAlias, TypeGuard
24+
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard
2425

2526
from mypy_extensions import trait
2627

mypy/operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from typing_extensions import Final
5+
from typing import Final
66

77
# Map from binary operator id to related method name (in Python 3).
88
op_methods: Final = {

mypy/options.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import re
55
import sys
66
import sysconfig
7-
from typing import Any, Callable, Dict, Mapping, Pattern
8-
from typing_extensions import Final
7+
from typing import Any, Callable, Final, Mapping, Pattern
98

109
from mypy import defaults
1110
from mypy.errorcodes import ErrorCode, error_codes
@@ -529,7 +528,7 @@ def compile_glob(self, s: str) -> Pattern[str]:
529528
return re.compile(expr + "\\Z")
530529

531530
def select_options_affecting_cache(self) -> Mapping[str, object]:
532-
result: Dict[str, object] = {}
531+
result: dict[str, object] = {}
533532
for opt in OPTIONS_AFFECTING_CACHE:
534533
val = getattr(self, opt)
535534
if opt in ("disabled_error_codes", "enabled_error_codes"):

mypy/plugins/attrs.py

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

55
from collections import defaultdict
66
from functools import reduce
7-
from typing import Iterable, List, Mapping, cast
8-
from typing_extensions import Final, Literal
7+
from typing import Final, Iterable, List, Mapping, cast
8+
from typing_extensions import Literal
99

1010
import mypy.plugin # To avoid circular imports.
1111
from mypy.applytype import apply_generic_arguments

mypy/plugins/dataclasses.py

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

33
from __future__ import annotations
44

5-
from typing import TYPE_CHECKING, Iterator, Optional
6-
from typing_extensions import Final
5+
from typing import TYPE_CHECKING, Final, Iterator
76

87
from mypy import errorcodes, message_registry
98
from mypy.expandtype import expand_type, expand_type_by_instance
@@ -134,7 +133,7 @@ def to_argument(self, current_info: TypeInfo) -> Argument:
134133
kind=arg_kind,
135134
)
136135

137-
def expand_type(self, current_info: TypeInfo) -> Optional[Type]:
136+
def expand_type(self, current_info: TypeInfo) -> Type | None:
138137
if self.type is not None and self.info.self_type is not None:
139138
# In general, it is not safe to call `expand_type()` during semantic analyzis,
140139
# however this plugin is called very late, so all types should be fully ready.

mypy/plugins/enums.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"""
1313
from __future__ import annotations
1414

15-
from typing import Iterable, Sequence, TypeVar, cast
16-
from typing_extensions import Final
15+
from typing import Final, Iterable, Sequence, TypeVar, cast
1716

1817
import mypy.plugin # To avoid circular imports.
1918
from mypy.nodes import TypeInfo

0 commit comments

Comments
 (0)