Skip to content

Commit 9b0dad5

Browse files
committed
fix autodetect dynamic attrs in 3.11
1 parent dfa1a22 commit 9b0dad5

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

include/pybind11/attr.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,10 @@ struct type_record {
345345

346346
bases.append((PyObject *) base_info->type);
347347

348-
if (base_info->type->tp_dictoffset != 0) {
349-
dynamic_attr = true;
350-
}
348+
dynamic_attr |= base_info->type->tp_dictoffset != 0;
349+
#if PY_VERSION_HEX >= 0x030B0000
350+
dynamic_attr |= (base_info->type->tp_flags & Py_TPFLAGS_MANAGED_DICT) != 0;
351+
#endif
351352

352353
if (caster) {
353354
base_info->implicit_casts.emplace_back(type, caster);

tests/test_multiple_inheritance.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ TEST_SUBMODULE(multiple_inheritance, m) {
230230
struct VanillaDictMix1 : Vanilla, WithDict {};
231231
struct VanillaDictMix2 : WithDict, Vanilla {};
232232
py::class_<WithDict>(m, "WithDict", py::dynamic_attr()).def(py::init<>());
233-
py::class_<VanillaDictMix1, Vanilla, WithDict>(m, "VanillaDictMix1", py::dynamic_attr())
234-
.def(py::init<>());
235-
py::class_<VanillaDictMix2, WithDict, Vanilla>(m, "VanillaDictMix2", py::dynamic_attr())
236-
.def(py::init<>());
233+
py::class_<VanillaDictMix1, Vanilla, WithDict>(m, "VanillaDictMix1").def(py::init<>());
234+
py::class_<VanillaDictMix2, WithDict, Vanilla>(m, "VanillaDictMix2").def(py::init<>());
237235

238236
// test_diamond_inheritance
239237
// Issue #959: segfault when constructing diamond inheritance instance

0 commit comments

Comments
 (0)