Skip to content

Ship a PEP 561 py.typed marker - #1761

Merged
rajeeja merged 7 commits into
mainfrom
rajeeja/py-typed
Oct 16, 2026
Merged

rajeeja merged 7 commits into
mainfrom
rajeeja/py-typed

Conversation

@rajeeja

@rajeeja rajeeja commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1760

Overview

Adds the PEP 561 py.typed marker so type checkers are permitted to use the annotations uxarray already ships.

Without the marker, mypy and pyright treat every uxarray import as Any and discard all existing annotations, and --strict users get an error on import uxarray itself. Grid.n_face is 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.typed to a wheel on its own (_IMPLICIT_DATA_FILES in setuptools/command/build_py.py), but [build-system] requires here is setuptools>=60: on 68.2.2 the marker is dropped from the wheel unless [tool.setuptools.package-data] declares it. MANIFEST.in line 4 is recursive-include uxarray *.py, so the explicit include covers the sdist. Both can be dropped if the setuptools floor is ever raised past 69.

Changes

  • uxarray/py.typed — new, empty
  • pyproject.toml — [tool.setuptools.package-data]
  • MANIFEST.in — include uxarray/py.typed
  • test/test_dependencies.py — assert the marker is present in the installed package

Verification

Built the wheel and sdist from this branch:

  • py.typed present in both
  • installed the wheel non-editable into a clean venv, confirmed the marker lands in site-packages
  • deleted the marker from that install and confirmed the test fails, so it is not a tautology
  • bisected setuptools: implicit py.typed starts at 69.0 (absent in 61/62/64/68.1/68.2). On 68.2.2, building without package-data drops the marker and building with it keeps it

The 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 test from the root, which prepends the CWD to sys.path and 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_dataset and open_mfdataset. So ux.open_grid("mesh.nc") still infers as Any and a downstream grid.n_face + "x" still goes uncaught. Annotating those constructors is the natural next step, and annotating open_grid first requires a decision about return_chunks, which is undocumented, untested, and used by exactly one private caller. Worth doing separately.

PR Checklist

General

  • An issue is created and linked
  • Added appropriate labels (if your uxarray repo permissions allow it)
  • Filled out Overview and Expected Usage (if applicable) sections

Testing

  • Tests added
  • [N/A] Benchmarks added

Documentation

  • [N/A] Docstrings on new functions
  • [N/A] Examples added

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.
Comment thread test/test_dependencies.py Resolved
Comment thread pyproject.toml Resolved
…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.
@rajeeja

rajeeja commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Updated with latest main and pushed d2937b9 for both comments.

@cmdupuis3 you were right on both counts:

  1. python -m pytest path — worse than it looked: CI does pip install . --no-deps and python -m pytest test from the root, so the test was reading the source tree and could never have caught a packaging regression. Now a subprocess with cwd=tmp_path, matching the existing helper in that file.
  2. "setuptools ships only .py files" — wrong, and the comment is corrected. setuptools >= 69.0 adds py.typed implicitly. But our floor is setuptools>=60, and I verified on 68.2.2 that the marker is dropped without the package-data entry, so it stays — with accurate reasoning this time.

Open question for you on that second one: I can instead raise the floor to setuptools>=69 and delete both the package-data entry and the MANIFEST.in line. Fewer knobs, at the cost of a stricter build requirement. Happy either way — say which you prefer and I will make it so.

Verified against a real wheel built from this branch: marker present, installs into a clean venv, and the test fails if I delete it.

@rajeeja
rajeeja requested a review from cmdupuis3 October 5, 2026 18:04
@rajeeja
rajeeja requested a review from Sevans711 October 16, 2026 17:45

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!"

@rajeeja
rajeeja merged commit 6126f0d into main Oct 16, 2026
22 checks passed
@erogluorhan
erogluorhan deleted the rajeeja/py-typed branch November 13, 2026 23:43
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.

Ship a PEP 561 py.typed marker

3 participants