Repository navigation
Support the limited API? #183
Description
Activity
- added 2 commits that reference this issue
on Oct 4, 2026 I wrote #184 to add support for the limited C API.
- added a commit that references this issue
on Oct 5, 2026 It's now implemented in the main branch.
@ngoldbaum: I just merged Py_SETREF()/Py_XSETREF() into Python 3.16: python/cpython@ec14f81. Do you expect that pythoncapi-compat provides new limited C API functions to older Python versions? It sounds somehow to go against limited C API, no? I expect Py_SETREF()/Py_XSETREF() to be only available in Python 3.16 limited C API, even if pythoncapi-compat. Well, I'm not sure. What do you think?
It sounds someone to go against limited C API, no?
I think it goes with the intention of this repo, which allows people to adopt idioms that are added in future Python versions. It's a bad idea to use those idioms if it hasn't been added in a future version but once it has, it makes sense to use internal details to implement backward compatibility shims.
Of course that may be difficult in practice for most things in the limited API because it will require new ABI surface. In this case, though, we can provide a shim. So I would say why not allow that?
Without support here, NumPy would add a shim somewhere internally in NumPy that only NumPy uses and may be buggy. IMO it's better to centralize compat shims here as much as possible.
Reacted by Pratham Hole@ngoldbaum: Hum. Supporting the limited C API on old Python versions is tricky to get it right, because of the stable ABI. I suggest to work on a case by case basis to add new limited C API to old Python versions. Py_SETREF() / Py_XSETREF() is special since it doesn't call (new) Python functions in its implementation, but only
memcpy()which comes from the C library. So for these two macros, I think that it's safe to add them to old Python versions.I created #187 to add Py_SETREF/Py_XSETREF to old limited C API versions.
Three years ago, I created https://github.com/vstinner/deadparrot experimental project: a shared library providing old and new Python C API functions to support all Python versions. But I didn't go far, and no one adopted it. The pythoncapi-compat "header file" approach seems to fit well developers needs and it's convenient to use (just include the header file, you're done).
Reacted by Pratham Hole
pythoncapi-compat/tests/test_pythoncapi_compat_cext.c
Lines 11 to 13 in ba68139
I'm curious if there's any interest in adding support here. I'd particularly like to avoid adding extensive shims to NumPy to work around issues like in numpy/numpy#32864.