]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH...
authorFlorian Dahlitz <f2dahlitz@freenet.de>
Wed, 27 Nov 2019 08:46:40 +0000 (09:46 +0100)
committerTal Einat <taleinat+github@gmail.com>
Wed, 27 Nov 2019 08:46:40 +0000 (10:46 +0200)
Doc/reference/datamodel.rst

index 76b7035ced9794466a048bf53dc24b373cdc9865..68098508afbaa28cfed55bc57e9b2241892e12a3 100644 (file)
@@ -1655,8 +1655,19 @@ class' :attr:`~object.__dict__`.
    Called at the time the owning class *owner* is created. The
    descriptor has been assigned to *name*.
 
-   .. versionadded:: 3.6
+   .. note::
+
+      ``__set_name__`` is only called implicitly as part of the ``type`` constructor, so
+      it will need to be called explicitly with the appropriate parameters when a
+      descriptor is added to a class after initial creation::
 
+         descr = custom_descriptor()
+         cls.attr = descr
+         descr.__set_name__(cls, 'attr')
+
+      See :ref:`class-object-creation` for more details.
+
+   .. versionadded:: 3.6
 
 The attribute :attr:`__objclass__` is interpreted by the :mod:`inspect` module
 as specifying the class where this object was defined (setting this