Asgiref's sync_to_async and Pycharm - fix incorrect type warning by Pycharm

Viewed 166

It seems that Pycharm doesn't really grok sync_to_async. For example, in the following code:

@sync_to_async
def get_point(...) -> Point:
    ...

def other_func():
    point = await get_point()

I get the warning Class 'Point' does not define '__await__' so the 'await' operator cannot be used on its instance.

What's the simplest way to add a correct type definition for sync_to_async? (Which is preferable to just ignoring the error)

1 Answers

This is apparently easily solved by upgrading asgiref to the latest 3.4.1 from 3.3.1 that it was before.

Related