Skip to content

Commit 2cafba8

Browse files
Ignore missing types in syntax check (#8660)
1 parent 513ced3 commit 2cafba8

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

mypy.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Global options:
2+
3+
[mypy]
4+
disable_error_code = var-annotated,has-type

run_syntax_check.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,28 @@ def adjust_file_contents(target_file: str):
1818
file_content = file.read_text()
1919
adjusted_import = 'from AlgorithmImports import *;from datetime import date, time, datetime, timedelta;import pandas as pd;import numpy as np;'
2020

21-
tmpFile = tempfile.NamedTemporaryFile(prefix=f"{file.name}_", delete=False)
22-
Path(tmpFile.name).write_text("# mypy: disable-error-code=\"no-redef\"\n" + file_content.replace("from AlgorithmImports import *", adjusted_import))
23-
return tmpFile
21+
tmp_file = tempfile.NamedTemporaryFile(prefix=f"{file.name}_", delete=False)
22+
Path(tmp_file.name).write_text("# mypy: disable-error-code=\"no-redef\"\n" + file_content.replace("from AlgorithmImports import *", adjusted_import))
23+
return tmp_file
2424

2525
def run_syntax_check(target_file: str):
26-
tmpFile = adjust_file_contents(target_file)
26+
tmp_file = adjust_file_contents(target_file)
2727
try:
28-
result = run([sys.executable, "-m", "mypy", "--skip-cache-mtime-checks", "--skip-version-check", "--show-error-codes",
28+
algorithm_result = run([sys.executable, "-m", "mypy", "--skip-cache-mtime-checks", "--skip-version-check", "--show-error-codes",
2929
"--no-error-summary", "--no-color-output", "--ignore-missing-imports", "--check-untyped-defs", "--cache-fine-grained", "--install-types",
30-
"--non-interactive", "--cache-dir", "mypy_cache", tmpFile.name], capture_output=True, text=True)
30+
"--non-interactive", "--cache-dir", "mypy_cache", tmp_file.name], capture_output=True, text=True)
3131

32-
print(result.stdout)
33-
if result.stderr:
34-
print(result.stderr)
32+
print(algorithm_result.stdout)
33+
if algorithm_result.stderr:
34+
print(algorithm_result.stderr)
3535
return False
3636
return True
3737
except:
3838
import traceback
3939
print(f"{target_file} failed An exception occurred: {traceback.format_exc()}")
4040
finally:
41-
tmpFile.close()
42-
os.unlink(tmpFile.name)
41+
tmp_file.close()
42+
os.unlink(tmp_file.name)
4343
return False
4444

4545
if __name__ == '__main__':
@@ -50,4 +50,5 @@ def run_syntax_check(target_file: str):
5050
target_files = [target for target in target_files if sys.argv[1] in target]
5151
result = pool.map(run_syntax_check, target_files)
5252
print(result)
53+
print(f"SUCCESS RATE {round((sum(result) / len(result)) * 100, 1)}%")
5354
exit(0 if all(result) else 1)

0 commit comments

Comments
 (0)