mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Union can cause Iterator to require a return statement

Open tvuotila opened this issue 1 year ago • 0 comments

Bug Report

Iterator doesn't require a return statement except when used in an union.

To Reproduce

from typing import Iterator, Union

Type = Union[Iterator[int], int]

def foo() -> Type:
    yield 1

playground link

Actual Behavior

error: Missing return statement [return]

Expected behavior

I expected Mypy to not return any errors like

from typing import Iterator, Union

Type = Iterator[int]

def foo() -> Type:
    yield 1

Your Environment

  • Mypy version used: 1.10.0 (Works on 1.9.0)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.12

tvuotila avatar Jun 24 '24 07:06 tvuotila