根据PEP-484,我们应该可以输入提示生成器函数,如下所示:
from typing import Generator
def generate() -> Generator[int, None, None]:
for i in range(10):
yield i
for i in generate():
print(i)
Run Code Online (Sandbox Code Playgroud)
但是,列表推导在PyCharm中给出以下错误.
Expected 'collections.Iterable', got 'Generator[int, None, None]' instead less... (?F1)
Run Code Online (Sandbox Code Playgroud)
知道为什么PyCharm将此视为错误吗?谢谢.
阅读一些答案后的一些澄清.我正在使用PyCharm Community Edition 2016.3.2(最新版本)并导入了typing.Generator(在代码中更新).上面的代码运行得很好,但PyCharm认为这是一个错误:
所以,我想知道这实际上是PyCharm中的错误还是不支持的功能.