File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 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
4343----------------------------------------------------
4444
4545The :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
5962An 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
You can’t perform that action at this time.
0 commit comments