Repository navigation
Ship a PEP 561 py.typed marker - #1761
Conversation
uxarray annotates its public API, but without a py.typed marker type checkers discard every one of those annotations and --strict users get an error on `import uxarray`. MANIFEST.in globs only *.py, so the marker needs explicit package-data config to reach the wheel. Verified by building the wheel and sdist: py.typed is present in both, and the wheel gains exactly one file over the released 2026.9.0.
…eck out-of-tree setuptools >= 69.0 adds py.typed to a wheel on its own via _IMPLICIT_DATA_FILES, so the original comment claiming setuptools ships only .py files was wrong. Verified on 68.2.2 the marker is dropped without the package-data entry and kept with it, so the entry is still needed for the declared setuptools >= 60 floor; comment now says that. The test imported uxarray in-process. CI runs 'python -m pytest test' from the repo root, which prepends CWD to sys.path and imports the source tree, where the marker always exists, so a packaging regression could not fail the test. It now imports in a subprocess with cwd set elsewhere, matching the existing pattern in this file.
|
Updated with latest @cmdupuis3 you were right on both counts:
Open question for you on that second one: I can instead raise the floor to Verified against a real wheel built from this branch: marker present, installs into a clean venv, and the test fails if I delete it. |
Sevans711
left a comment
There was a problem hiding this comment.
These changes look pretty reasonable to me, at least from what I was able to gather from the conversation here, plus some back-and-forth with Claude.
The one note I would add is, if you can emphasize this in the release notes, that could be helpful for any users using type-checkers, maybe something like: "type-checkers will now start trying to utilize uxarray's type annotations, which are still a work in progress and may be inaccurate. If you see type-checkers raising errors on code that works correctly, please open a corresponding issue!"
Closes #1760
Overview
Adds the PEP 561
py.typedmarker so type checkers are permitted to use the annotations uxarray already ships.Without the marker, mypy and pyright treat every uxarray import as
Anyand discard all existing annotations, and--strictusers get an error onimport uxarrayitself.Grid.n_faceis declared-> int(uxarray/grid/grid.py:897) and that annotation does nothing for a user today — the mechanism that would consume it is simply absent. xarray, numpy and dask all ship the marker.Two config changes are needed rather than one. setuptools >= 69.0 adds
py.typedto a wheel on its own (_IMPLICIT_DATA_FILESinsetuptools/command/build_py.py), but[build-system] requireshere issetuptools>=60: on 68.2.2 the marker is dropped from the wheel unless[tool.setuptools.package-data]declares it.MANIFEST.inline 4 isrecursive-include uxarray *.py, so the explicitincludecovers the sdist. Both can be dropped if the setuptools floor is ever raised past 69.Changes
uxarray/py.typed— new, emptypyproject.toml—[tool.setuptools.package-data]MANIFEST.in—include uxarray/py.typedtest/test_dependencies.py— assert the marker is present in the installed packageVerification
Built the wheel and sdist from this branch:
py.typedpresent in bothpy.typedstarts at 69.0 (absent in 61/62/64/68.1/68.2). On 68.2.2, building withoutpackage-datadrops the marker and building with it keeps itThe test asserts against the installed package rather than the source tree, and does so in a subprocess run from outside the repo: CI uses
python -m pytest testfrom the root, which prepends the CWD tosys.pathand would otherwise import the source tree, where the marker always exists.Follow-up (not in this PR)
The marker is a promise, and coverage is currently thin: 213/798 functions have return annotations, and 227 public functions have none — including
open_grid,open_datasetandopen_mfdataset. Soux.open_grid("mesh.nc")still infers asAnyand a downstreamgrid.n_face + "x"still goes uncaught. Annotating those constructors is the natural next step, and annotatingopen_gridfirst requires a decision aboutreturn_chunks, which is undocumented, untested, and used by exactly one private caller. Worth doing separately.PR Checklist
General
Testing
Documentation