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