Skip to content

Commit 4f161e6

Browse files
[doc] Mention __slots__ behavior in weakref.rst (GH-21061) (GH-28773)
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). Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit b24b47e) Co-authored-by: Jakub Stasiak <[email protected]>
1 parent 92018a0 commit 4f161e6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Doc/library/weakref.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ support weak references but can add support through subclassing::
8888
Extension types can easily be made to support weak references; see
8989
:ref:`weakref-support`.
9090

91+
When ``__slots__`` are defined for a given type, weak reference support is
92+
disabled unless a ``'__weakref__'`` string is also present in the sequence of
93+
strings in the ``__slots__`` declaration.
94+
See :ref:`__slots__ documentation <slots>` for details.
9195

9296
.. class:: ref(object[, callback])
9397

0 commit comments

Comments
 (0)