-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial type annotations and mypy setup #1842
Conversation
6c3975a
to
863814a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to being able to replace my validation code with this + some decorator :-)
c83a4cc
to
e08f835
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first exposure to Python typing - I might have made dumb suggestions...
Running tox on the latest develop branch on my (hopefully now updated) development environment fails:
Do I have a bad/wrong version of mypy? |
Ah, I have: Just my luck! They changed it. |
This adds a mypy lint task in tox and CI and adds typing to a number of modules.
One use-before-definition bug in an exception handler has already been caught thanks to mypy. Bonus points for finding it in the diff ;-)
Modules that have type annotations are, until we're fully typed, explicitly added to
setup.cfg
. This way, we can gradually type more and more of Mopidy, similarly to how we gradually made more and more of the test suite pass on Python 3 in late 2019.I've made extensive use of
from __future__ import annotations
in combination with keeping typing-only imports insideif TYPE_CHECKING
. This ensures that the runtime performance hit from the type annotations is minimal.