mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 14:50:19 +00:00
8bad7bc911
* feat: add `validate` method on function to validate input without calling it * docs: add documentation * chore: add change file
18 lines
296 B
Python
18 lines
296 B
Python
from pydantic import validate_arguments, ValidationError
|
|
|
|
|
|
@validate_arguments
|
|
def slow_sum(a: int, b: int) -> int:
|
|
print(f'Called with a={a}, b={b}')
|
|
return a + b
|
|
|
|
|
|
slow_sum(1, 1)
|
|
|
|
slow_sum.validate(2, 2)
|
|
|
|
try:
|
|
slow_sum.validate(1, 'b')
|
|
except ValidationError as exc:
|
|
print(exc)
|