1def type_check(verification_mode):
2 def decorator(*argument_types):
3 def wrapper(function):
4 def validator(*args, **kwargs):
5 if verification_mode == "in":
6 invalid_input = False
7 for arg in args:
8 if not isinstance(arg, argument_types):
9 invalid_input = True
10 break
11 if invalid_input:
12 print("Invalid input arguments, expected {}!".format(', '.join(map(str, argument_types))))
13
14 result = function(*args, **kwargs)
15
16 if verification_mode == "out":
17 if not isinstance(result, argument_types):
18 print("Invalid output value, expected {}!".format(', '.join(map(str, argument_types))))
19
20 return result
21 return validator
22 return wrapper
23 return decorator
....
----------------------------------------------------------------------
Ran 4 tests in 0.002s
OK