From 55bd28fa6f05669a78a4f8de25dede3c20867c0b Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Tue, 23 Jun 2020 02:07:45 +0200 Subject: [PATCH 1/2] Mention __slots__ in weakref documentation It took me longer than I expected to figure out why a random class I dealt with didn't support weak references. I believe this addition will make the __slots__/weakref interaction more discoverable to people having troubles with this. (Before this patch __slots__ was not mentioned in weakref documentation even once). --- Doc/library/weakref.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index d3c3a070f38af0a..92bc44ebbf69992 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -88,6 +88,9 @@ support weak references but can add support through subclassing:: Extension types can easily be made to support weak references; see :ref:`weakref-support`. +``__slots__`` existence in a type (and the contents) affects whether that type +supports weak references. See :ref:`__slots__ documentation ` for details. + .. class:: ref(object[, callback]) From 62c04b18f60b517475ae489aa9585743caa07851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Wed, 6 Oct 2021 20:01:09 +0200 Subject: [PATCH 2/2] Rephrase to be more explicit --- Doc/library/weakref.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 92bc44ebbf69992..bdf3c55e9c49508 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -88,9 +88,10 @@ support weak references but can add support through subclassing:: Extension types can easily be made to support weak references; see :ref:`weakref-support`. -``__slots__`` existence in a type (and the contents) affects whether that type -supports weak references. See :ref:`__slots__ documentation ` for details. - +When ``__slots__`` are defined for a given type, weak reference support is +disabled unless a ``'__weakref__'`` string is also present in the sequence of +strings in the ``__slots__`` declaration. +See :ref:`__slots__ documentation ` for details. .. class:: ref(object[, callback])