This relates to #19389 by enabling mypy to run without --ignore-imports. This is the minimum amount of work needed to get mypy running in the linter, after which annotations can be added to scripts in contrib/ and test_framework/ to get the full benefit of running mypy in the linter.
special notes
This also involved updating PyZMQ per #19389 (comment) .
how to test
after making these changes, I ran ./test/lint/lint-python.sh and verified no errors.
To be sure mypy would actually catch type errors when they existed, I added the following lines to contrib/devtools/symbol-checker.py:
def check_imported_symbols(filename: str) -> bool:
test = filename + 1
...
First, filename needed to be annotated as str, or else mypy treats it as Any and Any +1 is allowed. After annotating filename: str and adding an illegal operation, running ./test/lint/lint-python.sh` returned the following error:
contrib/devtools/symbol-check.py:170:5: F841 local variable 'test' is assigned to but never used
contrib/devtools/symbol-check.py:170: error: Unsupported operand types for + ("str" and "int") [operator]
next steps
Where we do have mypy annotations, they are often incomplete. This causes mypy to evaluate arguments as Any (see example above with symbol-checker.py). I propose a follow-up PR adding annotations. At a minimum, annotations should be added for everything in test_framework/, which can be done fairly easily with monkeytype. The benefit of this is, now that we are running without --ignore-imports, mypy can detect errors in the functional tests even if they don't have annotations, so long as all of the files in test_framework/ are fully annotated.