1def type_check(direction):
2 """Perform type checks on input arguments and return values."""
3 def inner_type_check(*types):
4 def decorator(func):
5 def wrapper(*args, **kwargs):
6 if direction == "in":
7 all_arguments = args + tuple(kwargs.values())
8 for argument in all_arguments:
9 if type(argument) not in types:
10 print(
11 f"Invalid input arguments, expected "
12 f"{', '.join(map(str, types))}!"
13 )
14 break
15
16 output = func(*args, **kwargs)
17
18 if direction == "out" and type(output) not in types:
19 print(
20 f"Invalid output value, expected "
21 f"{', '.join(map(str, types))}!"
22 )
23
24 return output
25 return wrapper
26 return decorator
27 return inner_type_check
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK