Skip to content

Commit

Permalink
Remove remaining type comments in favour of PEP 526 annotations (#13454)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Aug 20, 2022
1 parent 7606270 commit e6a0527
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions misc/incremental_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions misc/perf_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import subprocess
import textwrap
import time
from typing import Callable, Tuple
from typing import Callable


class Command:
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions misc/touch_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
Mapping,
NamedTuple,
NoReturn,
Optional,
Sequence,
TextIO,
TypeVar,
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
16 changes: 8 additions & 8 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 3 additions & 2 deletions mypy/stubgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e6a0527

Please sign in to comment.