From: Jakub Stasiak Date: Wed, 6 Oct 2021 18:23:02 +0000 (+0200) Subject: [doc] Mention __slots__ behavior in weakref.rst (GH-21061) X-Git-Tag: v3.11.0a2~292 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b24b47e64355224c1bf4e46ed7c4d9f7df4e6f09;p=thirdparty%2FPython%2Fcpython.git [doc] Mention __slots__ behavior in weakref.rst (GH-21061) 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 --- diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst index 5a8df4c27dc3..1102c634edaf 100644 --- a/Doc/library/weakref.rst +++ b/Doc/library/weakref.rst @@ -88,6 +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`. +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])