Skip to content

Commit 8524b20

Browse files
authored
fix: Python-3.12 compatibility (#4168)
* fix: Python-3.12 compatibility Enable dynamic attributes for `pybind11_static_property` * Add future-notice comment
1 parent 64f7281 commit 8524b20

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

include/pybind11/detail/class.h

Lines changed: 10 additions & 0 deletions
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. */
@@ -87,6 +90,13 @@ inline PyTypeObject *make_static_property_type() {
8790
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
8891
}
8992

93+
# if PY_VERSION_HEX >= 0x030C0000
94+
// PRE 3.12 FEATURE FREEZE. PLEASE REVIEW AFTER FREEZE.
95+
// Since Python-3.12 property-derived types are required to
96+
// have dynamic attributes (to set `__doc__`)
97+
enable_dynamic_attributes(heap_type);
98+
# endif
99+
90100
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
91101
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
92102

0 commit comments

Comments
 (0)