Type hint can define the return type in Python, so when a function returns namedtuple type, then how to define it?
def bar(func):
def decorator(*args, **kwargs):
return namedtuple('data', 'name user')(**func(*args, **kwargs))
return update_wrapper(decorator, func)
@bar
def info() -> NamedTuple:
return {'name': 'a1', 'user': 'b1'}
Expected type 'NamedTuple', got Dict[str,str] instead
As you know, the function info()
returns Dict[str, str]
, but the decorator @bar
changes it. Now the function info()
returns a namedtuple object, so is there a way to indicate that the function info()
returns a namedtupe object by type hint?