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

Function return type is not being preserved when using @wrapt.decorator #233

Open
ICE-FlatLine opened this issue Mar 19, 2023 · 0 comments

Comments

@ICE-FlatLine
Copy link

ICE-FlatLine commented Mar 19, 2023

Hi,
I am using the following function as a decorator for other functions with the help of wrapt.decorator:

@wrapt.decorator
async def log_function_execution(func, instance, args, kwargs):
    """
    Wrapping CYSDKLogger log writing at the beginning & ending of function
    """
    CYSDKLogger().logger.info(f'Start {func.__name__}')
    result = await func(*args, **kwargs)
    CYSDKLogger().logger.info(f'Finish {func.__name__}')
    return result

Basically, it logs start and finish of the inner function execution.
Using it as a simple decorator:

@log_function_execution
async def acquire_by_conf(self, machine_conf: MACHINE_CONF, keep_alive: bool = False,
                          local_execution: Union[None, bool] = None) -> MobileDevice:

However,
when calling for the acquire_by_conf() method, IDE (Pycharm) throws this warning:
image

Seems like instead of MobileDevice return type, type checker expects Coroutine[Any, Any, MobileDevice] (Not sure if this is indeed the issue).
Is there a way to preserve return type of the decorated function for the type checker?

P.S. By removing the decorator from the method, warning from IDE disappears.
I am using python 3.7.15

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

1 participant