https://github.com/python/cpython/commit/974a7f70b33eb980ec820b42948bfa777b9de07c
commit: 974a7f70b33eb980ec820b42948bfa777b9de07c
branch: main
author: Serhiy Storchaka <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2026-10-31T17:21:32+05:30
summary:
gh-135385: do not reserve inline values for attributes stored in slots (#156656)
files:
A
Misc/NEWS.d/next/Core_and_Builtins/2026-08-30-16-30-00.gh-issue-135385.Wn7Rd4.rst
M Objects/dictobject.c
diff --git
a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-30-16-30-00.gh-issue-135385.Wn7Rd4.rst
b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-30-16-30-00.gh-issue-135385.Wn7Rd4.rst
new file mode 100644
index 000000000000000..43b72921fe9e45c
--- /dev/null
+++
b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-30-16-30-00.gh-issue-135385.Wn7Rd4.rst
@@ -0,0 +1,3 @@
+Reduce the memory consumption of instances of classes which define
+``__slots__`` and also have a ``__dict__``. Space for the attributes stored
+in slots is no longer reserved in the inline values of every instance.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 9d06afbca8066ca..fa6fd6b27ef8794 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -7305,6 +7305,11 @@ _PyDict_NewKeysForClass(PyHeapTypeObject *cls)
PyObject *key = PyTuple_GET_ITEM(attrs, i);
Py_hash_t hash;
if (PyUnicode_CheckExact(key) && (hash =
unicode_get_hash(key)) != -1) {
+ /* An attribute stored in a slot never uses the dict. */
+ PyObject *descr = _PyType_Lookup((PyTypeObject *)cls, key);
+ if (descr != NULL && Py_IS_TYPE(descr,
&PyMemberDescr_Type)) {
+ continue;
+ }
if (insert_split_key(keys, key, hash) == DKIX_EMPTY) {
break;
}
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]