<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h
index 1044db94..89d418cc 100644
--- a/include/pybind11/attr.h
+++ b/include/pybind11/attr.h
@@ -351,7 +351,8 @@ struct type_record {
 
         bases.append((PyObject *) base_info-&gt;type);
 
-#if PY_VERSION_HEX &lt; 0x030B0000
+// Keep in sync with enable_dynamic_attributes() in detail/class.h
+#if PY_VERSION_HEX &lt; 0x030B0000 || defined(PYPY_VERSION)
         dynamic_attr |= base_info-&gt;type-&gt;tp_dictoffset != 0;
 #else
         dynamic_attr |= (base_info-&gt;type-&gt;tp_flags &amp; Py_TPFLAGS_MANAGED_DICT) != 0;
diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h
index b990507d..e97d48b2 100644
--- a/include/pybind11/detail/class.h
+++ b/include/pybind11/detail/class.h
@@ -560,9 +560,9 @@ extern "C" inline int pybind11_clear(PyObject *self) {
 inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
     auto *type = &amp;heap_type-&gt;ht_type;
     type-&gt;tp_flags |= Py_TPFLAGS_HAVE_GC;
-#if PY_VERSION_HEX &lt; 0x030B0000
-    type-&gt;tp_dictoffset = type-&gt;tp_basicsize;           // place dict at the end
-    type-&gt;tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it
+#if PY_VERSION_HEX &lt; 0x030B0000 || defined(PYPY_VERSION) // For PyPy see PR #5508
+    type-&gt;tp_dictoffset = type-&gt;tp_basicsize;            // place dict at the end
+    type-&gt;tp_basicsize += (ssize_t) sizeof(PyObject *);  // and allocate enough space for it
 #else
     type-&gt;tp_flags |= Py_TPFLAGS_MANAGED_DICT;
 #endif
</pre></body></html>