How do I declare the type of a python generator

Viewed 47

What is the correct way of specifying the type of a generator in python?

Say for example I have the generator:

def f():
    yield "Banana"
    yield 68

How do I specify that it has the type Union[str,int]? Is it just def f() -> Union[str,int]:?

0 Answers
Related