Closed geokala closed 5 months ago
Actually UUID
qualifies as a type.
>>> type(UUID)
<class 'type'>
>>> type('62aba560-bc73-49c9-b629-ae2a5bf14f17')
<class 'str'>
>>> Schema(UUID).validate(UUID('62aba560-bc73-49c9-b629-ae2a5bf14f17'))
UUID('62aba560-bc73-49c9-b629-ae2a5bf14f17')
So you should refer to type
section of the documentation
You might use the following:
>>> from uuid import UUID
>>> from schema import Schema, And, Use
>>> Schema(And(Use(UUID), UUID)).validate('62aba560-bc73-49c9-b629-ae2a5bf14f17')
UUID('62aba560-bc73-49c9-b629-ae2a5bf14f17')
OK, makes sense- it might be worth updating the callable section of the documentation to refer to that, but thanks for the clarification!
The documentation on pypi states:
If Schema(...) encounters a callable (function, class, or object with __call__ method) it will call it, and if its return value evaluates to True it will continue validating, else—it will raise SchemaError.
However, this is not the behaviour seen when using, e.g. UUID: `>>> from uuid import UUID
This is in python3.11, with schema==0.7.5