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 = {}
exec(code, locs)
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)
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):