Skip to content

Conversation

@nicholasjng
Copy link
Contributor

PyObject_DelAttr{,String} are part of the stable ABI starting only from Python 3.13. Thus, when building extensions targeting the stable ABI for Python 3.12, we should fall back to the earlier PyObject_SetAttr{,String}(obj, key, NULL) pattern.


This should fix the abi3audit failures I observed in nicholasjng/nanobind-bazel#83.

The implementation idea is based on the second paragraph of the https://docs.python.org/3/c-api/object.html#c.PyObject_SetAttrString doc.

src/common.cpp Outdated
}

void delattr(PyObject *obj, const char *key) {
#if (defined(Py_LIMITED_API) && PY_LIMITED_API < 0x030D0000)
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think we need the parens around the preprocessor expression (and this pattern generally isn't used in the codebase)

Copy link
Contributor Author

@nicholasjng nicholasjng Nov 24, 2025

Choose a reason for hiding this comment

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

Ah, sorry about that. I copied this directly from another such statement in the same file, so it's at least used that way in src/common.cpp.

(EDIT: I copied part of a ternary statement, that's my bad. Fixed in the latest revision.)

…n 3.12 SABI builds

`PyObject_DelAttr{,String}` are part of the stable ABI starting only from Python 3.13.
Thus, when building extensions targeting the stable ABI for Python 3.12, we should fall
back to the earlier `PyObject_SetAttr{,String}(obj, key, NULL)` pattern.
@wjakob wjakob merged commit dbe8a3c into wjakob:master Nov 24, 2025
31 checks passed
@wjakob
Copy link
Owner

wjakob commented Nov 24, 2025

Thanks!

@nicholasjng nicholasjng deleted the stable-abi-fixes-312 branch November 24, 2025 16:22
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.

2 participants