Pin the numpy C API level - #42
Merged
Merged
Conversation
Without NPY_NO_DEPRECATED_API the extension compiles against whatever numpy currently exposes, including APIs numpy has already deprecated, so a future removal surfaces as a broken build or a broken wheel at the worst possible moment. Setting it makes that a compile error here, on our schedule. The code turns out not to use any deprecated API: the build is clean with the guard in place, no new warnings, and the suite passes against the resulting wheel. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Pins the extension to NumPy’s non-deprecated C API baseline to catch deprecated usage during compilation.
Changes:
- Defines
NPY_NO_DEPRECATED_APIat the NumPy 1.7 API level. - Applies the macro to all extension translation units.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds
NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSIONto the extension'sdefine_macros.Without it the extension compiles against whatever numpy currently exposes, including APIs numpy has already deprecated. That means a future numpy removing one of them shows up as a broken build — or a broken wheel — at whatever moment numpy happens to release. With the guard, using a deprecated API becomes a compile error here, on our schedule rather than theirs.
Result
This was the change most likely to fail outright, since enabling the guard surfaces any deprecated usage as an error. It doesn't: the code uses no deprecated numpy API.
The define is visibly applied to both translation units:
and the build produces no new warnings or errors — including from the Cython-generated C, which is the part most likely to reach for older numpy APIs.
NPY_1_7_API_VERSIONis the level numpy documents for this purpose; it is the floor the code is held to, not a cap on the numpy version, and builds continue to use numpy 2 headers as before.Verification
🤖 Generated with Claude Code