Skip to content

Commit 8db72cd

Browse files
Add more tests. Fix code excerpt. (GH-25549) (GH-25550)
1 parent 34be484 commit 8db72cd

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Doc/howto/descriptor.rst

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,20 @@ The documentation shows a typical use to define a managed attribute ``x``:
953953
def delx(self): del self.__x
954954
x = property(getx, setx, delx, "I'm the 'x' property.")
955955

956+
.. doctest::
957+
:hide:
958+
959+
>>> C.x.__doc__
960+
"I'm the 'x' property."
961+
>>> c.x = 2.71828
962+
>>> c.x
963+
2.71828
964+
>>> del c.x
965+
>>> c.x
966+
Traceback (most recent call last):
967+
...
968+
AttributeError: 'C' object has no attribute '_C__x'
969+
956970
To see how :func:`property` is implemented in terms of the descriptor protocol,
957971
here is a pure Python equivalent:
958972

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

13561370

1357-
The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
1358-
makes it possible for :func:`classmethod` to support chained decorators.
1359-
For example, a classmethod and property could be chained together:
1371+
The code path for ``hasattr(type(self.f), '__get__')`` was added in
1372+
Python 3.9 and makes it possible for :func:`classmethod` to support
1373+
chained decorators. For example, a classmethod and property could be
1374+
chained together:
13601375

13611376
.. testcode::
13621377

0 commit comments

Comments
 (0)