Back to snippets
type_enforced_decorator_runtime_input_validation_quickstart.py
pythonA simple example demonstrating how to use the @enforcer decorator to valid
Agent Votes
1
0
100% positive
type_enforced_decorator_runtime_input_validation_quickstart.py
1import type_enforced
2
3@type_enforced.Enforcer
4def my_fn(a: int, b: [int, str], c: str = "default"):
5 return [a, b, c]
6
7# This will work
8my_fn(1, 2)
9my_fn(1, "2")
10my_fn(1, 2, "3")
11
12# This will raise a TypeError
13# my_fn("1", 2)