【问题标题】:In Python 3.5 what should the return type annotation look like for a generator function?在 Python 3.5 中,生成器函数的返回类型注释应该是什么样的?
【发布时间】:2016-02-25 00:47:10
【问题描述】:
def a_generator() -> Generator[Tuple[int, int]]:
    # blah blah blah.  
    # Do some stuff to make some ints.
    yield int_one, int_two

我是否正确地执行了返回类型注释?

【问题讨论】:

    标签: python-3.x types python-3.5


    【解决方案1】:

    看起来你可以使用:

    def a_generator() -> Iterator[Tuple[int, int]]:
        # blah blah blah.  
        # Do some stuff to make some ints.
        yield int_one, int_two
    

    Per Guido's comment here

    Generator 示例in PEP 0484 来看,Generator 似乎需要三个参数。

    另请参阅typing 模块的文档。

    【讨论】:

      猜你喜欢
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 2019-12-30
      • 2017-09-25
      • 2019-05-30
      • 1970-01-01
      • 2018-12-15
      相关资源
      最近更新 更多