v1.2.6
Changed the return type of validate
from None
to Literal[True]
, so that validation calls can be gated behind assertions and compiled away in optimised scenarios:
from typing_validation import validate
assert validate(val, t) # this is compiled away with -O or -OO
Introduced a variant is_valid
of validate
which returns a bool
:
from typing_validation import is_valid
if is_valid(val, t):
... # do stuff
else:
... # handle error
In case of validation failure, failure information is made available using latest_validation_failure
:
from typing_validation import is_valid, latest_validation_failure
if is_valid(val, t):
... # do stuff
else:
cause = latest_validation_failure()
... # handle error