-
Notifications
You must be signed in to change notification settings - Fork 101
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
mypy checking as part of CI #1725
base: master
Are you sure you want to change the base?
Conversation
Python 3.12 is more strict with string syntax; previous versions were happy with something like |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1725 +/- ##
==========================================
+ Coverage 69.06% 69.23% +0.17%
==========================================
Files 105 105
Lines 24703 24729 +26
Branches 4410 4410
==========================================
+ Hits 17061 17121 +60
+ Misses 6534 6499 -35
- Partials 1108 1109 +1 ☔ View full report in Codecov by Sentry. |
It's probably instructive to look at the changes I had to make to get
So, not too difficult a battle, but there are some things that are okay that mypy doesn't like. [edited to add: a lot of the broken commits here are me trying to get CI set up properly] |
Adding typed, documented instance variable declarations helps the docs (adds a Variables section): https://nanograv-pint--1725.org.readthedocs.build/en/1725/_autosummary/pint.fitter.Fitter.html#pint-fitter-fitter |
|
I'd actually say this is ready to go: if we want to start working on static typing for pint, I'd say apply #1718 and then this one; we can then start adding annotations and removing |
Curses. Astropy's type annotations pre-6.0 clash with mypy's, and oldestdeps doesn't use astropy 6.0. I'll have to back out the changes to |
Didn't have to back them out entirely, just separate the actual units into |
There is no way to specify return types/units that makes both |
@@ -1197,22 +1225,21 @@ def merge_dmx(model, index1, index2, value="mean", frozen=True): | |||
) | |||
if value.lower() == "first": | |||
dmx = getattr(model, f"DMX_{index1:04d}").quantity | |||
elif value.lower == "second": | |||
elif value.lower() == "second": |
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.
Bug found!
If we do want to apply static typing to PINT (#1709 ), a possible goal is for the static type checker
mypy
to successfully check the entire code base.mypy
is designed for gradual typing, and in fact there is a guide to applying mypy to an existing codebase. A key first step is to enable mypy as part of CI. Of course, this requires an appropriatemypy
setup; in particular it requires ignoring a lot of errors. As long as these are ignored,mypy
isn't doing a particularly strict job, but this is a starting point for gradual typing.Next steps:
mypy
working on the whole codebase and running in CI, but with sufficiently permissive settings that it passes. This PR does this.mypy
checking, fixing that part of the codebase so it passes. This PR does this for everything butpint.observatory
.mypy
is checking, making suremypy
continues to pass. This would be an incremental process going forward.mypy
exceptions/error suppression.There are choices about what the target for
mypy
checking should be - how strict we should attempt to eventually be. There are also choices about how best to approach these targets. There is room for a lot of discussion, but this PR is intended to establish the most basic setup to begin the process.There is a discussion about how astropy should handle typing: astropy/astropy#15170
There is also an analogue to this PR: astropy/astropy#15794
Summary of the optional rules as enabled by this PR:
These are certainly up for discussion, but they seem reasonable to me.
The idea of putting
mypy
in CI as this PR does it now is to encourage contributors to follow these rules:mypy
fails.ignore_
statements (except un-typed third-party packages).ignore_
statements).ignore_
rule and then make that module passmypy
.mypy
still passes.mypy
still passes.The goal isn't necessarily that everything has static types, just that they become the norm where they help.
I should also say that your editor can probably run
mypy
(or one of its mostly equivalent alternatives) as an on-the-fly linter and get angry underlines everywhere the code won't passmypy
. Your editor may also offer "inlay hints" showing the inferred types of various things, and allow you to fill those types in by double-clicking if you want to.