summaryrefslogtreecommitdiffstats
path: root/Doc/howto
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-04-23 03:26:56 (GMT)
committerGitHub <noreply@github.com>2021-04-23 03:26:56 (GMT)
commit8db72cd342917e68a42edcc41b25c58ac33ca928 (patch)
tree9bcb401a7d8d8df9123032927bea6593cd1c8820 /Doc/howto
parent34be48450f03b121be10a9f8e8989603478f0469 (diff)
downloadcpython-8db72cd342917e68a42edcc41b25c58ac33ca928.zip
cpython-8db72cd342917e68a42edcc41b25c58ac33ca928.tar.gz
cpython-8db72cd342917e68a42edcc41b25c58ac33ca928.tar.bz2
Add more tests. Fix code excerpt. (GH-25549) (GH-25550)
Diffstat (limited to 'Doc/howto')
-rw-r--r--Doc/howto/descriptor.rst21
1 files changed, 18 insertions, 3 deletions
diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst
index eef6b2d..9f0dd2f 100644
--- a/Doc/howto/descriptor.rst
+++ b/Doc/howto/descriptor.rst
@@ -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:
@@ -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::