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
Check types wit mypy #1039
Merged
Merged
Check types wit mypy #1039
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Typing is a backport of python3 python module. Once we have python3 it becomes obsolete.
We ignore all third-party dependencies by default. This might look verbose on first look however it has the advantage this way we can easily see if we accidentally add new dependencies and we can detect typos in local imports. The alternative would be to ignore all missing imports instead.
cmd is defined later as a string.
Mypy does not like re-imports from different modules. We can later drop this statement when we switch to python3.
Mypy complaints about this line. In this file I also added a more comprehensive example for typing annotation. Note that python3 has a nicer language builtin syntax. The currently used type annotations will be still compatible with python3 and can be ported on demand.
For a few container types mypy is not able to interfere the type automatically. In those cases it asks the user to provide a type manually.
I wonder why there is no CI support in this repository. I could add travis ci to build at least the |
cc @domenkozar |
domenkozar
approved these changes
Nov 4, 2018
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.
The CI runs on hydra, but it's not integrated into github. I personally would prefer something that works with github status :)
Anything left to do here? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation: Restore maintainability that was complained about in NixOS/nixpkgs#48378 (comment)
Mypy is optional typing system for python. It was designed by Guido van Rossum, the creator of python
and used on many big code bases such as Dropbox for python2 to python3 migrations.
Personally I was able to migrate a 6000 LOC non-trivial application with little test coverage in less then a day because it had type annotations. Please read the commit message descriptions for more information about the individual changes. Most types can be interfered automatically. To make a method type checked a type annotation has to be added. This also increases readability.
If this pull request is accepted I will make an effort to add semi-automatically types using the existing tests and https://github.com/dropbox/pyannotate.
I think mypy makes also sense beyond python3 migrations for a project like nixops where unittests are pretty hard due to dependencies on many external systems such as cloud apis.