So I was tinkering with generators, and i found out that generators have a typing object (i.e. generators have an alias)
I then stumbled upon documentation for the typing.Generator object on https://docs.python.org/3/library/typing.html#typing.Generator and this is what the docs have to say:
A generator can be annotated by the generic type
Generator[YieldType, SendType, ReturnType].
Which got me wondering on how to modify the SendType and ReturnType thingys
The docs suggested this as an example:
def echo_round() -> Generator[int, float, str]:
sent = yield 0
while sent >= 0:
sent = yield round(sent)
return 'Done'
I assume that the second sent declaration is what defines the SendType, but yield 0 returns None (or doesnt return anything in the first place), and therefore raises TypeError: '>=' not supported between instances of 'NoneType' and 'int'
How does SendType work, how do I modify it, and what are cases in which SendType and ReturnType are useful?