Skip to content

Commit fe24088

Browse files
authored
Add more tests. Fix code excerpt. (pythonGH-25549)
1 parent 702a088 commit fe24088

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

@@ -1364,9 +1378,10 @@ Using the non-data descriptor protocol, a pure Python version of
13641378
"A doc for 'T'"
13651379

13661380

1367-
The code path for ``hasattr(obj, '__get__')`` was added in Python 3.9 and
1368-
makes it possible for :func:`classmethod` to support chained decorators.
1369-
For example, a classmethod and property could be chained together:
1381+
The code path for ``hasattr(type(self.f), '__get__')`` was added in
1382+
Python 3.9 and makes it possible for :func:`classmethod` to support
1383+
chained decorators. For example, a classmethod and property could be
1384+
chained together:
13701385

13711386
.. testcode::
13721387

0 commit comments

Comments
 (0)