Skip to content

v1.2.6

Compare
Choose a tag to compare
@sg495 sg495 released this 30 Jan 10:47
· 28 commits to main since this release

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