Skip to content

Commit e6a0527

Browse files
authored
Remove remaining type comments in favour of PEP 526 annotations (#13454)
1 parent 7606270 commit e6a0527

File tree

7 files changed

+21
-19
lines changed

7 files changed

+21
-19
lines changed

misc/incremental_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import textwrap
4545
import time
4646
from argparse import ArgumentParser, Namespace, RawDescriptionHelpFormatter
47-
from typing import Any, Dict, Tuple
47+
from typing import Any, Dict
4848
from typing_extensions import Final, TypeAlias as _TypeAlias
4949

5050
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
7070
proc = subprocess.Popen(
7171
" ".join(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True
7272
)
73-
stdout_bytes, stderr_bytes = proc.communicate() # type: Tuple[bytes, bytes]
73+
stdout_bytes, stderr_bytes = proc.communicate()
7474
stdout, stderr = stdout_bytes.decode("utf-8"), stderr_bytes.decode("utf-8")
7575
if fail_on_error and proc.returncode != 0:
7676
print("EXECUTED COMMAND:", repr(command))

misc/perf_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import subprocess
99
import textwrap
1010
import time
11-
from typing import Callable, Tuple
11+
from typing import Callable
1212

1313

1414
class Command:
@@ -32,7 +32,7 @@ def execute(command: list[str]) -> None:
3232
proc = subprocess.Popen(
3333
" ".join(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True
3434
)
35-
stdout_bytes, stderr_bytes = proc.communicate() # type: Tuple[bytes, bytes]
35+
stdout_bytes, stderr_bytes = proc.communicate()
3636
stdout, stderr = stdout_bytes.decode("utf-8"), stderr_bytes.decode("utf-8")
3737
if proc.returncode != 0:
3838
print("EXECUTED COMMAND:", repr(command))

misc/touch_checker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import textwrap
1212
import time
13-
from typing import Callable, Tuple
13+
from typing import Callable
1414

1515

1616
def print_offset(text: str, indent_length: int = 4) -> None:
@@ -28,7 +28,7 @@ def execute(command: list[str]) -> None:
2828
proc = subprocess.Popen(
2929
" ".join(command), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True
3030
)
31-
stdout_bytes, stderr_bytes = proc.communicate() # type: Tuple[bytes, bytes]
31+
stdout_bytes, stderr_bytes = proc.communicate()
3232
stdout, stderr = stdout_bytes.decode("utf-8"), stderr_bytes.decode("utf-8")
3333
if proc.returncode != 0:
3434
print("EXECUTED COMMAND:", repr(command))

mypy/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
Mapping,
3636
NamedTuple,
3737
NoReturn,
38-
Optional,
3938
Sequence,
4039
TextIO,
4140
TypeVar,
@@ -2490,7 +2489,8 @@ def verify_dependencies(self, suppressed_only: bool = False) -> None:
24902489
line = self.dep_line_map.get(dep, 1)
24912490
try:
24922491
if dep in self.ancestors:
2493-
state, ancestor = None, self # type: (Optional[State], Optional[State])
2492+
state: State | None = None
2493+
ancestor: State | None = self
24942494
else:
24952495
state, ancestor = self, None
24962496
# Called just for its side effects of producing diagnostics.

mypy/checkexpr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,8 @@ def check_boolean_op(self, e: OpExpr, context: Context) -> Type:
33703370
assert e.op in ("and", "or") # Checked by visit_op_expr
33713371

33723372
if e.right_always:
3373-
left_map, right_map = None, {} # type: mypy.checker.TypeMap, mypy.checker.TypeMap
3373+
left_map: mypy.checker.TypeMap = None
3374+
right_map: mypy.checker.TypeMap = {}
33743375
elif e.right_unreachable:
33753376
left_map, right_map = {}, None
33763377
elif e.op == "and":

mypy/semanal.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from __future__ import annotations
5252

5353
from contextlib import contextmanager
54-
from typing import Any, Callable, Iterable, Iterator, List, Optional, Set, TypeVar, cast
54+
from typing import Any, Callable, Iterable, Iterator, List, TypeVar, cast
5555
from typing_extensions import Final, TypeAlias as _TypeAlias
5656

5757
from mypy import errorcodes as codes, message_registry
@@ -1215,8 +1215,9 @@ def analyze_function_body(self, defn: FuncItem) -> None:
12151215
self.function_stack.pop()
12161216

12171217
def check_classvar_in_signature(self, typ: ProperType) -> None:
1218+
t: ProperType
12181219
if isinstance(typ, Overloaded):
1219-
for t in typ.items: # type: ProperType
1220+
for t in typ.items:
12201221
self.check_classvar_in_signature(t)
12211222
return
12221223
if not isinstance(typ, CallableType):
@@ -1463,7 +1464,8 @@ def analyze_namedtuple_classdef(
14631464
):
14641465
# Don't reprocess everything. We just need to process methods defined
14651466
# in the named tuple class body.
1466-
is_named_tuple, info = True, defn.info # type: bool, Optional[TypeInfo]
1467+
is_named_tuple = True
1468+
info: TypeInfo | None = defn.info
14671469
else:
14681470
is_named_tuple, info = self.named_tuple_analyzer.analyze_namedtuple_classdef(
14691471
defn, self.is_stub_file, self.is_func_scope()
@@ -3149,11 +3151,9 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
31493151
res: Type | None = None
31503152
if self.is_none_alias(rvalue):
31513153
res = NoneType()
3152-
alias_tvars, depends_on, qualified_tvars = (
3153-
[],
3154-
set(),
3155-
[],
3156-
) # type: List[str], Set[str], List[str]
3154+
alias_tvars: list[str] = []
3155+
depends_on: set[str] = set()
3156+
qualified_tvars: list[str] = []
31573157
else:
31583158
tag = self.track_incomplete_refs()
31593159
res, alias_tvars, depends_on, qualified_tvars = self.analyze_alias(

mypy/stubgen.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
import sys
4949
import traceback
5050
from collections import defaultdict
51-
from typing import Dict, Iterable, List, Mapping, Optional, cast
51+
from typing import Iterable, List, Mapping, cast
5252
from typing_extensions import Final
5353

5454
import mypy.build
@@ -1652,7 +1652,8 @@ def generate_stubs(options: Options) -> None:
16521652
py_modules, c_modules = collect_build_targets(options, mypy_opts)
16531653

16541654
# Collect info from docs (if given):
1655-
sigs = class_sigs = None # type: Optional[Dict[str, str]]
1655+
sigs: dict[str, str] | None = None
1656+
class_sigs = sigs
16561657
if options.doc_dir:
16571658
sigs, class_sigs = collect_docs_signatures(options.doc_dir)
16581659

0 commit comments

Comments
 (0)