dynamic attributes, descriptors and first concurrency examples

This commit is contained in:
Luciano Ramalho
2015-01-17 22:40:40 -02:00
parent 0618105a47
commit dd1a53ff71
27 changed files with 1151 additions and 216 deletions

View File

@@ -29,11 +29,11 @@ instance::
>>> raisins = LineItem('Golden raisins', 10, 6.95)
>>> dir(raisins) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
['_Quantity_0', '_Quantity_1', '__class__', ...
['_Quantity:0', '_Quantity:1', '__class__', ...
'description', 'price', 'subtotal', 'weight']
>>> raisins._Quantity_0
>>> getattr(raisins, '_Quantity:0')
10
>>> raisins._Quantity_1
>>> getattr(raisins, '_Quantity:1')
6.95
If the descriptor is accessed in the class, the descriptor object is
@@ -56,7 +56,7 @@ class Quantity:
cls = self.__class__
prefix = cls.__name__
index = cls.__counter
self.storage_name = '_{}_{}'.format(prefix, index)
self.storage_name = '_{}:{}'.format(prefix, index)
cls.__counter += 1
def __get__(self, instance, owner):