相关疑难解决方法(0)

在python 3.6中输入提示生成器

根据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中的错误还是不支持的功能.

python pycharm python-3.x

24
推荐指数
3
解决办法
7736
查看次数

标签 统计

pycharm ×1

python ×1

python-3.x ×1