Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to typehint the return type of decorated functions? #288

Closed
HMaker opened this issue Aug 27, 2020 · 2 comments
Closed

How to typehint the return type of decorated functions? #288

HMaker opened this issue Aug 27, 2020 · 2 comments

Comments

@HMaker
Copy link

HMaker commented Aug 27, 2020

It seems Pylance is unable to infer the return type of decorated functions, I tried

import typing

ReturnType = typing.TypeVar('ReturnType')
def my_parametrized_decorator(my_parameter):
    def decorator(decorated_func: typing.Callable[..., typing.Awaitable[ReturnType]]):
        async def wrapper(*args, **kwargs):
            return await decorated_func(*args, **kwargs)
        return wrapper
    return decorator

@my_parametrized_decorator('foo')
async def foo() -> typing.List[str]:
    return ['foo', 'bar']

I expected Pylance to show the return type of foo is List[str] but it shows ReturnType

@erictraut
Copy link
Contributor

Please refer to this issue: microsoft/pyright#774

@HMaker
Copy link
Author

HMaker commented Aug 27, 2020

It worked, thanks.

@HMaker HMaker closed this as completed Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants