Add stubtest to CI for type annotation validation#11124
Add stubtest to CI for type annotation validation#11124kkollsga wants to merge 1 commit intopydata:mainfrom
Conversation
08ca82f to
11bab2c
Compare
|
Hi @kkollsga , I'm curious about this issue so am happy to dig into this PR a bit - but before I do that I would like to know to what extent AI has been used on this PR. It seems like a heavy PR and from a glance (on mobile) I dont see the connections to the original work done in Scipy. An AI disclosure statement would be really helpful for me to know how its been used 😊 (Note I am not a maintainer, and Xarray - AFAICT - doesn't have LLM disclosure as a contributing policy. This is a request from myself) |
|
This PR was developed with assistance from Claude Code. AI usage is disclosed via the The original issue references stubtest tooling from NumPy's fellowship work, with a cross-reference to #10273 (scipy-stubs compliance). The allowlist was built specifically for xarray's patterns by iteratively running stubtest on core modules. This PR also cleans up some obsolete type ignores that scipy-stubs made redundant, partially addressing #10273. The categorized allowlist (TYPE_CHECKING imports, dynamic methods, protocol differences) is designed to be maintainable as xarray evolves. |
51e903b to
c36e571
Compare
|
Earlier iterations ran into issues with pixi lock validation when modifying The fix was to keep this PR as pure infrastructure with no source changes, and rebuild the allowlist from scratch using efficient grouped regex patterns. This brought it down to 170 lines with 0 stubtest errors and 0 unused patterns. Future work: Expand coverage to additional modules (backends, computation, indexes), then transition from |
70abc7a to
04105e0
Compare
Add stubtest to CI for validating type stubs against runtime behavior. This helps catch type annotation regressions early. - Add stubtest job to ci-additional.yaml (non-blocking with continue-on-error) - Create allowlist for known acceptable differences (TYPE_CHECKING imports, etc.) - Tests core modules: dataarray, dataset, variable Refs pydata#11086 Co-Authored-By: Claude <noreply@anthropic.com>
04105e0 to
293b7e2
Compare
whats-new.rstapi.rst(N/A - no new public API)Summary
This PR integrates mypy's stubtest tool into xarray's CI pipeline to validate that type annotations match runtime behavior.
What's included
CI Integration:
stubtestjob in.github/workflows/ci-additional.yamlcontinue-on-error: true(Phase 1: informational)dataarray,dataset,variableInfrastructure:
_stubtest/allowlist.txt- Comprehensive allowlist for TYPE_CHECKING imports and intentional stub/runtime differences_stubtest/run_stubtest.py- Runner script with reportingci_tests/- Pytest-based tests for stubtest compliance and type regressionsCode cleanup:
# type: ignorecomments revealed byscipy-stubsandpandas-stubsPhased rollout
The stubtest job is currently non-blocking (
continue-on-error: true). Once maintainers are confident it's stable, it can be made required by changing tocontinue-on-error: false.Verification
Stubtest errors reduced from 1,084 → 0 with the allowlist.