1def type_check(label):
2 def check_for_valid_type(*valid_types):
3 def decorator(func):
4 def wrapper(*args, **kwargs):
5 arg_list = args + tuple(kwargs.values())
6 if label == "in":
7 for arg in arg_list:
8 if not isinstance(arg, valid_types):
9 print(f"Invalid input arguments, expected {', '.join(str(v) for v in valid_types)}!")
10 break
11
12 result = func(*args, **kwargs)
13 if label == "out":
14 if not isinstance(result, valid_types):
15 print(f"Invalid output value, expected {', '.join(str(v) for v in valid_types)}!")
16 return result
17 return wrapper
18 return decorator
19 return check_for_valid_type
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK