Hi, I have a question, maybe not a Hamilton proble...
# hamilton-help
r
Hi, I have a question, maybe not a Hamilton problem:
Copy code
from 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:
Copy code
from typing import Generator
isinstance(Path.rglob('result.txt'), Generator)  # true
Any clue?
s
The generator is being passed in as input, is that right?
r
yes!
s
Yeah seems like a bug on the input type check
r
haha, ok. i use Any instead right now. Also i forget i can not pickle generator when use multiprocessing.
👍 2
i
I think in general, a
Generator
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.
👍 1
s
yes
Iterator
would be a better type, good suggestion @Iliya R.