1def type_check(method):
2 def checker(*expected_types):
3 def decorator(func):
4 def wrapper(*args, **kwargs):
5 if method == 'in':
6 invalid_args = [arg for arg in args if not isinstance(arg, expected_types)]
7 if invalid_args:
8 expected_types_str = ", ".join([str(t) for t in expected_types])
9 print(f"Invalid input arguments, expected {expected_types_str}!")
10
11 result = func(*args, **kwargs)
12 if method == 'out' and not isinstance(result, expected_types):
13 expected_types_str = ", ".join([str(t) for t in expected_types])
14 print(f"Invalid output value, expected {expected_types_str}!")
15 return result
16 return wrapper
17 return decorator
18 return checker
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK