aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Dahlitz <f2dahlitz@freenet.de>2019-11-27 09:46:40 +0100
committerTal Einat <taleinat+github@gmail.com>2019-11-27 10:46:40 +0200
commit1bddf890e595a865414645c6041733043c4081f8 (patch)
tree1e05724e605c8dd7b75984d243f082a3a2c25040 /Doc/reference
parentShow the differing module names for readlink() (GH-17395) (diff)
downloadcpython-1bddf890e595a865414645c6041733043c4081f8.tar.gz
cpython-1bddf890e595a865414645c6041733043c4081f8.tar.bz2
cpython-1bddf890e595a865414645c6041733043c4081f8.zip
bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH-17364)
Diffstat (limited to 'Doc/reference')
-rw-r--r--Doc/reference/datamodel.rst13
1 files changed, 12 insertions, 1 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 76b7035ced9..68098508afb 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -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