Conversation
|
Python 3.12 is more strict with string syntax; previous versions were happy with something like |
Codecov Report❌ 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. 🚀 New features to boost your workflow:
|
|
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 |
| if value.lower() == "first": | ||
| dmx = getattr(model, f"DMX_{index1:04d}").quantity | ||
| elif value.lower == "second": | ||
| elif value.lower() == "second": |
If we do want to apply static typing to PINT (#1709 ), a possible goal is for the static type checker
mypyto successfully check the entire code base.mypyis 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 appropriatemypysetup; in particular it requires ignoring a lot of errors. As long as these are ignored,mypyisn't doing a particularly strict job, but this is a starting point for gradual typing.Next steps:
mypyworking on the whole codebase and running in CI, but with sufficiently permissive settings that it passes. This PR does this.mypychecking, fixing that part of the codebase so it passes. This PR does this for everything butpint.observatory.mypyis checking, making suremypycontinues to pass. This would be an incremental process going forward.mypyexceptions/error suppression.There are choices about what the target for
mypychecking 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
mypyin CI as this PR does it now is to encourage contributors to follow these rules:mypyfails.ignore_statements (except un-typed third-party packages).ignore_statements).ignore_rule and then make that module passmypy.mypystill passes.mypystill 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.