Skip to content

Commit

Permalink
fix: Python-3.11 compatibility
Browse files Browse the repository at this point in the history
Enable dynamic attributes for `pybind11_static_property`
  • Loading branch information
sizmailov committed Aug 31, 2022
1 parent 68e6fda commit b7cfbcc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/pybind11/detail/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ extern "C" inline int pybind11_static_set(PyObject *self, PyObject *obj, PyObjec
return PyProperty_Type.tp_descr_set(self, cls, value);
}

// Forward declaration to use in `make_static_property_type()`
inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type);

/** A `static_property` is the same as a `property` but the `__get__()` and `__set__()`
methods are modified to always use the object type instead of a concrete instance.
Return value: New reference. */
Expand Down Expand Up @@ -86,7 +89,11 @@ inline PyTypeObject *make_static_property_type() {
if (PyType_Ready(type) < 0) {
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
}

# if PY_VERSION_HEX >= 0x03110000
// Since Python-3.11 property-derived types are required to
// have dynamic attributes (to set `__doc__`)
enable_dynamic_attributes(heap_type);
# endif
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);

Expand Down

0 comments on commit b7cfbcc

Please sign in to comment.