Asgiref 的 sync_to_async 和 Pycharm - 修复了 Pycharm 的错误类型警告
Asgiref's sync_to_async and Pycharm - fix incorrect type warning by Pycharm
看来Pycharm并没有真正理解sync_to_async。例如,在下面的代码中:
@sync_to_async
def get_point(...) -> Point:
...
def other_func():
point = await get_point()
我收到警告 Class 'Point' does not define '__await__' so the 'await' operator cannot be used on its instance
。
为 sync_to_async 添加正确类型定义的最简单方法是什么? (这比忽略错误更可取)
这显然很容易通过将 asgiref 从之前的 3.3.1 升级到最新的 3.4.1 来解决。
看来Pycharm并没有真正理解sync_to_async。例如,在下面的代码中:
@sync_to_async
def get_point(...) -> Point:
...
def other_func():
point = await get_point()
我收到警告 Class 'Point' does not define '__await__' so the 'await' operator cannot be used on its instance
。
为 sync_to_async 添加正确类型定义的最简单方法是什么? (这比忽略错误更可取)
这显然很容易通过将 asgiref 从之前的 3.3.1 升级到最新的 3.4.1 来解决。