Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def wrapper(*args, **kwargs):
memo = _CallMemo(python_func, _localns, args=args, kwargs=kwargs)
check_argument_types(memo)
retval = func(*args, **kwargs)
check_return_type(retval, memo)
# If a generator is returned, wrap it if its yield/send/return types can be checked
if inspect.isgenerator(retval) or isasyncgen(retval):
return_type = memo.type_hints.get('return')
if return_type:
origin = getattr(return_type, '__origin__', None)
if origin in generator_origin_types:
return TypeCheckedGenerator(retval, memo)
elif origin is not None and origin in asyncgen_origin_types:
return TypeCheckedAsyncGenerator(retval, memo)
return retval