ex 7.4
This commit is contained in:
parent
fc5fc23c5d
commit
26d175ba93
@ -39,3 +39,8 @@ class Structure:
|
||||
locs = {}
|
||||
exec(code, locs)
|
||||
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)
|
||||
|
||||
|
||||
class Integer(Typed):
|
||||
expected_type = int
|
||||
_typed_classes = [
|
||||
('Integer', 'int'),
|
||||
('Float', 'float'),
|
||||
('String', 'str'),
|
||||
]
|
||||
|
||||
|
||||
class Float(Typed):
|
||||
expected_type = float
|
||||
|
||||
|
||||
class String(Typed):
|
||||
expected_type = str
|
||||
globals().update((name, type(name, (Typed,), {'expected_type': ty}))
|
||||
for name, ty in _typed_classes)
|
||||
|
||||
|
||||
class Positive(Validator):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user