Skip to content

Commit 846df06

Browse files
committed
Strenghten typechecking
The reason we were using `--protocols` was due to google/pytype#764. Skipping just the offending lines.
1 parent 736e305 commit 846df06

File tree

9 files changed

+18
-14
lines changed

9 files changed

+18
-14
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
pylint --version
2525
- name: Type check
2626
run: |
27-
pytype --protocols -j auto .
27+
pytype -j auto .
2828
- name: Test
2929
run: |
3030
pytest

compiler_opt/rl/compilation_runner_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
from absl import flags
2424
import tensorflow as tf
2525

26-
from google.protobuf import text_format
26+
# This is https://github.com/google/pytype/issues/764
27+
from google.protobuf import text_format # pytype: disable=pyi-error
28+
2729
from compiler_opt.rl import compilation_runner
2830
from compiler_opt.rl import constant
2931

compiler_opt/rl/data_collector_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_build_distribution_monitor(self):
3434
def test_early_exit(self, mock_time):
3535
mock_time.return_value = 0
3636
early_exit = data_collector.EarlyExitChecker(
37-
num_modules=10, deadline=10, thresholds=[(.9, 0), (.5, .5), (0, 1)])
37+
num_modules=10, deadline=10, thresholds=((.9, 0), (.5, .5), (0, 1)))
3838

3939
# We've waited no time, so have to hit 90% to early exit
4040
self.assertFalse(early_exit._should_exit(0))

compiler_opt/rl/local_data_collector_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
from compiler_opt.rl import compilation_runner
2828
from compiler_opt.rl import data_collector
2929
from compiler_opt.rl import local_data_collector
30-
from google.protobuf import text_format
30+
31+
# This is https://github.com/google/pytype/issues/764
32+
from google.protobuf import text_format # pytype: disable=pyi-error
3133

3234

3335
def _get_sequence_example(feature_value):

compiler_opt/rl/regalloc/regalloc_runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
import gin
2525
import tensorflow as tf
2626

27-
from google.protobuf import struct_pb2
27+
# This is https://github.com/google/pytype/issues/764
28+
from google.protobuf import struct_pb2 # pytype: disable=pyi-error
2829
from compiler_opt.rl import compilation_runner
2930

3031

compiler_opt/rl/train_locally.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def sequence_example_iterator_fn(seq_ex: List[str]):
146146
len(reward_stat_map))
147147

148148
data_collector = local_data_collector.LocalDataCollector(
149-
file_paths=file_paths,
149+
file_paths=tuple(file_paths),
150150
num_workers=FLAGS.num_workers,
151151
num_modules=FLAGS.num_modules,
152152
runner=runner,

compiler_opt/tools/__init__.py

Whitespace-only changes.

compiler_opt/tools/benchmark_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def large_variation_counters(self, variation: float):
9696
return frozenset(ret)
9797

9898
def _load_values(self, data: BenchmarkRunResults,
99-
names: Iterable[str]) -> PerBenchmarkResults:
99+
names: Iterable[str]) -> None:
100100
"""Organize json values per-benchmark, per counter.
101101
102102
Args:

compiler_opt/tools/extract_ir.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
import shutil
3535
import subprocess
3636

37-
from typing import Dict
38-
from typing import List
37+
from typing import Dict, List, Optional
3938

4039
from absl import app
4140
from absl import flags
@@ -71,15 +70,15 @@
7170

7271
# TODO(ml-compiler-opt): maybe we can also convert here the cmdline file,from a
7372
# \0 - separated list of strings, to a \n one.
74-
def should_include_module(cmdline: str, match_regexp: str) -> bool:
73+
def should_include_module(cmdline: str, match_regexp: Optional[str]) -> bool:
7574
"""Determine if the module should be included."""
7675
if match_regexp is None:
7776
return True
7877
lines = cmdline.split('\0')
7978
return any(len(re.findall(match_regexp, l)) for l in lines)
8079

8180

82-
def get_thinlto_index(cmdline: str, basedir: str) -> str:
81+
def get_thinlto_index(cmdline: str, basedir: str) -> Optional[str]:
8382
opts = cmdline.split('\0')
8483
for option in opts:
8584
if option.startswith('-fthinlto-index'):
@@ -150,7 +149,7 @@ def _get_extraction_bc_command(self, llvm_objcopy_path):
150149
]
151150

152151
def extract(self, llvm_objcopy_path: str, cmd_filter: str,
153-
is_thinlto: bool) -> str:
152+
is_thinlto: bool) -> Optional[str]:
154153
"""Run llvm-objcopy to extract the .bc and command line."""
155154
if not os.path.exists(self.input_obj()):
156155
logging.info('%s does not exist.', self.input_obj())
@@ -235,7 +234,7 @@ def make_obj(obj_file: str) -> TrainingIRExtractor:
235234

236235
# This is here just for readability, lint complains if the pooling expression is
237236
# over 3 lines; and it needs to be a non-local so it may be pickled.
238-
def extract_artifacts(obj: TrainingIRExtractor) -> str:
237+
def extract_artifacts(obj: TrainingIRExtractor) -> Optional[str]:
239238
return obj.extract(FLAGS.llvm_objcopy_path, FLAGS.cmd_filter,
240239
FLAGS.thinlto_build)
241240

@@ -272,7 +271,7 @@ def main(argv):
272271
f.write(path + '\n')
273272

274273
logging.info('Converted %d files out of %d',
275-
len(objs) - relative_output_paths.count(None), len(objs))
274+
len(objs) - len(relative_output_paths), len(objs))
276275

277276

278277
if __name__ == '__main__':

0 commit comments

Comments
 (0)