iotests: annotate TestRunner.shared_self for mypy 2.4
PATCH 1/1 iotests: annotate TestRunner.shared_self for mypy 2.4
mypy 2.4.0 infers the unannotated class attribute "shared_self = None" as having type "None" and rejects the later assignment of a TestRunner instance in run_tests_pool():
testrunner.py:126: error: Incompatible types in assignment (expression has type "TestRunner", variable has type "None")
Earlier mypy versions treated the attribute as a partial type and accepted the assignment. Give the attribute an explicit Optional['TestRunner'] annotation so both old and new mypy agree.
Fixes tests/linters.py::TestLinters::test_mypy_iotests with mypy >= 2.4.
---
CI run with mypy 2.4: https://gitlab.com/tpambor/qemu/-/pipelines/2905639361
--- tests/qemu-iotests/testrunner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qemu-iotests/testrunner.py +1 -1
@@ -108,7 +108,7 @@ def __init__(self, status: str, description: str = '', class TestRunner(contextlib.AbstractContextManager['TestRunner']): - shared_self = None + shared_self: Optional['TestRunner'] = None @staticmethod def proc_run_test(test: str, test_field_width: int) -> TestResult:
---
base-commit: f7ada39edacaa5c26b30e98b94017b0b2ccbcf94
change-id: 20261002-mypy-2-4-2544da3f4e17
Best regards,
Signature · 1 line
Tim Pambor <[email protected]>
Kevin Wolf
AppliedAm 02.10.2026 um 09:04 hat Tim Pambor geschrieben:
Quoted 11 lines
mypy 2.4.0 infers the unannotated class attribute "
shared_self= None" as having type "None" and rejects the later assignment of a TestRunner instance inrun_tests_pool():testrunner.py:126: error: Incompatible types in assignment (expression has type "TestRunner", variable has type "None")
Earlier mypy versions treated the attribute as a partial type and accepted the assignment. Give the attribute an explicit Optional['TestRunner'] annotation so both old and new mypy agree.
Quoted 5 lines
Fixes tests/linters.py::TestLinters::test_mypy_iotests with mypy >= 2.4.
Signed-off-by Tim Pambor <[email protected]>---
CI run with mypy 2.4: https://gitlab.com/tpambor/qemu/-/pipelines/2905639361
Thanks, applied to the block branch.
Kevin