run_mypy: refactor check_mypy so that the import is used

This tries `from mypy.version import ...` instead of `import mypy`, and
then consolidates the branch checks. This is slightly cleaner, and
removes the need to ignore pyflakes warnings.
This commit is contained in:
Dylan Baker authored and Paolo Bonzini committed 2026-10-24 08:13:14 +02:00
1 parent 485650c1ef
commit 14d74d1f5d
1 file changed
+6 -7
+6 -7
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright © 2024 Intel Corporation
# Copyright © 2024-2026 Intel Corporation
from pathlib import Path
import argparse
@@ -26,14 +26,13 @@ additional = [
def check_mypy() -> None:
try:
import mypy
from mypy.version import __version__ as mypy_version
if version_compare(mypy_version, '>=0.812'):
return
print('mypy >=0.812 is required, older versions report spurious errors')
except ImportError:
print('Failed import mypy')
sys.exit(1)
from mypy.version import __version__ as mypy_version
if not version_compare(mypy_version, '>=0.812'):
print('mypy >=0.812 is required, older versions report spurious errors')
sys.exit(1)
sys.exit(1)
def main() -> int:
root = Path(__file__).absolute().parent