diff --git a/misc/analyze_cache.py b/misc/analyze_cache.py index 45c44139b473..33205f5132fc 100644 --- a/misc/analyze_cache.py +++ b/misc/analyze_cache.py @@ -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" diff --git a/misc/incremental_checker.py b/misc/incremental_checker.py index 85239b6462b8..4e42aef333bb 100755 --- a/misc/incremental_checker.py +++ b/misc/incremental_checker.py @@ -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" diff --git a/mypy/build.py b/mypy/build.py index 5a6f8c00896e..5a0a481ae1a2 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -31,6 +31,7 @@ Callable, ClassVar, Dict, + Final, Iterator, Mapping, NamedTuple, @@ -38,7 +39,7 @@ 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 diff --git a/mypy/checker.py b/mypy/checker.py index cdce42ddaaa1..bf200299d8b3 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -9,6 +9,7 @@ AbstractSet, Callable, Dict, + Final, Generic, Iterable, Iterator, @@ -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 @@ -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) diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index 986e58c21762..aee8d58a69f6 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -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 @@ -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 diff --git a/mypy/checkpattern.py b/mypy/checkpattern.py index 50d7b8a9826f..e432675b0b5a 100644 --- a/mypy/checkpattern.py +++ b/mypy/checkpattern.py @@ -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 diff --git a/mypy/checkstrformat.py b/mypy/checkstrformat.py index 974985d8b4fc..cda603be086b 100644 --- a/mypy/checkstrformat.py +++ b/mypy/checkstrformat.py @@ -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 diff --git a/mypy/config_parser.py b/mypy/config_parser.py index 05af2ba6e21e..47b0bc3acabc 100644 --- a/mypy/config_parser.py +++ b/mypy/config_parser.py @@ -19,6 +19,7 @@ Any, Callable, Dict, + Final, Iterable, List, Mapping, @@ -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 diff --git a/mypy/constant_fold.py b/mypy/constant_fold.py index 6881ecae9e88..4582b2a7396d 100644 --- a/mypy/constant_fold.py +++ b/mypy/constant_fold.py @@ -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, diff --git a/mypy/constraints.py b/mypy/constraints.py index 803b9819be6f..f9124630a706 100644 --- a/mypy/constraints.py +++ b/mypy/constraints.py @@ -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 diff --git a/mypy/defaults.py b/mypy/defaults.py index 59a99cd58888..2a881975a27c 100644 --- a/mypy/defaults.py +++ b/mypy/defaults.py @@ -1,7 +1,7 @@ from __future__ import annotations import os -from typing_extensions import Final +from typing import Final PYTHON2_VERSION: Final = (2, 7) diff --git a/mypy/dmypy_server.py b/mypy/dmypy_server.py index 2427f83c5767..a50ebc5415ba 100644 --- a/mypy/dmypy_server.py +++ b/mypy/dmypy_server.py @@ -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 diff --git a/mypy/dmypy_util.py b/mypy/dmypy_util.py index a1b419617f73..2aae41d998da 100644 --- a/mypy/dmypy_util.py +++ b/mypy/dmypy_util.py @@ -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 diff --git a/mypy/errorcodes.py b/mypy/errorcodes.py index b9448f3d5af9..68ae4b49a806 100644 --- a/mypy/errorcodes.py +++ b/mypy/errorcodes.py @@ -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 diff --git a/mypy/errors.py b/mypy/errors.py index 6739d30f16a4..2badac3e3d6d 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -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 diff --git a/mypy/evalexpr.py b/mypy/evalexpr.py index 2bc6966fa2fa..4b3abb1be3e2 100644 --- a/mypy/evalexpr.py +++ b/mypy/evalexpr.py @@ -7,7 +7,7 @@ """ import ast -from typing_extensions import Final +from typing import Final import mypy.nodes from mypy.visitor import ExpressionVisitor diff --git a/mypy/expandtype.py b/mypy/expandtype.py index 24835a5ee4d6..83d9bf4c8725 100644 --- a/mypy/expandtype.py +++ b/mypy/expandtype.py @@ -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 diff --git a/mypy/fastparse.py b/mypy/fastparse.py index fa185be21f9e..eeeda16f9d8d 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -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 diff --git a/mypy/find_sources.py b/mypy/find_sources.py index a3ef2d3db052..3565fc4609cd 100644 --- a/mypy/find_sources.py +++ b/mypy/find_sources.py @@ -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 @@ -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. diff --git a/mypy/fixup.py b/mypy/fixup.py index 15f4c13c20fa..2b2e1210ee4e 100644 --- a/mypy/fixup.py +++ b/mypy/fixup.py @@ -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 ( diff --git a/mypy/ipc.py b/mypy/ipc.py index 21ef61918de5..d026f2429a0f 100644 --- a/mypy/ipc.py +++ b/mypy/ipc.py @@ -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 diff --git a/mypy/literals.py b/mypy/literals.py index 53ba559c56bb..cba5712644be 100644 --- a/mypy/literals.py +++ b/mypy/literals.py @@ -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, diff --git a/mypy/main.py b/mypy/main.py index 9d95bb6cb1f6..f6e617e4d84f 100644 --- a/mypy/main.py +++ b/mypy/main.py @@ -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 diff --git a/mypy/message_registry.py b/mypy/message_registry.py index 4e08f0dab5ed..bd3b8571b69e 100644 --- a/mypy/message_registry.py +++ b/mypy/message_registry.py @@ -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 diff --git a/mypy/messages.py b/mypy/messages.py index 8e59e7329168..021ad2c7390c 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -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 diff --git a/mypy/modulefinder.py b/mypy/modulefinder.py index e0406bffcc7b..c780015c639d 100644 --- a/mypy/modulefinder.py +++ b/mypy/modulefinder.py @@ -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 diff --git a/mypy/nodes.py b/mypy/nodes.py index 212ddb5def37..eb093f5d45b0 100644 --- a/mypy/nodes.py +++ b/mypy/nodes.py @@ -11,6 +11,7 @@ Any, Callable, Dict, + Final, Iterator, List, Optional, @@ -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 diff --git a/mypy/operators.py b/mypy/operators.py index 2b383ef199bb..07ec5a24fa77 100644 --- a/mypy/operators.py +++ b/mypy/operators.py @@ -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 = { diff --git a/mypy/options.py b/mypy/options.py index daa666dc7638..75343acd38bb 100644 --- a/mypy/options.py +++ b/mypy/options.py @@ -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 @@ -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"): diff --git a/mypy/plugins/attrs.py b/mypy/plugins/attrs.py index e05a8e44b2f8..a6a383405ac6 100644 --- a/mypy/plugins/attrs.py +++ b/mypy/plugins/attrs.py @@ -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 diff --git a/mypy/plugins/dataclasses.py b/mypy/plugins/dataclasses.py index efa1338962a0..7b3795b91a74 100644 --- a/mypy/plugins/dataclasses.py +++ b/mypy/plugins/dataclasses.py @@ -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 @@ -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. diff --git a/mypy/plugins/enums.py b/mypy/plugins/enums.py index 1acf42d11ee6..7869a8b5cdfa 100644 --- a/mypy/plugins/enums.py +++ b/mypy/plugins/enums.py @@ -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 diff --git a/mypy/plugins/functools.py b/mypy/plugins/functools.py index eba4d77f2343..0aa2824c9b51 100644 --- a/mypy/plugins/functools.py +++ b/mypy/plugins/functools.py @@ -1,8 +1,7 @@ """Plugin for supporting the functools standard library module.""" from __future__ import annotations -from typing import NamedTuple -from typing_extensions import Final +from typing import Final, NamedTuple import mypy.plugin from mypy.nodes import ARG_POS, ARG_STAR2, Argument, FuncItem, Var diff --git a/mypy/plugins/singledispatch.py b/mypy/plugins/singledispatch.py index a44493f900b1..c5ce20233a0a 100644 --- a/mypy/plugins/singledispatch.py +++ b/mypy/plugins/singledispatch.py @@ -1,7 +1,7 @@ from __future__ import annotations -from typing import NamedTuple, Sequence, TypeVar, Union -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Final, NamedTuple, Sequence, TypeVar, Union +from typing_extensions import TypeAlias as _TypeAlias from mypy.messages import format_type from mypy.nodes import ARG_POS, Argument, Block, ClassDef, Context, SymbolTable, TypeInfo, Var diff --git a/mypy/reachability.py b/mypy/reachability.py index 8602fc645e2b..a25b9dff4581 100644 --- a/mypy/reachability.py +++ b/mypy/reachability.py @@ -2,8 +2,7 @@ from __future__ import annotations -from typing import Tuple, TypeVar -from typing_extensions import Final +from typing import Final, Tuple, TypeVar from mypy.literals import literal from mypy.nodes import ( diff --git a/mypy/renaming.py b/mypy/renaming.py index 2fa3ef168a66..c960eb4b1ce8 100644 --- a/mypy/renaming.py +++ b/mypy/renaming.py @@ -1,8 +1,7 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Iterator -from typing_extensions import Final +from typing import Final, Iterator from mypy.nodes import ( AssignmentStmt, diff --git a/mypy/report.py b/mypy/report.py index 81d49baf50da..5d93351aa37d 100644 --- a/mypy/report.py +++ b/mypy/report.py @@ -12,8 +12,8 @@ import tokenize from abc import ABCMeta, abstractmethod from operator import attrgetter -from typing import Any, Callable, Dict, Iterator, Tuple -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Any, Callable, Dict, Final, Iterator, Tuple +from typing_extensions import TypeAlias as _TypeAlias from urllib.request import pathname2url from mypy import stats diff --git a/mypy/semanal.py b/mypy/semanal.py index 25393096bc5f..75d41b344698 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -51,8 +51,8 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Any, Callable, Collection, Iterable, Iterator, List, TypeVar, cast -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Any, Callable, Collection, Final, Iterable, Iterator, List, TypeVar, cast +from typing_extensions import TypeAlias as _TypeAlias from mypy import errorcodes as codes, message_registry from mypy.constant_fold import constant_fold_expr diff --git a/mypy/semanal_classprop.py b/mypy/semanal_classprop.py index 3f5bc9c4c2de..dfd4e5b6f122 100644 --- a/mypy/semanal_classprop.py +++ b/mypy/semanal_classprop.py @@ -5,7 +5,7 @@ from __future__ import annotations -from typing_extensions import Final +from typing import Final from mypy.errors import Errors from mypy.nodes import ( diff --git a/mypy/semanal_enum.py b/mypy/semanal_enum.py index f8d321ffada9..cd11204c3bcc 100644 --- a/mypy/semanal_enum.py +++ b/mypy/semanal_enum.py @@ -5,8 +5,7 @@ from __future__ import annotations -from typing import cast -from typing_extensions import Final +from typing import Final, cast from mypy.nodes import ( ARG_NAMED, diff --git a/mypy/semanal_main.py b/mypy/semanal_main.py index d7e9712fa427..51a7014fac1a 100644 --- a/mypy/semanal_main.py +++ b/mypy/semanal_main.py @@ -27,8 +27,8 @@ from __future__ import annotations from contextlib import nullcontext -from typing import TYPE_CHECKING, Callable, List, Optional, Tuple, Union -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import TYPE_CHECKING, Callable, Final, List, Optional, Tuple, Union +from typing_extensions import TypeAlias as _TypeAlias import mypy.build import mypy.state diff --git a/mypy/semanal_namedtuple.py b/mypy/semanal_namedtuple.py index 5eac02833d24..42f7b10f3333 100644 --- a/mypy/semanal_namedtuple.py +++ b/mypy/semanal_namedtuple.py @@ -6,8 +6,7 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Iterator, List, Mapping, cast -from typing_extensions import Final +from typing import Final, Iterator, List, Mapping, cast from mypy.exprtotype import TypeTranslationError, expr_to_unanalyzed_type from mypy.nodes import ( diff --git a/mypy/semanal_shared.py b/mypy/semanal_shared.py index d097e1fb08dc..425e5906926a 100644 --- a/mypy/semanal_shared.py +++ b/mypy/semanal_shared.py @@ -3,8 +3,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import Callable, overload -from typing_extensions import Final, Literal, Protocol +from typing import Callable, Final, overload +from typing_extensions import Literal, Protocol from mypy_extensions import trait diff --git a/mypy/semanal_typeddict.py b/mypy/semanal_typeddict.py index 47a3f558aa13..aba5bf69b130 100644 --- a/mypy/semanal_typeddict.py +++ b/mypy/semanal_typeddict.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing_extensions import Final +from typing import Final from mypy import errorcodes as codes, message_registry from mypy.errorcodes import ErrorCode diff --git a/mypy/server/mergecheck.py b/mypy/server/mergecheck.py index ef6f5b86c8f3..6f044a5ea8b9 100644 --- a/mypy/server/mergecheck.py +++ b/mypy/server/mergecheck.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing_extensions import Final +from typing import Final from mypy.nodes import Decorator, FakeInfo, FuncDef, SymbolNode, Var from mypy.server.objgraph import get_path, get_reachable_graph diff --git a/mypy/server/objgraph.py b/mypy/server/objgraph.py index 37d0f4d2ca1a..a13fd8412934 100644 --- a/mypy/server/objgraph.py +++ b/mypy/server/objgraph.py @@ -5,8 +5,7 @@ import types import weakref from collections.abc import Iterable -from typing import Iterator, Mapping -from typing_extensions import Final +from typing import Final, Iterator, Mapping method_descriptor_type: Final = type(object.__dir__) method_wrapper_type: Final = type(object().__ne__) diff --git a/mypy/server/trigger.py b/mypy/server/trigger.py index 5f2115739d38..97b5f89cd3ba 100644 --- a/mypy/server/trigger.py +++ b/mypy/server/trigger.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing_extensions import Final +from typing import Final # Used as a suffix for triggers to handle "from m import *" dependencies (see also # make_wildcard_trigger) diff --git a/mypy/server/update.py b/mypy/server/update.py index dafed6642d1e..0cc7a2229514 100644 --- a/mypy/server/update.py +++ b/mypy/server/update.py @@ -118,8 +118,8 @@ import re import sys import time -from typing import Callable, NamedTuple, Sequence, Union -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Callable, Final, NamedTuple, Sequence, Union +from typing_extensions import TypeAlias as _TypeAlias from mypy.build import ( DEBUG_FINE_GRAINED, diff --git a/mypy/sharedparse.py b/mypy/sharedparse.py index 6f864ccce816..ef2e4f720664 100644 --- a/mypy/sharedparse.py +++ b/mypy/sharedparse.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing_extensions import Final +from typing import Final """Shared logic between our three mypy parser files.""" diff --git a/mypy/state.py b/mypy/state.py index 2e44a936f819..cd3a360dd15f 100644 --- a/mypy/state.py +++ b/mypy/state.py @@ -1,8 +1,7 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Iterator -from typing_extensions import Final +from typing import Final, Iterator # These are global mutable state. Don't add anything here unless there's a very # good reason. diff --git a/mypy/stats.py b/mypy/stats.py index 5f4b9d4d201f..b8803e03b9d2 100644 --- a/mypy/stats.py +++ b/mypy/stats.py @@ -5,8 +5,7 @@ import os from collections import Counter from contextlib import contextmanager -from typing import Iterator -from typing_extensions import Final +from typing import Final, Iterator from mypy import nodes from mypy.argmap import map_formals_to_actuals diff --git a/mypy/stubdoc.py b/mypy/stubdoc.py index 7c8751bbd6ed..232d9e9762e9 100644 --- a/mypy/stubdoc.py +++ b/mypy/stubdoc.py @@ -10,8 +10,8 @@ import io import re import tokenize -from typing import Any, MutableMapping, MutableSequence, NamedTuple, Sequence, Tuple -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Any, Final, MutableMapping, MutableSequence, NamedTuple, Sequence, Tuple +from typing_extensions import TypeAlias as _TypeAlias # Type alias for signatures strings in format ('func_name', '(arg, opt_arg=False)'). Sig: _TypeAlias = Tuple[str, str] diff --git a/mypy/stubgen.py b/mypy/stubgen.py index ba71456af4a4..229559ac8120 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -49,8 +49,7 @@ import sys import traceback from collections import defaultdict -from typing import Iterable, Mapping -from typing_extensions import Final +from typing import Final, Iterable, Mapping import mypy.build import mypy.mixedtraverser diff --git a/mypy/stubgenc.py b/mypy/stubgenc.py index 4fc9f8c6fdfa..8aa1fb3d2c0a 100755 --- a/mypy/stubgenc.py +++ b/mypy/stubgenc.py @@ -12,8 +12,7 @@ import re from abc import abstractmethod from types import ModuleType -from typing import Any, Iterable, Mapping -from typing_extensions import Final +from typing import Any, Final, Iterable, Mapping from mypy.moduleinspect import is_c_module from mypy.stubdoc import ( @@ -502,7 +501,7 @@ def generate_c_type_stub( """ raw_lookup = getattr(obj, "__dict__") # noqa: B009 items = sorted(get_members(obj), key=lambda x: method_name_sort_key(x[0])) - names = set(x[0] for x in items) + names = {x[0] for x in items} methods: list[str] = [] types: list[str] = [] static_properties: list[str] = [] diff --git a/mypy/subtypes.py b/mypy/subtypes.py index c9de56edfa36..a6dc071f92b0 100644 --- a/mypy/subtypes.py +++ b/mypy/subtypes.py @@ -1,8 +1,8 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Any, Callable, Iterator, List, TypeVar, cast -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Any, Callable, Final, Iterator, List, TypeVar, cast +from typing_extensions import TypeAlias as _TypeAlias import mypy.applytype import mypy.constraints diff --git a/mypy/test/data.py b/mypy/test/data.py index 9b3931ee8be6..940776bf7b19 100644 --- a/mypy/test/data.py +++ b/mypy/test/data.py @@ -12,8 +12,8 @@ from abc import abstractmethod from dataclasses import dataclass from pathlib import Path -from typing import Any, Iterator, NamedTuple, NoReturn, Pattern, Union -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Any, Final, Iterator, NamedTuple, NoReturn, Pattern, Union +from typing_extensions import TypeAlias as _TypeAlias import pytest diff --git a/mypy/type_visitor.py b/mypy/type_visitor.py index 2efae49e9e10..cbfa43a77b81 100644 --- a/mypy/type_visitor.py +++ b/mypy/type_visitor.py @@ -14,8 +14,7 @@ from __future__ import annotations from abc import abstractmethod -from typing import Any, Callable, Generic, Iterable, Sequence, TypeVar, cast -from typing_extensions import Final +from typing import Any, Callable, Final, Generic, Iterable, Sequence, TypeVar, cast from mypy_extensions import mypyc_attr, trait diff --git a/mypy/typeanal.py b/mypy/typeanal.py index d577f355dbc8..d894e2cc8c51 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -4,8 +4,8 @@ import itertools from contextlib import contextmanager -from typing import Callable, Iterable, Iterator, List, Sequence, Tuple, TypeVar -from typing_extensions import Final, Protocol +from typing import Callable, Final, Iterable, Iterator, List, Sequence, Tuple, TypeVar +from typing_extensions import Protocol from mypy import errorcodes as codes, message_registry, nodes from mypy.errorcodes import ErrorCode diff --git a/mypy/types.py b/mypy/types.py index 131383790ec8..784ef538f197 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -9,6 +9,7 @@ Any, ClassVar, Dict, + Final, Iterable, NamedTuple, NewType, @@ -17,7 +18,7 @@ Union, cast, ) -from typing_extensions import Final, Self, TypeAlias as _TypeAlias, TypeGuard, overload +from typing_extensions import Self, TypeAlias as _TypeAlias, TypeGuard, overload import mypy.nodes from mypy.bogus_type import Bogus diff --git a/mypy/typestate.py b/mypy/typestate.py index ff5933af5928..b32fb0ef6df1 100644 --- a/mypy/typestate.py +++ b/mypy/typestate.py @@ -5,8 +5,8 @@ from __future__ import annotations -from typing import Dict, Set, Tuple -from typing_extensions import Final, TypeAlias as _TypeAlias +from typing import Dict, Final, Set, Tuple +from typing_extensions import TypeAlias as _TypeAlias from mypy.nodes import TypeInfo from mypy.server.trigger import make_trigger diff --git a/mypy/util.py b/mypy/util.py index 2960818d0984..268ba8f9de81 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -11,8 +11,8 @@ import sys import time from importlib import resources as importlib_resources -from typing import IO, Callable, Container, Iterable, Sequence, Sized, TypeVar -from typing_extensions import Final, Literal +from typing import IO, Callable, Container, Final, Iterable, Sequence, Sized, TypeVar +from typing_extensions import Literal try: import curses diff --git a/mypyc/analysis/attrdefined.py b/mypyc/analysis/attrdefined.py index 02e02a82a4f9..350158246cdb 100644 --- a/mypyc/analysis/attrdefined.py +++ b/mypyc/analysis/attrdefined.py @@ -63,8 +63,7 @@ def foo(self) -> int: from __future__ import annotations -from typing import Set, Tuple -from typing_extensions import Final +from typing import Final, Set, Tuple from mypyc.analysis.dataflow import ( CFG, @@ -414,7 +413,7 @@ def update_always_defined_attrs_using_subclasses(cl: ClassIR, seen: set[ClassIR] seen.add(cl) -def detect_undefined_bitmap(cl: ClassIR, seen: Set[ClassIR]) -> None: +def detect_undefined_bitmap(cl: ClassIR, seen: set[ClassIR]) -> None: if cl.is_trait: return diff --git a/mypyc/codegen/cstring.py b/mypyc/codegen/cstring.py index e006f12e09ec..853787f8161d 100644 --- a/mypyc/codegen/cstring.py +++ b/mypyc/codegen/cstring.py @@ -21,7 +21,7 @@ from __future__ import annotations import string -from typing_extensions import Final +from typing import Final CHAR_MAP: Final = [f"\\{i:03o}" for i in range(256)] diff --git a/mypyc/codegen/emit.py b/mypyc/codegen/emit.py index 8f0e0bc65edc..1bd376754ab9 100644 --- a/mypyc/codegen/emit.py +++ b/mypyc/codegen/emit.py @@ -5,8 +5,7 @@ import pprint import sys import textwrap -from typing import Callable -from typing_extensions import Final +from typing import Callable, Final from mypyc.codegen.literals import Literals from mypyc.common import ( @@ -926,7 +925,7 @@ def emit_unbox( elif is_float_rprimitive(typ): assert not optional # Not supported for overlapping error values if declare_dest: - self.emit_line("double {};".format(dest)) + self.emit_line(f"double {dest};") # TODO: Don't use __float__ and __index__ self.emit_line(f"{dest} = PyFloat_AsDouble({src});") self.emit_lines(f"if ({dest} == -1.0 && PyErr_Occurred()) {{", failure, "}") diff --git a/mypyc/codegen/emitfunc.py b/mypyc/codegen/emitfunc.py index 7e6d775d74b4..b4d31544b196 100644 --- a/mypyc/codegen/emitfunc.py +++ b/mypyc/codegen/emitfunc.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing_extensions import Final +from typing import Final from mypyc.analysis.blockfreq import frequently_executed_blocks from mypyc.codegen.emit import DEBUG_ERRORS, Emitter, TracebackAndGotoHandler, c_array_initializer @@ -686,10 +686,10 @@ def visit_float_op(self, op: FloatOp) -> None: lhs = self.reg(op.lhs) rhs = self.reg(op.rhs) if op.op != FloatOp.MOD: - self.emit_line("%s = %s %s %s;" % (dest, lhs, op.op_str[op.op], rhs)) + self.emit_line(f"{dest} = {lhs} {op.op_str[op.op]} {rhs};") else: # TODO: This may set errno as a side effect, that is a little sketchy. - self.emit_line("%s = fmod(%s, %s);" % (dest, lhs, rhs)) + self.emit_line(f"{dest} = fmod({lhs}, {rhs});") def visit_float_neg(self, op: FloatNeg) -> None: dest = self.reg(op) @@ -700,7 +700,7 @@ def visit_float_comparison_op(self, op: FloatComparisonOp) -> None: dest = self.reg(op) lhs = self.reg(op.lhs) rhs = self.reg(op.rhs) - self.emit_line("%s = %s %s %s;" % (dest, lhs, op.op_str[op.op], rhs)) + self.emit_line(f"{dest} = {lhs} {op.op_str[op.op]} {rhs};") def visit_load_mem(self, op: LoadMem) -> None: dest = self.reg(op) diff --git a/mypyc/codegen/literals.py b/mypyc/codegen/literals.py index 8f84089221c3..1f0c3bc6ec7b 100644 --- a/mypyc/codegen/literals.py +++ b/mypyc/codegen/literals.py @@ -1,7 +1,7 @@ from __future__ import annotations -from typing import FrozenSet, List, Tuple, Union -from typing_extensions import Final, TypeGuard +from typing import Final, FrozenSet, Tuple, Union +from typing_extensions import TypeGuard # Supported Python literal types. All tuple / frozenset items must have supported # literal types as well, but we can't represent the type precisely. @@ -140,7 +140,7 @@ def encoded_complex_values(self) -> list[str]: def encoded_tuple_values(self) -> list[str]: return self._encode_collection_values(self.tuple_literals) - def encoded_frozenset_values(self) -> List[str]: + def encoded_frozenset_values(self) -> list[str]: return self._encode_collection_values(self.frozenset_literals) def _encode_collection_values( diff --git a/mypyc/common.py b/mypyc/common.py index 05e13370cb98..4615bf30d742 100644 --- a/mypyc/common.py +++ b/mypyc/common.py @@ -2,8 +2,7 @@ import sys import sysconfig -from typing import Any, Dict -from typing_extensions import Final +from typing import Any, Dict, Final from mypy.util import unnamed_function diff --git a/mypyc/ir/class_ir.py b/mypyc/ir/class_ir.py index a5ac2133ce13..682e30629118 100644 --- a/mypyc/ir/class_ir.py +++ b/mypyc/ir/class_ir.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import List, NamedTuple, Optional +from typing import List, NamedTuple from mypyc.common import PROPSET_PREFIX, JsonDict from mypyc.ir.func_ir import FuncDecl, FuncIR, FuncSignature @@ -73,7 +73,7 @@ class VTableMethod(NamedTuple): cls: "ClassIR" name: str method: FuncIR - shadow_method: Optional[FuncIR] + shadow_method: FuncIR | None VTableEntries = List[VTableMethod] @@ -192,7 +192,7 @@ def __init__( # bitmap for types such as native ints that can't have a dedicated error # value that doesn't overlap a valid value. The bitmap is used if the # value of an attribute is the same as the error value. - self.bitmap_attrs: List[str] = [] + self.bitmap_attrs: list[str] = [] def __repr__(self) -> str: return ( diff --git a/mypyc/ir/func_ir.py b/mypyc/ir/func_ir.py index dbb45fc7ec29..44847c7bb0b3 100644 --- a/mypyc/ir/func_ir.py +++ b/mypyc/ir/func_ir.py @@ -2,8 +2,7 @@ from __future__ import annotations -from typing import Sequence -from typing_extensions import Final +from typing import Final, Sequence from mypy.nodes import ARG_POS, ArgKind, Block, FuncDef from mypyc.common import BITMAP_BITS, JsonDict, bitmap_name, get_id_from_name, short_id_from_name @@ -86,7 +85,7 @@ def real_args(self) -> tuple[RuntimeArg, ...]: return self.args[: -self.num_bitmap_args] return self.args - def bound_sig(self) -> "FuncSignature": + def bound_sig(self) -> FuncSignature: if self.num_bitmap_args: return FuncSignature(self.args[1 : -self.num_bitmap_args], self.ret_type) else: diff --git a/mypyc/ir/ops.py b/mypyc/ir/ops.py index 6007f8a4ce04..cb8d9662820c 100644 --- a/mypyc/ir/ops.py +++ b/mypyc/ir/ops.py @@ -12,8 +12,7 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Dict, Generic, List, NamedTuple, Sequence, TypeVar, Union -from typing_extensions import Final +from typing import TYPE_CHECKING, Final, Generic, List, NamedTuple, Sequence, TypeVar, Union from mypy_extensions import trait @@ -1204,10 +1203,10 @@ def __init__(self, lhs: Value, rhs: Value, op: int, line: int = -1) -> None: self.rhs = rhs self.op = op - def sources(self) -> List[Value]: + def sources(self) -> list[Value]: return [self.lhs, self.rhs] - def accept(self, visitor: "OpVisitor[T]") -> T: + def accept(self, visitor: OpVisitor[T]) -> T: return visitor.visit_float_op(self) @@ -1226,10 +1225,10 @@ def __init__(self, src: Value, line: int = -1) -> None: self.type = float_rprimitive self.src = src - def sources(self) -> List[Value]: + def sources(self) -> list[Value]: return [self.src] - def accept(self, visitor: "OpVisitor[T]") -> T: + def accept(self, visitor: OpVisitor[T]) -> T: return visitor.visit_float_neg(self) @@ -1254,10 +1253,10 @@ def __init__(self, lhs: Value, rhs: Value, op: int, line: int = -1) -> None: self.rhs = rhs self.op = op - def sources(self) -> List[Value]: + def sources(self) -> list[Value]: return [self.lhs, self.rhs] - def accept(self, visitor: "OpVisitor[T]") -> T: + def accept(self, visitor: OpVisitor[T]) -> T: return visitor.visit_float_comparison_op(self) @@ -1575,5 +1574,5 @@ def visit_keep_alive(self, op: KeepAlive) -> T: # (Serialization and deserialization *will* be used for incremental # compilation but so far it is not hooked up to anything.) class DeserMaps(NamedTuple): - classes: Dict[str, "ClassIR"] - functions: Dict[str, "FuncIR"] + classes: dict[str, "ClassIR"] + functions: dict[str, "FuncIR"] diff --git a/mypyc/ir/pprint.py b/mypyc/ir/pprint.py index 4d10a91835ca..c86060c49594 100644 --- a/mypyc/ir/pprint.py +++ b/mypyc/ir/pprint.py @@ -3,8 +3,7 @@ from __future__ import annotations from collections import defaultdict -from typing import Any, Sequence, Union -from typing_extensions import Final +from typing import Any, Final, Sequence, Union from mypyc.common import short_name from mypyc.ir.func_ir import FuncIR, all_values_full diff --git a/mypyc/ir/rtypes.py b/mypyc/ir/rtypes.py index 61f83c9c041e..fe0c51ea2221 100644 --- a/mypyc/ir/rtypes.py +++ b/mypyc/ir/rtypes.py @@ -23,8 +23,7 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, ClassVar, Generic, TypeVar -from typing_extensions import Final +from typing import TYPE_CHECKING, ClassVar, Final, Generic, TypeVar from mypyc.common import IS_32_BIT_PLATFORM, PLATFORM_SIZE, JsonDict, short_name from mypyc.namegen import NameGenerator diff --git a/mypyc/irbuild/builder.py b/mypyc/irbuild/builder.py index 86c28882d738..10f057a29bbb 100644 --- a/mypyc/irbuild/builder.py +++ b/mypyc/irbuild/builder.py @@ -13,8 +13,8 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Any, Callable, Iterator, Sequence, Union -from typing_extensions import Final, overload +from typing import Any, Callable, Final, Iterator, Sequence, Union +from typing_extensions import overload from mypy.build import Graph from mypy.maptype import map_instance_to_supertype diff --git a/mypyc/irbuild/classdef.py b/mypyc/irbuild/classdef.py index ef8db97c818e..fc2bb4a1fc2f 100644 --- a/mypyc/irbuild/classdef.py +++ b/mypyc/irbuild/classdef.py @@ -4,8 +4,7 @@ import typing_extensions from abc import abstractmethod -from typing import Callable -from typing_extensions import Final +from typing import Callable, Final from mypy.nodes import ( AssignmentStmt, diff --git a/mypyc/irbuild/constant_fold.py b/mypyc/irbuild/constant_fold.py index dc21be4689e2..12a4b15dd40c 100644 --- a/mypyc/irbuild/constant_fold.py +++ b/mypyc/irbuild/constant_fold.py @@ -10,8 +10,7 @@ from __future__ import annotations -from typing import Union -from typing_extensions import Final +from typing import Final, Union from mypy.constant_fold import constant_fold_binary_op, constant_fold_unary_op from mypy.nodes import ( diff --git a/mypyc/irbuild/format_str_tokenizer.py b/mypyc/irbuild/format_str_tokenizer.py index 480c683aa164..0b46887811fb 100644 --- a/mypyc/irbuild/format_str_tokenizer.py +++ b/mypyc/irbuild/format_str_tokenizer.py @@ -3,7 +3,7 @@ from __future__ import annotations from enum import Enum, unique -from typing_extensions import Final +from typing import Final from mypy.checkstrformat import ( ConversionSpecifier, diff --git a/mypyc/irbuild/ll_builder.py b/mypyc/irbuild/ll_builder.py index a37bcc0dbb86..e34f03704047 100644 --- a/mypyc/irbuild/ll_builder.py +++ b/mypyc/irbuild/ll_builder.py @@ -10,8 +10,7 @@ from __future__ import annotations -from typing import Callable, Optional, Sequence, Tuple -from typing_extensions import Final +from typing import Callable, Final, Optional, Sequence, Tuple from mypy.argmap import map_actuals_to_formals from mypy.nodes import ARG_POS, ARG_STAR, ARG_STAR2, ArgKind diff --git a/mypyc/irbuild/specialize.py b/mypyc/irbuild/specialize.py index 06af4d6d7426..2f22b4bfc9d2 100644 --- a/mypyc/irbuild/specialize.py +++ b/mypyc/irbuild/specialize.py @@ -755,7 +755,7 @@ def translate_bool(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value @specialize_function("builtins.float") -def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Optional[Value]: +def translate_float(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None: if len(expr.args) != 1 or expr.arg_kinds[0] != ARG_POS: return None arg = expr.args[0] diff --git a/mypyc/primitives/registry.py b/mypyc/primitives/registry.py index 1e2cf2695ee7..aa96b35aec56 100644 --- a/mypyc/primitives/registry.py +++ b/mypyc/primitives/registry.py @@ -37,8 +37,7 @@ from __future__ import annotations -from typing import List, NamedTuple, Optional, Tuple -from typing_extensions import Final +from typing import Final, NamedTuple from mypyc.ir.ops import StealsDescription from mypyc.ir.rtypes import RType @@ -50,16 +49,16 @@ class CFunctionDescription(NamedTuple): name: str - arg_types: List[RType] + arg_types: list[RType] return_type: RType - var_arg_type: Optional[RType] - truncated_type: Optional[RType] + var_arg_type: RType | None + truncated_type: RType | None c_function_name: str error_kind: int steals: StealsDescription is_borrowed: bool - ordering: Optional[List[int]] - extra_int_constants: List[Tuple[int, RType]] + ordering: list[int] | None + extra_int_constants: list[tuple[int, RType]] priority: int diff --git a/mypyc/test-data/fixtures/testutil.py b/mypyc/test-data/fixtures/testutil.py index 5a4b1d0f549e..7f00ee5aea00 100644 --- a/mypyc/test-data/fixtures/testutil.py +++ b/mypyc/test-data/fixtures/testutil.py @@ -7,7 +7,7 @@ Any, Iterator, TypeVar, Generator, Optional, List, Tuple, Sequence, Union, Callable, Awaitable, ) -from typing_extensions import Final +from typing import Final FLOAT_MAGIC: Final = -113.0