Skip to content

Commit

Permalink
Run pyupgrade --py38-plus on the source code (#15575)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jul 3, 2023
1 parent 49d95cf commit dcdcc60
Show file tree
Hide file tree
Showing 80 changed files with 137 additions and 168 deletions.
4 changes: 2 additions & 2 deletions misc/analyze_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import os
import os.path
from collections import Counter
from typing import Any, Dict, Iterable
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing import Any, Dict, Final, Iterable
from typing_extensions import TypeAlias as _TypeAlias

ROOT: Final = ".mypy_cache/3.5"

Expand Down
4 changes: 2 additions & 2 deletions misc/incremental_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
import textwrap
import time
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
from typing import Any, Dict
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing import Any, Dict, Final
from typing_extensions import TypeAlias as _TypeAlias

CACHE_PATH: Final = ".incremental_checker_cache.json"
MYPY_REPO_URL: Final = "https://github.com/python/mypy.git"
Expand Down
3 changes: 2 additions & 1 deletion mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
Callable,
ClassVar,
Dict,
Final,
Iterator,
Mapping,
NamedTuple,
NoReturn,
Sequence,
TextIO,
)
from typing_extensions import Final, TypeAlias as _TypeAlias, TypedDict
from typing_extensions import TypeAlias as _TypeAlias, TypedDict

import mypy.semanal_main
from mypy.checker import TypeChecker
Expand Down
5 changes: 3 additions & 2 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
AbstractSet,
Callable,
Dict,
Final,
Generic,
Iterable,
Iterator,
Expand All @@ -22,7 +23,7 @@
cast,
overload,
)
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing_extensions import TypeAlias as _TypeAlias

