[Python-checkins] [doc] Mention __slots__ behavior in weakref.rst (GH-21061) (GH-28773)

ambv webhook-mailer at python.org
Wed Oct 6 14:52:53 EDT 2021


https://github.com/python/cpython/commit/4f161e65a011f287227c944fad9987446644041f
commit: 4f161e65a011f287227c944fad9987446644041f
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-10-06T20:52:48+02:00
summary:

[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 <lukasz at langa.pl>
(cherry picked from commit b24b47e64355224c1bf4e46ed7c4d9f7df4e6f09)

Co-authored-by: Jakub Stasiak <jakub at stasiak.at>

files:
M Doc/library/weakref.rst

diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst
index b88543e445372..4b0945c020f84 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 <slots>` for details.
 
 .. class:: ref(object[, callback])
 



More information about the Python-checkins mailing list