@@ -170,7 +170,15 @@ the lookup or update:
170170
171171
172172An interactive session shows that all access to the managed attribute *age * is
173- logged, but that the regular attribute *name * is not logged::
173+ logged, but that the regular attribute *name * is not logged:
174+
175+ .. testcode ::
176+ :hide:
177+
178+ import logging, sys
179+ logging.basicConfig(level=logging.INFO, stream=sys.stdout, force=True)
180+
181+ .. doctest ::
174182
175183 >>> mary = Person(' Mary M' , 30 ) # The initial age update is logged
176184 INFO:root:Updating 'age' to 30
@@ -256,7 +264,15 @@ we call :func:`vars` to look up the descriptor without triggering it:
256264 >>> vars (vars (Person)[' age' ])
257265 {'public_name': 'age', 'private_name': '_age'}
258266
259- The new class now logs access to both *name * and *age *::
267+ The new class now logs access to both *name * and *age *:
268+
269+ .. testcode ::
270+ :hide:
271+
272+ import logging, sys
273+ logging.basicConfig(level=logging.INFO, stream=sys.stdout, force=True)
274+
275+ .. doctest ::
260276
261277 >>> pete = Person(' Peter P' , 10 )
262278 INFO:root:Updating 'name' to 'Peter P'
@@ -433,7 +449,9 @@ Here's how the data validators can be used in a real class:
433449 self.kind = kind
434450 self.quantity = quantity
435451
436- The descriptors prevent invalid instances from being created::
452+ The descriptors prevent invalid instances from being created:
453+
454+ .. doctest ::
437455
438456 >>> Component(' Widget' , ' metal' , 5 ) # Blocked: 'Widget' is not all uppercase
439457 Traceback (most recent call last):
@@ -1227,7 +1245,10 @@ Now a new dictionary of unique keys can be constructed like this:
12271245
12281246.. doctest ::
12291247
1230- >>> Dict.fromkeys(' abracadabra' )
1248+ >>> d = Dict.fromkeys(' abracadabra' )
1249+ >>> type (d) is Dict
1250+ True
1251+ >>> d
12311252 {'a': None, 'b': None, 'r': None, 'c': None, 'd': None}
12321253
12331254Using the non-data descriptor protocol, a pure Python version of
0 commit comments