Skip to content

Commit 6741b67

Browse files
committed
fix: Python-3.12 compatibility
Enable dynamic attributes for `pybind11_static_property`
1 parent 68e6fda commit 6741b67

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

include/pybind11/detail/class.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ extern "C" inline int pybind11_static_set(PyObject *self, PyObject *obj, PyObjec
5555
return PyProperty_Type.tp_descr_set(self, cls, value);
5656
}
5757

58+
// Forward declaration to use in `make_static_property_type()`
59+
inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type);
60+
5861
/** A `static_property` is the same as a `property` but the `__get__()` and `__set__()`
5962
methods are modified to always use the object type instead of a concrete instance.
6063
Return value: New reference. */
@@ -86,7 +89,11 @@ inline PyTypeObject *make_static_property_type() {
8689
if (PyType_Ready(type) < 0) {
8790
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
8891
}
89-
92+
# if PY_VERSION_HEX >= 0x030C0000
93+
// Since Python-3.12 property-derived types are required to
94+
// have dynamic attributes (to set `__doc__`)
95+
enable_dynamic_attributes(heap_type);
96+
# endif
9097
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
9198
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
9299

0 commit comments

Comments
 (0)