Looking at the following: https://docs.python.org/3/library/typing.html#typing.Generator
I'm not sure how one would know what the yield/send/return value is for any given generator?
The yield value seems easy, as I assume one can just do type(next(<generator>)), but the others aren't so clear.
example
For example, I'm not sure how one would typehint the following :
# note - this is not meant to be useful...
import pathlib
def list_of_paths(paths) -> list[pathlib.Path]:
return list(paths)
path_list = list_of_paths(paths = pathlib.Path('.').glob('*'))
How to know what to use in Generator?
from typing import Generator
import pathlib
def list_of_paths(paths : Generator[pathlib.Path, ? , ? ]) -> list[pathlib.Path]:
return list(paths)
path_list = list_of_paths(paths = pathlib.Path('.').glob('*'))
edit
Continuing with the example of pathlib.Path.glob, the documentation is https://docs.python.org/3/library/pathlib.html#pathlib.Path.glob
It's note clear here what the send / return types for this generator are.