8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4fedd71 commit 85c8492Copy full SHA for 85c8492
Doc/howto/descriptor.rst
@@ -170,7 +170,15 @@ the lookup or update:
170
171
172
An interactive session shows that all access to the managed attribute *age* is
173
-logged, but that the regular attribute *name* is not logged::
+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::
182
183
>>> mary = Person('Mary M', 30) # The initial age update is logged
184
INFO:root:Updating 'age' to 30
@@ -256,7 +264,15 @@ we call :func:`vars` to look up the descriptor without triggering it:
256
264
>>> vars(vars(Person)['age'])
257
265
{'public_name': 'age', 'private_name': '_age'}
258
266
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
270
271
272
273
274
275
260
276
261
277
>>> pete = Person('Peter P', 10)
262
278
INFO:root:Updating 'name' to 'Peter P'
@@ -433,7 +449,9 @@ Here's how the data validators can be used in a real class:
433
449
self.kind = kind
434
450
self.quantity = quantity
435
451
436
-The descriptors prevent invalid instances from being created::
452
+The descriptors prevent invalid instances from being created:
453
454
437
455
438
456
>>> Component('Widget', 'metal', 5) # Blocked: 'Widget' is not all uppercase
439
457
Traceback (most recent call last):
@@ -1227,7 +1245,10 @@ Now a new dictionary of unique keys can be constructed like this:
1227
1245
1228
1246
.. doctest::
1229
1247
1230
- >>> Dict.fromkeys('abracadabra')
1248
+ >>> d = Dict.fromkeys('abracadabra')
1249
+ >>> type(d) is Dict
1250
+ True
1251
+ >>> d
1231
1252
{'a': None, 'b': None, 'r': None, 'c': None, 'd': None}
1232
1253
1233
1254
Using the non-data descriptor protocol, a pure Python version of