Skip to content

Commit 74fce09

Browse files
committed
Avoid use of PyObject_DelAttr and PyObject_DelAttrString in Python 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.
1 parent acd6a3e commit 74fce09

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/common.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,23 @@ void setattr(PyObject *obj, PyObject *key, PyObject *value) {
451451
}
452452

453453
void delattr(PyObject *obj, const char *key) {
454+
#if defined(Py_LIMITED_API) && PY_LIMITED_API < 0x030D0000
455+
int rv = PyObject_SetAttrString(obj, key, nullptr);
456+
#else
454457
int rv = PyObject_DelAttrString(obj, key);
458+
#endif
459+
455460
if (rv)
456461
raise_python_error();
457462
}
458463

459464
void delattr(PyObject *obj, PyObject *key) {
465+
#if defined(Py_LIMITED_API) && PY_LIMITED_API < 0x030D0000
466+
int rv = PyObject_SetAttr(obj, key, nullptr);
467+
#else
460468
int rv = PyObject_DelAttr(obj, key);
469+
#endif
470+
461471
if (rv)
462472
raise_python_error();
463473
}

0 commit comments

Comments
 (0)