Skip to content
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

Merged
merged 13 commits into from
Jan 20, 2021
Merged

Initial type annotations and mypy setup #1842

merged 13 commits into from
Jan 20, 2021

Conversation

jodal
Copy link
Member

@jodal jodal commented Nov 9, 2019

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 inside if TYPE_CHECKING. This ensures that the runtime performance hit from the type annotations is minimal.

@jodal jodal self-assigned this Nov 9, 2019
@jodal jodal force-pushed the typing branch 5 times, most recently from 6c3975a to 863814a Compare November 10, 2019 18:27
Copy link
Member

@adamcik adamcik left a 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 :-)

mopidy/backend.py Outdated Show resolved Hide resolved
mopidy/commands.py Show resolved Hide resolved
@jodal jodal force-pushed the typing branch 5 times, most recently from c83a4cc to e08f835 Compare January 19, 2021 20:48
@jodal jodal marked this pull request as ready for review January 19, 2021 20:57
@jodal jodal changed the title Typing Initial type annotations and mypy setup Jan 19, 2021
Copy link
Member

@kingosticks kingosticks left a 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...

mopidy/mixer.py Outdated Show resolved Hide resolved
mopidy/mixer.py Show resolved Hide resolved
mopidy/ext.py Show resolved Hide resolved
mopidy/ext.py Outdated Show resolved Hide resolved
mopidy/ext.py Outdated Show resolved Hide resolved
mopidy/backend.py Outdated Show resolved Hide resolved
mopidy/backend.py Outdated Show resolved Hide resolved
mopidy/backend.py Outdated Show resolved Hide resolved
mopidy/backend.py Outdated Show resolved Hide resolved
@jodal jodal merged commit a0fa850 into mopidy:develop Jan 20, 2021
@jodal jodal deleted the typing branch January 20, 2021 22:47
@kingosticks
Copy link
Member

Running tox on the latest develop branch on my (hopefully now updated) development environment fails:

mypy run-test: commands[0] | python -m mypy mopidy
mopidy/audio/scan.py:22: error: First argument to namedtuple() should be '_Result', not 'Result'
Found 1 error in 1 file (checked 67 source files)

Do I have a bad/wrong version of mypy?

@kingosticks
Copy link
Member

kingosticks commented Jan 23, 2021

Ah, I have:
mypy==0.800
vs when you merged:
mypy==0.790

Just my luck! They changed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants