Dustin Wyatt
Dustin Wyatt

Reputation: 4244

In Python 3.5 what should the return type annotation look like for a generator function?

def a_generator() -> Generator[Tuple[int, int]]:
    # blah blah blah.  
    # Do some stuff to make some ints.
    yield int_one, int_two

Did I do that return type annotation correctly?

Upvotes: 2

Views: 438

Answers (1)

Trey Hunner
Trey Hunner

Reputation: 11814

It looks like you could use:

def a_generator() -> Iterator[Tuple[int, int]]:
    # blah blah blah.  
    # Do some stuff to make some ints.
    yield int_one, int_two

Per Guido's comment here

From the Generator example in PEP 0484, it looks like Generator takes three arguments.

Also see the documentation for the typing module.

Upvotes: 1

Related Questions