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

TYP: bootstrap type checking with mypy #2438

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

neutrinoceros
Copy link
Contributor

@neutrinoceros neutrinoceros commented Jun 1, 2024

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

  • this is a bottom-up approach: instead of focusing on documenting public APIs, I'm just trying to
    eliminate errors that mypy runs into with a simple configuration (like "module x has no attribute y")
  • I'm using int as a "good-enough" proxy annotation for many different C types (no distinction is
    made between signed and unsigned, or bit sizes)
  • I'm using bool as a proxy for bint
  • I'm not trying to use any proxy for *char (but maybe str would be fitted in that role)
  • As a first step, I only tried to satisfy mypy assuming Python 3.12 or newer.
    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.

Copy link

codecov bot commented Jun 1, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.54%. Comparing base (fdd36ac) to head (24df973).
Report is 4 commits behind head on master.

Files Patch % Lines
h5py/_hl/files.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2438   +/-   ##
=======================================
  Coverage   89.54%   89.54%           
=======================================
  Files          16       16           
  Lines        2381     2382    +1     
=======================================
+ Hits         2132     2133    +1     
  Misses        249      249           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@neutrinoceros neutrinoceros force-pushed the typ/base_stubs branch 2 times, most recently from 6861642 to f7f2d8c Compare June 1, 2024 16:59
@neutrinoceros neutrinoceros marked this pull request as ready for review June 1, 2024 17:12
@neutrinoceros neutrinoceros changed the title TYP: bootstrap typechecking with mypy + Python 3.12 TYP: bootstrap type checking with mypy Jun 1, 2024
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.

1 participant