Skip to content

Commit cd27d22

Browse files
bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH-17364)
(cherry picked from commit 1bddf89) Co-authored-by: Florian Dahlitz <[email protected]>
1 parent 2fb9719 commit cd27d22

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Doc/reference/datamodel.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,19 @@ class' :attr:`~object.__dict__`.
16411641
Called at the time the owning class *owner* is created. The
16421642
descriptor has been assigned to *name*.
16431643

1644-
.. versionadded:: 3.6
1644+
.. note::
1645+
1646+
``__set_name__`` is only called implicitly as part of the ``type`` constructor, so
1647+
it will need to be called explicitly with the appropriate parameters when a
1648+
descriptor is added to a class after initial creation::
16451649

1650+
descr = custom_descriptor()
1651+
cls.attr = descr
1652+
descr.__set_name__(cls, 'attr')
1653+
1654+
See :ref:`class-object-creation` for more details.
1655+
1656+
.. versionadded:: 3.6
16461657

16471658
The attribute :attr:`__objclass__` is interpreted by the :mod:`inspect` module
16481659
as specifying the class where this object was defined (setting this

0 commit comments

Comments
 (0)