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

Check types wit mypy #1039

Merged
merged 7 commits into from Nov 4, 2018
Merged

Check types wit mypy #1039

merged 7 commits into from Nov 4, 2018

Conversation

Mic92
Copy link
Member

@Mic92 Mic92 commented Nov 2, 2018

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.

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.
@Mic92
Copy link
Member Author

Mic92 commented Nov 2, 2018

I wonder why there is no CI support in this repository. I could add travis ci to build at least the release.nix.

@Mic92
Copy link
Member Author

Mic92 commented Nov 4, 2018

cc @domenkozar

Copy link
Member

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

@Mic92
Copy link
Member Author

Mic92 commented Nov 4, 2018

Anything left to do here?

@domenkozar domenkozar merged commit f79a749 into NixOS:master Nov 4, 2018
@Mic92 Mic92 deleted the mypy branch November 4, 2018 22:08
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

2 participants