ex 7.4
This commit is contained in:
parent
fc5fc23c5d
commit
26d175ba93
@ -39,3 +39,8 @@ class Structure:
|
|||||||
locs = {}
|
locs = {}
|
||||||
exec(code, locs)
|
exec(code, locs)
|
||||||
cls.__init__ = locs['__init__']
|
cls.__init__ = locs['__init__']
|
||||||
|
|
||||||
|
|
||||||
|
def typed_structure(clsname, **validators):
|
||||||
|
cls = type(clsname, (Structure,), validators)
|
||||||
|
return cls
|
||||||
|
|||||||
16
validate.py
16
validate.py
@ -27,16 +27,14 @@ class Typed(Validator):
|
|||||||
return super().check(value)
|
return super().check(value)
|
||||||
|
|
||||||
|
|
||||||
class Integer(Typed):
|
_typed_classes = [
|
||||||
expected_type = int
|
('Integer', 'int'),
|
||||||
|
('Float', 'float'),
|
||||||
|
('String', 'str'),
|
||||||
|
]
|
||||||
|
|
||||||
|
globals().update((name, type(name, (Typed,), {'expected_type': ty}))
|
||||||
class Float(Typed):
|
for name, ty in _typed_classes)
|
||||||
expected_type = float
|
|
||||||
|
|
||||||
|
|
||||||
class String(Typed):
|
|
||||||
expected_type = str
|
|
||||||
|
|
||||||
|
|
||||||
class Positive(Validator):
|
class Positive(Validator):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user