File tree 1 file changed +8
-3
lines changed 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -43,21 +43,26 @@ Simple example: A descriptor that returns a constant
43
43
----------------------------------------------------
44
44
45
45
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:
47
47
48
+ .. testcode ::
48
49
49
50
class Ten:
50
51
def __get__(self, obj, objtype=None):
51
52
return 10
52
53
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 ::
54
57
55
58
class A:
56
59
x = 5 # Regular class attribute
57
60
y = Ten() # Descriptor instance
58
61
59
62
An interactive session shows the difference between normal attribute lookup
60
- and descriptor lookup::
63
+ and descriptor lookup:
64
+
65
+ .. doctest ::
61
66
62
67
>>> a = A() # Make an instance of class A
63
68
>>> a.x # Normal attribute lookup
You can’t perform that action at this time.
0 commit comments