Skip to content

Commit d5d5b90

Browse files
committed
Convert type comments to annotations using com2ann
1 parent 487b736 commit d5d5b90

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

misc/analyze_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def report_most_common(chunks: List[JsonDict], amount: Optional[int] = None) ->
8686

8787

8888
def compress(chunk: JsonDict) -> JsonDict:
89-
cache = {} # type: Dict[int, JsonDict]
89+
cache: Dict[int, JsonDict] = {}
9090
counter = 0
9191

9292
def helper(chunk: Any) -> Any:
@@ -119,7 +119,7 @@ def helper(chunk: Any) -> Any:
119119

120120

121121
def decompress(chunk: JsonDict) -> JsonDict:
122-
cache = {} # type: Dict[int, JsonDict]
122+
cache: Dict[int, JsonDict] = {}
123123

124124
def helper(chunk: Any) -> Any:
125125
if not isinstance(chunk, dict):

misc/incremental_checker.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def run_mypy(
136136
137137
If `daemon` is True, we use daemon mode; the daemon must be started and stopped by the caller.
138138
"""
139-
stats = {} # type: Dict[str, Any]
139+
stats: Dict[str, Any] = {}
140140
if daemon:
141141
command = DAEMON_CMD + ["check", "-v"]
142142
else:
@@ -163,7 +163,7 @@ def run_mypy(
163163

164164

165165
def filter_daemon_stats(output: str) -> Tuple[str, Dict[str, Any]]:
166-
stats = {} # type: Dict[str, Any]
166+
stats: Dict[str, Any] = {}
167167
lines = output.splitlines()
168168
output_lines = []
169169
for line in lines:
@@ -258,16 +258,16 @@ def test_incremental(
258258
"""
259259
print("Note: first commit is evaluated twice to warm up cache")
260260
commits = [commits[0]] + commits
261-
overall_stats = {} # type: Dict[str, float]
261+
overall_stats: Dict[str, float] = {}
262262
for commit_id, message in commits:
263263
print(f'Now testing commit {commit_id}: "{message}"')
264264
execute(["git", "-C", temp_repo_path, "checkout", commit_id])
265265
runtime, output, stats = run_mypy(
266266
target_file_path, mypy_cache_path, mypy_script, incremental=True, daemon=daemon
267267
)
268268
relevant_stats = combine_stats(overall_stats, stats)
269-
expected_runtime = cache[commit_id]["runtime"] # type: float
270-
expected_output = cache[commit_id]["output"] # type: str
269+
expected_runtime: float = cache[commit_id]["runtime"]
270+
expected_output: str = cache[commit_id]["output"]
271271
if output != expected_output:
272272
print(" Output does not match expected result!")
273273
print(f" Expected output ({expected_runtime:.3f} sec):")
@@ -289,7 +289,7 @@ def test_incremental(
289289
def combine_stats(overall_stats: Dict[str, float], new_stats: Dict[str, Any]) -> Dict[str, float]:
290290
INTERESTING_KEYS = ["build_time", "gc_time"]
291291
# For now, we only support float keys
292-
relevant_stats = {} # type: Dict[str, float]
292+
relevant_stats: Dict[str, float] = {}
293293
for key in INTERESTING_KEYS:
294294
if key in new_stats:
295295
value = float(new_stats[key])
@@ -391,9 +391,9 @@ def test_repo(
391391

392392

393393
def main() -> None:
394-
help_factory = lambda prog: RawDescriptionHelpFormatter(
394+
help_factory: Any = lambda prog: RawDescriptionHelpFormatter(
395395
prog=prog, max_help_position=32
396-
) # type: Any
396+
)
397397
parser = ArgumentParser(
398398
prog="incremental_checker", description=__doc__, formatter_class=help_factory
399399
)

misc/test_case_to_actual.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Chunk:
1010
def __init__(self, header_type: str, args: str) -> None:
1111
self.header_type = header_type
1212
self.args = args
13-
self.lines = [] # type: List[str]
13+
self.lines: List[str] = []
1414

1515

1616
def is_header(line: str) -> bool:
@@ -22,7 +22,7 @@ def normalize(lines: Iterator[str]) -> Iterator[str]:
2222

2323

2424
def produce_chunks(lines: Iterator[str]) -> Iterator[Chunk]:
25-
current_chunk = None # type: Chunk
25+
current_chunk: Chunk = None
2626
for line in normalize(lines):
2727
if is_header(line):
2828
if current_chunk is not None:

misc/touch_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def teardown() -> None:
6464

6565

6666
def make_change_wrappers(filename: str) -> Tuple[Command, Command]:
67-
copy = None # type: Optional[str]
67+
copy: Optional[str] = None
6868

6969
def setup() -> None:
7070
nonlocal copy

mypy/modulefinder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ class BuildSourceSet:
134134

135135
def __init__(self, sources: List[BuildSource]) -> None:
136136
self.source_text_present = False
137-
self.source_modules = {} # type: Dict[str, str]
138-
self.source_paths = set() # type: Set[str]
137+
self.source_modules: Dict[str, str] = {}
138+
self.source_paths: Set[str] = set()
139139

140140
for source in sources:
141141
if source.text is not None:

mypy/test/teststubgen.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ def test(self, arg0: str) -> None:
887887
"""
888888
pass
889889

890-
output = [] # type: List[str]
891-
imports = [] # type: List[str]
890+
output: List[str] = []
891+
imports: List[str] = []
892892
mod = ModuleType(TestClass.__module__, "")
893893
generate_c_function_stub(
894894
mod, "test", TestClass.test, output, imports, self_var="self", class_name="TestClass"
@@ -902,8 +902,8 @@ class TestClass:
902902
def test(cls, arg0: str) -> None:
903903
pass
904904

905-
output = [] # type: List[str]
906-
imports = [] # type: List[str]
905+
output: List[str] = []
906+
imports: List[str] = []
907907
mod = ModuleType(TestClass.__module__, "")
908908
generate_c_function_stub(
909909
mod, "test", TestClass.test, output, imports, self_var="cls", class_name="TestClass"

0 commit comments

Comments
 (0)