iotests/linters: check mypy files all at once

We can circumvent the '__main__' redefinition problem by passing
--scripts-are-modules. Take mypy out of the loop per-filename and check
everything in one go: it's quite a bit faster.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20210923180715.4168522-4-jsnow@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
John Snow 2021-09-23 14:07:12 -04:00 committed by Kevin Wolf
parent af6d4c56e1
commit f39decb583

View File

@ -74,32 +74,28 @@ def run_linters():
print('=== mypy ===') print('=== mypy ===')
sys.stdout.flush() sys.stdout.flush()
# We have to call mypy separately for each file. Otherwise, it
# will interpret all given files as belonging together (i.e., they
# may not both define the same classes, etc.; most notably, they
# must not both define the __main__ module).
env['MYPYPATH'] = env['PYTHONPATH'] env['MYPYPATH'] = env['PYTHONPATH']
for filename in files: p = subprocess.run(('mypy',
p = subprocess.run(('mypy', '--warn-unused-configs',
'--warn-unused-configs', '--disallow-subclassing-any',
'--disallow-subclassing-any', '--disallow-any-generics',
'--disallow-any-generics', '--disallow-incomplete-defs',
'--disallow-incomplete-defs', '--disallow-untyped-decorators',
'--disallow-untyped-decorators', '--no-implicit-optional',
'--no-implicit-optional', '--warn-redundant-casts',
'--warn-redundant-casts', '--warn-unused-ignores',
'--warn-unused-ignores', '--no-implicit-reexport',
'--no-implicit-reexport', '--namespace-packages',
'--namespace-packages', '--scripts-are-modules',
filename), *files),
env=env, env=env,
check=False, check=False,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
universal_newlines=True) universal_newlines=True)
if p.returncode != 0: if p.returncode != 0:
print(p.stdout) print(p.stdout)
for linter in ('pylint-3', 'mypy'): for linter in ('pylint-3', 'mypy'):