dynamic attributes, descriptors and first concurrency examples
This commit is contained in:
@@ -9,7 +9,7 @@ class AutoStorage: # <1>
|
||||
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):
|
||||
@@ -34,6 +34,7 @@ class Validated(abc.ABC, AutoStorage): # <3>
|
||||
|
||||
|
||||
class Quantity(Validated): # <7>
|
||||
"""a number greater than zero"""
|
||||
|
||||
def validate(self, instance, value):
|
||||
if value <= 0:
|
||||
@@ -42,6 +43,7 @@ class Quantity(Validated): # <7>
|
||||
|
||||
|
||||
class NonBlank(Validated):
|
||||
"""a string with at least one non-space character"""
|
||||
|
||||
def validate(self, instance, value):
|
||||
value = value.strip()
|
||||
|
||||
Reference in New Issue
Block a user