import mypy.checkexpr
from mypy import errorcodes as codes, message_registry, nodes, operators
Expand Down Expand Up @@ -1546,7 +1547,7 @@ def check_reverse_op_method(
if opt_meta is not None:
forward_inst = opt_meta

def has_readable_member(typ: Union[UnionType, Instance], name: str) -> bool:
def has_readable_member(typ: UnionType | Instance, name: str) -> bool:
# TODO: Deal with attributes of TupleType etc.
if isinstance(typ, Instance):
return typ.type.has_readable_member(name)
Expand Down
6 changes: 3 additions & 3 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import time
from collections import defaultdict
from contextlib import contextmanager
from typing import Callable, ClassVar, Iterable, Iterator, List, Optional, Sequence, cast
from typing_extensions import Final, TypeAlias as _TypeAlias, overload
from typing import Callable, ClassVar, Final, Iterable, Iterator, List, Optional, Sequence, cast
from typing_extensions import TypeAlias as _TypeAlias, overload

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


def apply_poly(tp: CallableType, poly_tvars: Sequence[TypeVarLikeType]) -> Optional[CallableType]:
def apply_poly(tp: CallableType, poly_tvars: Sequence[TypeVarLikeType]) -> CallableType | None:
"""Make free type variables generic in the type if possible.
This will translate the type `tp` while trying to create valid bindings for
Expand Down
3 changes: 1 addition & 2 deletions mypy/checkpattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from __future__ import annotations

from collections import defaultdict
from typing import NamedTuple
from typing_extensions import Final
from typing import Final, NamedTuple

import mypy.checker
from mypy import message_registry
Expand Down
4 changes: 2 additions & 2 deletions mypy/checkstrformat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from __future__ import annotations

import re
from typing import TYPE_CHECKING, Callable, Dict, Match, Pattern, Tuple, Union, cast
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing import TYPE_CHECKING, Callable, Dict, Final, Match, Pattern, Tuple, Union, cast
from typing_extensions import TypeAlias as _TypeAlias

import mypy.errorcodes as codes
from mypy.errors import Errors
Expand Down
3 changes: 2 additions & 1 deletion mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
Any,
Callable,
Dict,
Final,
Iterable,
List,
Mapping,
Expand All @@ -28,7 +29,7 @@
Tuple,
Union,
)
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing_extensions import TypeAlias as _TypeAlias

from mypy import defaults
from mypy.options import PER_MODULE_OPTIONS, Options
Expand Down
3 changes: 1 addition & 2 deletions mypy/constant_fold.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from __future__ import annotations

from typing import Union
from typing_extensions import Final
from typing import Final, Union

from mypy.nodes import (
ComplexExpr,
Expand Down
3 changes: 1 addition & 2 deletions mypy/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Iterable, List, Sequence, cast
from typing_extensions import Final
from typing import TYPE_CHECKING, Final, Iterable, List, Sequence, cast

import mypy.subtypes
import mypy.typeops
Expand Down
2 changes: 1 addition & 1 deletion mypy/defaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import os
from typing_extensions import Final
from typing import Final

PYTHON2_VERSION: Final = (2, 7)

Expand Down
4 changes: 2 additions & 2 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import time
import traceback
from contextlib import redirect_stderr, redirect_stdout
from typing import AbstractSet, Any, Callable, List, Sequence, Tuple
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing import AbstractSet, Any, Callable, Final, List, Sequence, Tuple
from typing_extensions import TypeAlias as _TypeAlias

import mypy.build
import mypy.errors
Expand Down
3 changes: 1 addition & 2 deletions mypy/dmypy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from __future__ import annotations

import json
from typing import Any
from typing_extensions import Final
from typing import Any, Final

from mypy.ipc import IPCBase

Expand Down
2 changes: 1 addition & 1 deletion mypy/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

from collections import defaultdict
from typing_extensions import Final
from typing import Final

from mypy_extensions import mypyc_attr

Expand Down
4 changes: 2 additions & 2 deletions mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import sys
import traceback
from collections import defaultdict
from typing import Callable, Iterable, NoReturn, Optional, TextIO, Tuple, TypeVar
from typing_extensions import Final, Literal, TypeAlias as _TypeAlias
from typing import Callable, Final, Iterable, NoReturn, Optional, TextIO, Tuple, TypeVar
from typing_extensions import Literal, TypeAlias as _TypeAlias

from mypy import errorcodes as codes
from mypy.errorcodes import IMPORT, ErrorCode
Expand Down
2 changes: 1 addition & 1 deletion mypy/evalexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import ast
from typing_extensions import Final
from typing import Final

import mypy.nodes
from mypy.visitor import ExpressionVisitor
Expand Down
3 changes: 1 addition & 2 deletions mypy/expandtype.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

from typing import Iterable, Mapping, Sequence, TypeVar, cast, overload
from typing_extensions import Final
from typing import Final, Iterable, Mapping, Sequence, TypeVar, cast, overload

from mypy.nodes import ARG_POS, ARG_STAR, ArgKind, Var
from mypy.state import state
Expand Down
4 changes: 2 additions & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import re
import sys
import warnings
from typing import Any, Callable, List, Optional, Sequence, TypeVar, Union, cast
from typing_extensions import Final, Literal, overload
from typing import Any, Callable, Final, List, Optional, Sequence, TypeVar, Union, cast
from typing_extensions import Literal, overload

from mypy import defaults, errorcodes as codes, message_registry
from mypy.errors import Errors
Expand Down
5 changes: 2 additions & 3 deletions mypy/find_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import functools
import os
from typing import Sequence
from typing_extensions import Final
from typing import Final, Sequence

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

@functools.lru_cache() # noqa: B019
@functools.lru_cache # noqa: B019
def _crawl_up_helper(self, dir: str) -> tuple[str, str] | None:
"""Given a directory, maybe returns module and base directory.
Expand Down
3 changes: 1 addition & 2 deletions mypy/fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from __future__ import annotations

from typing import Any
from typing_extensions import Final
from typing import Any, Final

from mypy.lookup import lookup_fully_qualified
from mypy.nodes import (
Expand Down
3 changes: 1 addition & 2 deletions mypy/ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import sys
import tempfile
from types import TracebackType
from typing import Callable
from typing_extensions import Final
from typing import Callable, Final

if sys.platform == "win32":
# This may be private, but it is needed for IPC on Windows, and is basically stable
Expand Down
4 changes: 2 additions & 2 deletions mypy/literals.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from typing import Any, Iterable, Optional, Tuple
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing import Any, Final, Iterable, Optional, Tuple
from typing_extensions import TypeAlias as _TypeAlias

from mypy.nodes import (
LITERAL_NO,
Expand Down
3 changes: 1 addition & 2 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import sys
import time
from gettext import gettext
from typing import IO, Any, NoReturn, Sequence, TextIO
from typing_extensions import Final
from typing import IO, Any, Final, NoReturn, Sequence, TextIO

from mypy import build, defaults, state, util
from mypy.config_parser import get_config_module_names, parse_config_file, parse_version
Expand Down
3 changes: 1 addition & 2 deletions mypy/message_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

from __future__ import annotations

from typing import NamedTuple
from typing_extensions import Final
from typing import Final, NamedTuple

from mypy import errorcodes as codes

Expand Down
3 changes: 1 addition & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
import re
from contextlib import contextmanager
from textwrap import dedent
from typing import Any, Callable, Collection, Iterable, Iterator, List, Sequence, cast
from typing_extensions import Final
from typing import Any, Callable, Collection, Final, Iterable, Iterator, List, Sequence, cast

import mypy.typeops
from mypy import errorcodes as codes, message_registry
Expand Down
4 changes: 2 additions & 2 deletions mypy/modulefinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
else:
import tomli as tomllib

from typing import Dict, List, NamedTuple, Optional, Tuple, Union
from typing_extensions import Final, TypeAlias as _TypeAlias
from typing import Dict, Final, List, NamedTuple, Optional, Tuple, Union
from typing_extensions import TypeAlias as _TypeAlias

from mypy import pyinfo
from mypy.fscache import FileSystemCache
Expand Down
3 changes: 2 additions & 1 deletion mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Any,
Callable,
Dict,
Final,
Iterator,
List,
Optional,
Expand All @@ -20,7 +21,7 @@
Union,
cast,
)
from typing_extensions import Final, TypeAlias as _TypeAlias, TypeGuard
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard

from mypy_extensions import trait

Expand Down
2 changes: 1 addition & 1 deletion mypy/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing_extensions import Final
from typing import Final

# Map from binary operator id to related method name (in Python 3).
op_methods: Final = {
Expand Down
5 changes: 2 additions & 3 deletions mypy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import re
import sys
import sysconfig
from typing import Any, Callable, Dict, Mapping, Pattern
from typing_extensions import Final
from typing import Any, Callable, Final, Mapping, Pattern

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

def select_options_affecting_cache(self) -> Mapping[str, object]:
result: Dict[str, object] = {}
result: dict[str, object] = {}
for opt in OPTIONS_AFFECTING_CACHE:
val = getattr(self, opt)
if opt in ("disabled_error_codes", "enabled_error_codes"):
Expand Down
4 changes: 2 additions & 2 deletions mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from collections import defaultdict
from functools import reduce
from typing import Iterable, List, Mapping, cast
from typing_extensions import Final, Literal
from typing import Final, Iterable, List, Mapping, cast
from typing_extensions import Literal

import mypy.plugin # To avoid circular imports.
from mypy.applytype import apply_generic_arguments
Expand Down
5 changes: 2 additions & 3 deletions mypy/plugins/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Iterator, Optional
from typing_extensions import Final
from typing import TYPE_CHECKING, Final, Iterator

from mypy import errorcodes, message_registry
from mypy.expandtype import expand_type, expand_type_by_instance
Expand Down Expand Up @@ -134,7 +133,7 @@ def to_argument(self, current_info: TypeInfo) -> Argument:
kind=arg_kind,
)

def expand_type(self, current_info: TypeInfo) -> Optional[Type]:
def expand_type(self, current_info: TypeInfo) -> Type | None:
if self.type is not None and self.info.self_type is not None:
# In general, it is not safe to call `expand_type()` during semantic analyzis,
# however this plugin is called very late, so all types should be fully ready.
Expand Down
3 changes: 1 addition & 2 deletions mypy/plugins/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"""
from __future__ import annotations

from typing import Iterable, Sequence, TypeVar, cast
from typing_extensions import Final
from typing import Final, Iterable, Sequence, TypeVar, cast

import mypy.plugin # To avoid circular imports.
from mypy.nodes import TypeInfo
Expand Down
Loading

0 comments on commit dcdcc60

Please sign in to comment.