Roy Kid
09/28/2024, 7:05 PMfrom pathlib import Path
from typing import Generator
def foo(generator: Genertor)->Any:
...
foo(Path.rglob('something')
# Error: Type requirement mismatch. Expected results:typing.Generator got <generator object Path.rglob at 0x7f286cb7bef0>:<class 'generator'> instead.
I want to pass a generator to hamilton function, and it told me type mismatch. But I'm sure it is a generator:
from typing import Generator
isinstance(Path.rglob('result.txt'), Generator) # true
Any clue?Stefan Krawczyk
09/28/2024, 7:14 PMRoy Kid
09/28/2024, 7:15 PMStefan Krawczyk
09/28/2024, 7:20 PMRoy Kid
09/28/2024, 7:21 PMIliya R
09/28/2024, 10:00 PMGenerator can by type hinted as an Iterator of the output type, which is simpler. In your particular case, a workaround to consider is creating the generator inside the operator.Stefan Krawczyk
09/29/2024, 3:35 AMIterator would be a better type, good suggestion @Iliya R.