TYP: bootstrap type checking with mypy #2438
Open
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.
This is a best effort attempt to lay a fundation to type-annotations in h5py (#1912).
Namely, my goal is to get
mypy h5py
running without errors on a simple configuration.I'm not claiming all annotations are perfect. In some cases I left them out entirely and merely declared existence of constants/functions/methods. In others, I just added empty
.pyi
files so mypy wouldn't complain about missing modules (which are really binary blobs).Some notes
eliminate errors that mypy runs into with a simple configuration (like "module x has no attribute y")
int
as a "good-enough" proxy annotation for many different C types (no distinction ismade between signed and unsigned, or bit sizes)
bool
as a proxy forbint
*char
(but maybestr
would be fitted in that role)A follow up would be making sure that it type-checks against the oldest supported Python too, which in general means downgrading to more complicated syntax.Just in case we'd drop 3.8 soon, I'm not attempting that right now. Whatever the target, it is doable, it's just more work the further in the past I need to reach. In particular, the difference between 3.8 and 3.9 is important enough that I'd like to get feedback before going down that hole.
update: turns out supporting type checking for Python 3.8 too is actually very easy with stub files, so it's done.