diff --git a/misc/incremental_checker.py b/misc/incremental_checker.py index a80370105113..3f5393717ba6 100755 --- a/misc/incremental_checker.py +++ b/misc/incremental_checker.py @@ -44,7 +44,7 @@ import textwrap import time from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter -from typing import Any, Dict, Tuple +from typing import Any, Dict from typing_extensions import Final, TypeAlias as _TypeAlias CACHE_PATH: Final = ".incremental_checker_cache.json" @@ -70,7 +70,7 @@ def execute(command: list[str], fail_on_error: bool = True) -> tuple[str, str, i proc = subprocess.Popen( " ".join(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) - stdout_bytes, stderr_bytes = proc.communicate() # type: Tuple[bytes, bytes] + stdout_bytes, stderr_bytes = proc.communicate() stdout, stderr = stdout_bytes.decode("utf-8"), stderr_bytes.decode("utf-8") if fail_on_error and proc.returncode != 0: print("EXECUTED COMMAND:", repr(command)) diff --git a/misc/perf_checker.py b/misc/perf_checker.py index 52095f9fe052..20c313e61af9 100644 --- a/misc/perf_checker.py +++ b/misc/perf_checker.py @@ -8,7 +8,7 @@ import subprocess import textwrap import time -from typing import Callable, Tuple +from typing import Callable class Command: @@ -32,7 +32,7 @@ def execute(command: list[str]) -> None: proc = subprocess.Popen( " ".join(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) - stdout_bytes, stderr_bytes = proc.communicate() # type: Tuple[bytes, bytes] + stdout_bytes, stderr_bytes = proc.communicate() stdout, stderr = stdout_bytes.decode("utf-8"), stderr_bytes.decode("utf-8") if proc.returncode != 0: print("EXECUTED COMMAND:", repr(command)) diff --git a/misc/touch_checker.py b/misc/touch_checker.py index 45d4b00d2973..64611880fcc8 100644 --- a/misc/touch_checker.py +++ b/misc/touch_checker.py @@ -10,7 +10,7 @@ import sys import textwrap import time -from typing import Callable, Tuple +from typing import Callable def print_offset(text: str, indent_length: int = 4) -> None: @@ -28,7 +28,7 @@ def execute(command: list[str]) -> None: proc = subprocess.Popen( " ".join(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True ) - stdout_bytes, stderr_bytes = proc.communicate() # type: Tuple[bytes, bytes] + stdout_bytes, stderr_bytes = proc.communicate() stdout, stderr = stdout_bytes.decode("utf-8"), stderr_bytes.decode("utf-8") if proc.returncode != 0: print("EXECUTED COMMAND:", repr(command)) diff --git a/mypy/build.py b/mypy/build.py index 1d7ab25c989e..c409b90d0b73 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -35,7 +35,6 @@ Mapping, NamedTuple, NoReturn, - Optional, Sequence, TextIO, TypeVar, @@ -2490,7 +2489,8 @@ def verify_dependencies(self, suppressed_only: bool = False) -> None: line = self.dep_line_map.get(dep, 1) try: if dep in self.ancestors: - state, ancestor = None, self # type: (Optional[State], Optional[State]) + state: State | None = None + ancestor: State | None = self else: state, ancestor = self, None # Called just for its side effects of producing diagnostics. diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py index cb542ee5300b..914ede54affd 100644 --- a/mypy/checkexpr.py +++ b/mypy/checkexpr.py @@ -3370,7 +3370,8 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type: assert e.op in ("and", "or") # Checked by visit_op_expr if e.right_always: - left_map, right_map = None, {} # type: mypy.checker.TypeMap, mypy.checker.TypeMap + left_map: mypy.checker.TypeMap = None + right_map: mypy.checker.TypeMap = {} elif e.right_unreachable: left_map, right_map = {}, None elif e.op == "and": diff --git a/mypy/semanal.py b/mypy/semanal.py index 08456c9ad845..71f588a144a0 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -51,7 +51,7 @@ from __future__ import annotations from contextlib import contextmanager -from typing import Any, Callable, Iterable, Iterator, List, Optional, Set, TypeVar, cast +from typing import Any, Callable, Iterable, Iterator, List, TypeVar, cast from typing_extensions import Final, TypeAlias as _TypeAlias from mypy import errorcodes as codes, message_registry @@ -1215,8 +1215,9 @@ def analyze_function_body(self, defn: FuncItem) -> None: self.function_stack.pop() def check_classvar_in_signature(self, typ: ProperType) -> None: + t: ProperType if isinstance(typ, Overloaded): - for t in typ.items: # type: ProperType + for t in typ.items: self.check_classvar_in_signature(t) return if not isinstance(typ, CallableType): @@ -1463,7 +1464,8 @@ def analyze_namedtuple_classdef( ): # Don't reprocess everything. We just need to process methods defined # in the named tuple class body. - is_named_tuple, info = True, defn.info # type: bool, Optional[TypeInfo] + is_named_tuple = True + info: TypeInfo | None = defn.info else: is_named_tuple, info = self.named_tuple_analyzer.analyze_namedtuple_classdef( defn, self.is_stub_file, self.is_func_scope() @@ -3149,11 +3151,9 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool: res: Type | None = None if self.is_none_alias(rvalue): res = NoneType() - alias_tvars, depends_on, qualified_tvars = ( - [], - set(), - [], - ) # type: List[str], Set[str], List[str] + alias_tvars: list[str] = [] + depends_on: set[str] = set() + qualified_tvars: list[str] = [] else: tag = self.track_incomplete_refs() res, alias_tvars, depends_on, qualified_tvars = self.analyze_alias( diff --git a/mypy/stubgen.py b/mypy/stubgen.py index 243db68f7a80..932c92ffe165 100755 --- a/mypy/stubgen.py +++ b/mypy/stubgen.py @@ -48,7 +48,7 @@ import sys import traceback from collections import defaultdict -from typing import Dict, Iterable, List, Mapping, Optional, cast +from typing import Iterable, List, Mapping, cast from typing_extensions import Final import mypy.build @@ -1652,7 +1652,8 @@ def generate_stubs(options: Options) -> None: py_modules, c_modules = collect_build_targets(options, mypy_opts) # Collect info from docs (if given): - sigs = class_sigs = None # type: Optional[Dict[str, str]] + sigs: dict[str, str] | None = None + class_sigs = sigs if options.doc_dir: sigs, class_sigs = collect_docs_signatures(options.doc_dir)