I am going to write a function decorator that takes an argument and returns a decorator that can be used to control the type of the argument to a one-argument function. I expect a raising error happens in case the passed argument be in a wrong type.
def typecontrol(num_type):
def wrapper_function(num):
if isinstance(num, num_type):
return num
else:
raise TypeError
return wrapper_function
@typecontrol(float)
def myfunc(num):
print(num)
I expect for example, myfunc(9.123)
should print 9.123 and myfunc(9)
should raise an error. But it always raises type error.