This commit is contained in:
Mike Bloy 2024-01-07 16:31:19 -06:00
parent fc5fc23c5d
commit 26d175ba93
2 changed files with 12 additions and 9 deletions

View File

@ -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

View File

@ -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):