Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Implement opaque PyObject ABI support #31091

Merged
ngoldbaum merged 30 commits into
numpy:mainfrom
kumaraditya303:opaque
May 6, 2026
Merged

ENH: Implement opaque PyObject ABI support #31091
ngoldbaum merged 30 commits into
numpy:mainfrom
kumaraditya303:opaque

Conversation

@kumaraditya303
Copy link
Copy Markdown
Contributor

@kumaraditya303 kumaraditya303 commented Mar 29, 2026

PR summary

This PR adds support for building opaque PyObject stable ABI extensions using NumPy.

AI Disclosure

Claude was used to generate the tests.

@kumaraditya303 kumaraditya303 changed the title Implement opaque PyObject ABI support ENH: Implement opaque PyObject ABI support Mar 29, 2026
@ngoldbaum
Copy link
Copy Markdown
Member

Sorry for adding and removing the milestone repeatedly. I know we talked about this yesterday at the meeting, but it occurs to me that maybe it's reasonable for NumPy 2.5 to support Python 3.15, e.g. by uploading wheels to PyPI? If so, it would be logical to include this as well.

NumPy 2.5 is scheduled to be released this summer, after the ABI for Python 3.15 is frozen, so it should be perfectly fine to build and upload NumPy wheels using a CPython beta.

I know that has implications for the release workflow, so ping @rgommers.

@charris
Copy link
Copy Markdown
Member

charris commented Apr 9, 2026

We don't upload wheels to PyPI for new Python releases until the rc release and cibuildwheel support for it.

EDIT: it is fine to build the wheels, just not to upload them. For instance, we build wheels for pyodide, but we don't upload them.

Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

I asked Claude to review this PR. I unfortunately don't have the mental patience to actually read this whole diff in one sitting.

It spotted a couple subtle issues in the iterator macros on the opaque pyobject build. Up to you, but I think it might be worth adding tests for the C iterator APIs under the opaque pyobject builds given the complexity of these macros.

But maybe also check for open-source uses first by searching github for items in the C API to see if it's worth doing.

Comment thread numpy/_core/include/numpy/ndarraytypes.h Outdated
Comment thread numpy/_core/include/numpy/ndarraytypes.h Outdated
Comment thread numpy/_core/code_generators/numpy_api.py Outdated
Comment thread numpy/__init__.cython-30.pxd Outdated
@rgommers
Copy link
Copy Markdown
Member

rgommers commented Apr 9, 2026

NumPy 2.5 is scheduled to be released this summer, after the ABI for Python 3.15 is frozen, so it should be perfectly fine to build and upload NumPy wheels using a CPython beta.

What Chuck said - only after 3.15.0rc1. There's nothing in this PR that requires this though, and there's no problem merging this PR and having support in the headers in 2.5.0.

Copy link
Copy Markdown
Member

@seberg seberg left a comment

Choose a reason for hiding this comment

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

Didn't scan too closely for bugs, but I think Nathan got them (and honestly, I am not all that worried because all of these look like they should be compile time errors downstream and then even a minor release can fix them when they come up -- doesn't mean it isn't better to do it now :)).

Overall, the diff seems much more churn than it actually is, IMO, so this should be fast to wrap up.

Comment thread numpy/_core/code_generators/numpy_api.py Outdated
Comment thread numpy/_core/code_generators/numpy_api.py
Comment thread numpy/_core/include/numpy/ndarraytypes.h Outdated
Comment thread numpy/_core/include/numpy/ndarraytypes.h
Comment thread numpy/_core/include/numpy/numpyconfig.h Outdated
@kumaraditya303 kumaraditya303 marked this pull request as ready for review April 11, 2026 09:28
Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

I asked Claude to give it another once-over and spotted a couple more issues.

I also tried building this branch against Pandas and saw compilation errors. We'll need to fix those before this can be merged.

Comment thread numpy/__init__.cython-30.pxd Outdated
Comment thread numpy/__init__.cython-30.pxd Outdated
Comment thread numpy/_core/code_generators/generate_numpy_api.py
Comment thread numpy/_core/include/numpy/arrayscalars.h Outdated
Comment thread numpy/_core/include/numpy/numpyconfig.h Outdated
@ngoldbaum ngoldbaum added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Apr 16, 2026
@ngoldbaum
Copy link
Copy Markdown
Member

I added needs-release-note because it's a new feature so we should at least describe it in the release notes.

We have zero narrative docs about how to use the NumPy C API with the Python limited API. I'm going to open a new issue tracking that and we can describe abi3t builds there.

@kumaraditya303 kumaraditya303 added 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) labels Apr 16, 2026
Copy link
Copy Markdown
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

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

I’m planning to merge this next week, let me know if anyone else wants a chance to review.

Comment thread numpy/_core/src/multiarray/arrayobject.c
@ngoldbaum
Copy link
Copy Markdown
Member

3.15b1 is coming soon and I'd like to enable downstream testing of this, so I'm going to merge this.

@ngoldbaum ngoldbaum merged commit 15a344d into numpy:main May 6, 2026
86 checks passed
MaanasArora pushed a commit to MaanasArora/numpy that referenced this pull request May 7, 2026
@charris
Copy link
Copy Markdown
Member

charris commented May 8, 2026

test_limited_opaque is causing test failures.

@ngoldbaum
Copy link
Copy Markdown
Member

Sorry for the overly hasty merge. It probably needs to be updated for 3.15.0b1, feel free to merge a commit disabling the test and either me or Kumar will send in a fix soon.

@kumaraditya303
Copy link
Copy Markdown
Contributor Author

Created #31403 for fixing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

01 - Enhancement 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants