diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-11-27 00:52:39 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-27 00:52:39 -0800 |
| commit | cd27d22ac90a869dc740004597246f24246348a6 (patch) | |
| tree | d6939c0c549226f10e01804fbf44a4efb4ddf0ae | |
| parent | 2fb971940b18bcf5a58b1b242b697d0f1d8ad7ef (diff) | |
| download | cpython-git-cd27d22ac90a869dc740004597246f24246348a6.tar.gz | |
bpo-38524: document implicit and explicit calling of descriptors' __set_name__ (GH-17364)
(cherry picked from commit 1bddf890e595a865414645c6041733043c4081f8)
Co-authored-by: Florian Dahlitz <f2dahlitz@freenet.de>
| -rw-r--r-- | Doc/reference/datamodel.rst | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 835db9224c..7a99e1e522 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1641,8 +1641,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 |
