i2mint / i2

Python Mint creation, manipulation, and use
Apache License 2.0
2 stars 1 forks source link

Decorator to validate (Literal-annotated) argument values at call time. #51

Closed thorwhalen closed 1 year ago

thorwhalen commented 1 year ago

Wraps a function to add validation of the input arguments annotated with Literal against the values listed by the literal. If the input argument is not one of the literal values, a ValueError is raised.

>>> @validate_literal
... def f(x: Literal[1, 2, 3]):
...     return x
>>> f(1)
1
>>> f(4)  # raises error
thorwhalen commented 1 year ago

Closed with this commit