From 14d74d1f5df57e3504e092a5dc7e888c52487ab8 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 22 Oct 2026 13:55:13 +0000 Subject: [PATCH] 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. --- run_mypy.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/run_mypy.py b/run_mypy.py index 30cf2b41b..23d3a6fa3 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -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