From fe40934a1c98150ee6684a7cdd21bac640fd2ac8 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Fri, 25 Feb 2022 07:14:34 +0100 Subject: add missing type param puzzle & test pyright strict --- check_checkers.py | 36 +++++++++++++++++++++++---------- puzzles/03_missing_type_param.py | 1 + puzzles/03_type_error_in_untyped_def.py | 2 -- puzzles/04_type_error_in_untyped_def.py | 2 ++ pyrightstrict.json | 3 +++ 5 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 puzzles/03_missing_type_param.py delete mode 100644 puzzles/03_type_error_in_untyped_def.py create mode 100644 puzzles/04_type_error_in_untyped_def.py create mode 100644 pyrightstrict.json diff --git a/check_checkers.py b/check_checkers.py index 413b79d..851c66f 100755 --- a/check_checkers.py +++ b/check_checkers.py @@ -143,6 +143,10 @@ class Pyright(Checker): ) +class PyrightStrict(Pyright): + extra_args = ('-p', 'pyrightstrict.json') + + # We don't check pyre because it has a very slow startup time (5s) since it parses the whole typeshed. # (see https://github.com/facebook/pyre-check/issues/592) @@ -193,11 +197,16 @@ def run( out.write('') if checker.extra_args: out.write(' with ') - out.write( - ', '.join( - f'{html.escape(flag)}' for flag in checker.extra_args - ) - ) + out.write('') + for arg in checker.extra_args: + if not arg.startswith('-'): + out.write(''.format(html.escape(arg))) + out.write(html.escape(arg) + ' ') + if not arg.startswith('-'): + out.write('') + os.makedirs('dist/configs', exist_ok=True) + shutil.copyfile(arg, 'dist/configs/' + arg) + out.write('') out.write('
({})'.format(html.escape(checker.version()))) out.write('') @@ -222,15 +231,18 @@ def run( no_error_ok = '# error' not in code results = [ - (checker.__class__.__name__, checker_results[checker.__class__.__name__]) + (checker, checker_results[checker.__class__.__name__]) for checker in checkers ] while results: - class_name, errors = results.pop(0) + checker, errors = results.pop(0) expected = (errors and error_ok) or (not errors and no_error_ok) colspan = 1 - if errors and results and results[0][1] == errors: + if results and (checker.name, errors) == ( + results[0][0].name, + results[0][1], + ): results.pop(0) colspan = 2 out.write( @@ -249,8 +261,10 @@ def run( out.write('
no errors found') if not expected: checker_issues = issues.get( - class_name.lower(), - issues.get(class_name.lower().replace('strict', ''), {}), + checker.__class__.__name__.lower(), + issues.get( + checker.__class__.__name__.lower().replace('strict', ''), {} + ), ) issue = checker_issues.get( os.path.splitext(os.path.basename(puzzle))[0].split( @@ -279,7 +293,7 @@ if __name__ == '__main__': with open('dist/checkers.html', 'w') as f: run( - [Mypy(), MypyStrict(), Pytype(), Pyright()], + [Mypy(), MypyStrict(), Pytype(), Pyright(), PyrightStrict()], ['puzzles/' + f for f in sorted(os.listdir('puzzles'))], typeshed, f, diff --git a/puzzles/03_missing_type_param.py b/puzzles/03_missing_type_param.py new file mode 100644 index 0000000..a2bcf80 --- /dev/null +++ b/puzzles/03_missing_type_param.py @@ -0,0 +1 @@ +x: list = [] # maybe error diff --git a/puzzles/03_type_error_in_untyped_def.py b/puzzles/03_type_error_in_untyped_def.py deleted file mode 100644 index 6c87c71..0000000 --- a/puzzles/03_type_error_in_untyped_def.py +++ /dev/null @@ -1,2 +0,0 @@ -def f(): - x: int = 'Python' # error diff --git a/puzzles/04_type_error_in_untyped_def.py b/puzzles/04_type_error_in_untyped_def.py new file mode 100644 index 0000000..6c87c71 --- /dev/null +++ b/puzzles/04_type_error_in_untyped_def.py @@ -0,0 +1,2 @@ +def f(): + x: int = 'Python' # error diff --git a/pyrightstrict.json b/pyrightstrict.json new file mode 100644 index 0000000..ca8bcb9 --- /dev/null +++ b/pyrightstrict.json @@ -0,0 +1,3 @@ +{ + "typeCheckingMode": "strict" +} -- cgit v1.2.3