1def type_check(in_or_out):
2 def types(*expected_types):
3 def decorator(func):
4 def wrapper(*args, **kwargs):
5 if in_or_out == "in":
6 for arg in args:
7 if not any(type(arg) == expected_type for expected_type in expected_types):
8 expected_type_str = ", ".join(str(expected_type) for expected_type in expected_types)
9 print(f"Invalid input arguments, expected {expected_type_str}!")
10 break
11 result = func(*args, **kwargs)
12 if in_or_out == "out":
13 if not any(type(result) == expected_type for expected_type in expected_types):
14 expected_type_str = ", ".join(str(expected_type) for expected_type in expected_types)
15 print(f"Invalid output value, expected {expected_type_str}!")
16
17 return result
18
19 return wrapper
20
21 return decorator
22
23 return types
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK