Skip to content

MyPy, Next Steps #19389

@troygiorshev

Description

@troygiorshev

MyPy was added in #18210, allowing for static type checking of type hints in our testing framework. However, there is still some work to be done before we can take advantage of these new capabilities. 🚀

Right now, lint-python.sh runs MyPy with the --ignore-imports flag. This is done primarily to ignore the lack of type hinting for zmq, but it hides many errors in our own code too.

To begin to see what's needed, first run mypy test/functional. You'll see two sets of errors. One complains about Skipping analyzing 'zmq'. This one can be ignored for now by changing the identified import zmq lines to import zmq # type: ignore.

The other states that it Cannot find implementation or library stub for module named 'data'. Remember that for a second.

Now go into test/functional/test_framework and run mypy mininode.py. Observe two more Cannot find implementation or library stub for module errors, now for test_framework.messages and test_framework.util.

What's happening here is that MyPy is failing to handle importing our test_framework package. We'll need to do a few things to fix this.

Resources

Important Notes

Our minimum supported python version is 3.5, so any changes must be compatible. In particular this means that we must use type comments, as opposed to type hinting, in variables that aren't function parameters. (i.e. foo # type: int as opposed to foo: int). This will complicate the use of MonkeyType, as it doesn't support type comments. It may be useful to make a scripted diff between type comments and type hints.

Useful skills:

MyPy experience

Want to work on this issue?

For guidance on contributing, please read CONTRIBUTING.md before opening your pull request.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions