Skip to content

Commit 7111d70

Browse files
committed
Test: Simple example
1 parent 936533c commit 7111d70

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Doc/howto/descriptor.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,26 @@ Simple example: A descriptor that returns a constant
4343
----------------------------------------------------
4444

4545
The :class:`Ten` class is a descriptor that always returns the constant ``10``
46-
from its :meth:`__get__` method::
46+
from its :meth:`__get__` method:
4747

48+
.. testcode::
4849

4950
class Ten:
5051
def __get__(self, obj, objtype=None):
5152
return 10
5253

53-
To use the descriptor, it must be stored as a class variable in another class::
54+
To use the descriptor, it must be stored as a class variable in another class:
55+
56+
.. testcode::
5457

5558
class A:
5659
x = 5 # Regular class attribute
5760
y = Ten() # Descriptor instance
5861

5962
An interactive session shows the difference between normal attribute lookup
60-
and descriptor lookup::
63+
and descriptor lookup:
64+
65+
.. doctest::
6166

6267
>>> a = A() # Make an instance of class A
6368
>>> a.x # Normal attribute lookup

0 commit comments

Comments
 (0)