From 5deb33b03c221634829e5ac57d6a6bd77453759c Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 30 Aug 2020 15:58:23 +0200 Subject: [PATCH] typing: update run_mypy and mypy.ini --- .mypy.ini | 26 +++++++++++--- run_mypy.py | 98 ++++++++++++++--------------------------------------- 2 files changed, 48 insertions(+), 76 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index b8dad03fc1fc..3da85ed3ffd5 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -1,5 +1,23 @@ [mypy] -strict_optional = False -show_error_context = False -show_column_numbers = True -ignore_missing_imports = True +strict_optional = False +show_error_context = False +show_column_numbers = True +ignore_missing_imports = True + +follow_imports = skip +warn_redundant_casts = True +warn_unused_ignores = True +warn_return_any = True +# warn_unreachable = True +disallow_untyped_calls = True +disallow_untyped_defs = True +disallow_incomplete_defs = True +disallow_untyped_decorators = True +no_implicit_optional = True +strict_equality = True +check_untyped_defs = True +# disallow_any_expr = True +# disallow_any_decorated = True +# disallow_any_explicit = True +# disallow_any_generics = True +# disallow_subclassing_any = True diff --git a/run_mypy.py b/run_mypy.py index 9851b5d83beb..759d66783d05 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -6,79 +6,34 @@ from pathlib import Path import typing as T -normal_modules = [ - 'mesonbuild/interpreterbase.py', - 'mesonbuild/mtest.py', - 'mesonbuild/minit.py', - 'mesonbuild/mintro.py', - 'mesonbuild/mparser.py', - 'mesonbuild/msetup.py', +modules = [ + # fully typed submodules 'mesonbuild/ast', - 'mesonbuild/wrap', 'mesonbuild/scripts', - 'tools', - 'mesonbuild/modules/fs.py', - # 'mesonbuild/dependencies/base.py', + 'mesonbuild/wrap', + + # specific files + 'mesonbuild/arglist.py', + # 'mesonbuild/compilers/mixins/intel.py', 'mesonbuild/dependencies/boost.py', - 'mesonbuild/dependencies/mpi.py', 'mesonbuild/dependencies/hdf5.py', - 'mesonbuild/compilers/mixins/intel.py', - 'mesonbuild/mlog.py', - 'mesonbuild/mcompile.py', - 'mesonbuild/mesonlib.py', - 'mesonbuild/arglist.py', + 'mesonbuild/dependencies/mpi.py', 'mesonbuild/envconfig.py', -] - -strict_modules = [ 'mesonbuild/interpreterbase.py', - 'mesonbuild/mtest.py', - 'mesonbuild/minit.py', - 'mesonbuild/mintro.py', - 'mesonbuild/mparser.py', - 'mesonbuild/msetup.py', 'mesonbuild/mcompile.py', 'mesonbuild/mesonlib.py', + 'mesonbuild/minit.py', + 'mesonbuild/mintro.py', 'mesonbuild/mlog.py', - 'mesonbuild/ast', - 'mesonbuild/wrap', - 'mesonbuild/scripts', 'mesonbuild/modules/fs.py', - 'mesonbuild/dependencies/boost.py', - 'mesonbuild/dependencies/hdf5.py', - 'mesonbuild/compilers/mixins/intel.py', - 'mesonbuild/arglist.py', - 'run_mypy.py', - 'tools', -] + 'mesonbuild/mparser.py', + 'mesonbuild/msetup.py', + 'mesonbuild/mtest.py', -normal_args = ['--follow-imports=skip'] -strict_args = normal_args + [ - '--warn-redundant-casts', - '--warn-unused-ignores', - '--warn-return-any', - # '--warn-unreachable', - '--disallow-untyped-calls', - '--disallow-untyped-defs', - '--disallow-incomplete-defs', - '--disallow-untyped-decorators', - '--no-implicit-optional', - '--strict-equality', - # '--disallow-any-expr', - # '--disallow-any-decorated', - # '--disallow-any-explicit', - # '--disallow-any-generics', - # '--disallow-subclassing-any', + 'run_mypy.py', + 'tools' ] -def run_mypy(opts: T.List[str], modules: T.List[str]) -> int: - root = Path(__file__).absolute().parent - p = subprocess.run( - [sys.executable, '-m', 'mypy'] + opts + modules, - cwd=root, - ) - return p.returncode - def check_mypy() -> None: try: import mypy @@ -87,24 +42,23 @@ def check_mypy() -> None: sys.exit(1) def main() -> int: - res = 0 check_mypy() + root = Path(__file__).absolute().parent + args = [] # type: T.List[str] + parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('-p', '--pretty', action='store_true', help='pretty print mypy errors') - args = parser.parse_args() - if args.pretty: - normal_args.append('--pretty') - strict_args.append('--pretty') + opts = parser.parse_args() + if opts.pretty: + args.append('--pretty') - print('Running normal mypy check...') - res += run_mypy(normal_args, normal_modules) - - print('\n\nRunning struct mypy check...') - res += run_mypy(strict_args, strict_modules) - - return res + p = subprocess.run( + [sys.executable, '-m', 'mypy'] + args + modules, + cwd=root, + ) + return p.returncode if __name__ == '__main__': sys.exit(main())