How to annotate a generator in python3?

后端 未结 2 782
庸人自扰
庸人自扰 2021-02-12 11:06

Python 3.x supports (optional) function annotations:

def add_ints(x:int, y:int) -> int :
    return x+y

I sometimes encounter problems as to

2条回答
  •  悲哀的现实
    2021-02-12 11:36

    The typing module defines the Generator type, which you can use like:

    Generator[yield_type, send_type, return_type] 
    

    See also PEP 0484.

提交回复
热议问题