Skip to content

Commit 2324bb4

Browse files
DahlitzFlorianshihai1991
authored andcommitted
bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (pythonGH-17364)
1 parent 2f780d8 commit 2324bb4

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
@@ -1655,8 +1655,19 @@ class' :attr:`~object.__dict__`.
16551655
Called at the time the owning class *owner* is created. The
16561656
descriptor has been assigned to *name*.
16571657

1658-
.. versionadded:: 3.6
1658+
.. note::
1659+
1660+
``__set_name__`` is only called implicitly as part of the ``type`` constructor, so
1661+
it will need to be called explicitly with the appropriate parameters when a
1662+
descriptor is added to a class after initial creation::
16591663

1664+
descr = custom_descriptor()
1665+
cls.attr = descr
1666+
descr.__set_name__(cls, 'attr')
1667+
1668+
See :ref:`class-object-creation` for more details.
1669+
1670+
.. versionadded:: 3.6
16601671

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

0 commit comments

Comments
 (0)