-
Notifications
You must be signed in to change notification settings - Fork 389
chore: add mypy to the build #689
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
Conversation
f32d0ea
to
77f9e61
Compare
Codecov ReportBase: 94.59% // Head: 94.67% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #689 +/- ##
==========================================
+ Coverage 94.59% 94.67% +0.08%
==========================================
Files 57 57
Lines 8339 8339
==========================================
+ Hits 7888 7895 +7
+ Misses 451 444 -7
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
7ca072b
to
c6bc1b4
Compare
Haven't looked at the content of the PR, but conceptually I have no issues with it. Will review later today. |
Thanks a lot for the PR! When it comes to introducing typings to a new repo, I've seen 2 orthogonal approaches, which is either rule by rule, or module by module. In the past I've found success with the later approach, as it defines the target a bit more thoroughly and it also creates what I like to call a "ball of coherency", where we can (mostly) trust the interactions between the typed modules. In theory I wouldn't be against this approach either, but having relatively lax rules might result in us publishing types that aren't accurate. |
That sounds good to me. I was looking around at how some other projects are doing it -- it looks like SQLAlchemy is adding a type ignore to the top of each file, then slowly removing it as they go. I just updated this PR to use that method. |
If we want to go with the file-by-file approach, then we need to make the mypy requirements stricter. I've pulled the broken bit out of #684 so it should be ready to review. This utilizes the configuration that mypy offers to configure which files are checked or not. I think I like the approach this PR offers for ignoring the files, as it is very visible when editing the file, whereas the mypy configuration is a bit farther away. Would you be open to get the rule list from #684? After that we can merge this and then rebase #684 and also unlock the ability to parallelize the type checking between multiple contributors. |
0fa4176
to
0d5842e
Compare
I just switched it to use the centralized mypy config method. However, I ended up inverting the list of files to ignore so the config file will shrink in size over time (rather than grow to include all files in the repo).
I just went through the mypy config line-by-line (based on the mypy docs) and made it as strict as possible (with the exception of Regarding ignores for external packages, for example:
We should probably depend on using |
Do you have a strong opinion pro having the separate |
mypy.ini
Outdated
# For details on each flag, please see the mypy documentation at: | ||
# https://mypy.readthedocs.io/en/stable/config_file.html#config-file | ||
|
||
# Note: The order of flags listed here should match the order used in mypy's | ||
# documentation to make it easier to find the documentation for each flag. |
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.
I like this. Thanks for adding the reference link. Always takes me 5 min or so to find the reference 😛
Thanks guys for working on this, I am not closely following the implementation details, but at a high-level I'm 👍 👍 ! |
217fa9a
to
cd2ebac
Compare
No strong preference at all -- I just updated the PR to have the config in the |
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.
LGTM. Thanks a lot and sorry for the back and forth :)
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 looks very reasonable to me, but I haven't been working professionally in Python the last few years, so haven't kept up with the idiomatic type tooling recommendations... so before we merge, I'd like to get @ofek's input, as I'm pretty sure he's stayed abreast of such things. I pinged him for a quick review, and assuming he's 👍 then we should merge.
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.
Looks good to me!
Thanks again @bringhurst 🎉 |
Why is this needed?
This is intended to be a lightweight version of #684. Rather than add types to everything in one shot, support for typing could be added to the build only. Python code typing could be incrementally added in future smaller/targeted PRs.
The changes in #684 are still useful. This is just an effort to split it up to make it easier to understand.
The method used here follows the same pattern that SQLAlchemy has been using to add types. For an example, see https://github.com/sqlalchemy/sqlalchemy/pull/9039/files and note the removal of the
# mypy: ignore-errors
comment to incrementally add types.Proposed Changes
Does this PR introduce any breaking change?
No. This PR will only contain build-time type checking.