Skip to content

[3.9] Add more tests. Fix code excerpt. (GH-25549) #25550

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 1 commit into from
Apr 23, 2021
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
21 changes: 18 additions & 3 deletions Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,20 @@ The documentation shows a typical use to define a managed attribute ``x``:
def delx(self): del self.__x
x = property(getx, setx, delx, "I'm the 'x' property.")

.. doctest::
:hide:

>>> C.x.__doc__
"I'm the 'x' property."
>>> c.x = 2.71828
>>> c.x
2.71828
>>> del c.x
>>> c.x
Traceback (most recent call last):
...
AttributeError: 'C' object has no attribute '_C__x'

To see how :func:`property` is implemented in terms of the descriptor protocol,
here is a pure Python equivalent:

Expand Down Expand Up @@ -1354,9 +1368,10 @@ Using the non-data descriptor protocol, a pure Python version of
"A doc for 'T'"


The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
makes it possible for :func:`classmethod` to support chained decorators.
For example, a classmethod and property could be chained together:
The code path for ``hasattr(type(self.f), '__get__')`` was added in
Python 3.9 and makes it possible for :func:`classmethod` to support
chained decorators. For example, a classmethod and property could be
chained together:

.. testcode::

Expand Down