Skip to content

bpo-38524: add note about the implicit and explicit calling of __set_name__ #17364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down