Create a decorator
expected_type() that checks if what the decorated function returns is of expected type. An
UnexpectedTypeException should be raised if the type returned by the decorated function doesn’t match the ones expected.
expected_type()should accept a tuple of many types that may be valid
UnexpectedTypeExceptionshould be raised if decorated function returns object of type that wasn’t defined in
expected_type()'s arguments (you have to implement that class)
return_somethingwill be decorated with
expected_typein the tests and will look exactly like in the example below
#the decorator creation def expected_type(*msg): def wrapper(return_something): for items in msg: x = return_something() if items == type(x): print("hello function is of the type expected") else: print("Type Unexpected Error") break return wrapper @expected_type('str','dict','set','list') def return_something(): return ('hello everyone') # calling the function print(return_something)
The Error l am getting is:
Type Unexpected Error
I am expecting the code to print hello function is of the type expected but it is not working, how can l correct it?