Last active
March 10, 2022 22:23
-
-
Save lewoudar/a5e0ff8b00856073e86f0d0e5740e60e to your computer and use it in GitHub Desktop.
A second example of pydantic argument validation using validate_arguments decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
from pydantic import validate_arguments, ValidationError, Field | |
@validate_arguments | |
def get_hypotenuse( | |
a: float = Field(..., gt=0), | |
b: float = Field(..., gt=0) | |
) -> float: | |
return math.sqrt(a ** 2 + b ** 2) | |
try: | |
print(get_hypotenuse(1, 3)) | |
except ValidationError as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment