【发布时间】:2019-04-18 03:40:53
【问题描述】:
例子:
import pytest
@pytest.fixture
async def phrase():
return 'hello world'
@pytest.fixture
async def replaced(phrase):
return phrase.replace('hello', 'goodbye')
方法.replace 是黄色的,警告说:
Unresolved attribute reference 'replace' for class 'Coroutine'
但是,这些装置正在工作。如果我从def phrase(): 中删除async,Pycharm 正在正确处理.replace,表明它是str 类的方法。有没有办法告诉 PyCharm phrase 在replaced 中使用时将是str 的一个实例,而不是Coroutine?最好不要为每个使用 phrase 的夹具重复代码。
【问题讨论】:
-
只是一个疯狂的猜测:使用
: str进行类型提示有效吗? -
很遗憾,没有。
-
yield 'hello world'而不是returning。 -
@hoefling 有效!考虑写一个答案?也许你知道为什么
yield有效,而return无效?
标签: python async-await pycharm pytest