Closed
Description
Lines 390 to 391 in d3cfe67
It's relatively simple to demonstrate counterexamples that are not GeneratorType
objects. For example,
Iterator:
from collections.abc import Generator
from types import GeneratorType
def gf() -> Generator[int]:
yield from [1, 2, 3, 4]
gen = gf()
assert type(gen) is GeneratorType
next(gen) # 1
print(type(gen.gi_yieldfrom)) # <class 'list_iterator'>
builtins.coroutine_wrapper
(some kind of collections.abc.Generator
?):
# python 3.10
import asyncio
async def a():
await asyncio.sleep(4)
return 1
def gf():
yield from a().__await__()
gen = gf()
next(gen) # _asyncio.Future object
print(type(gen.gi_yieldfrom)) # <class 'coroutine_wrapper'>
So, what would be a useful type annotation for this that is still accurate? Would Iterator[Any] | None
be OK, or do we have to do the same thing as types.CoroutineType.cr_await
and erase all useful information for the type?
Lines 438 to 442 in d3cfe67