false `bad-return` for a generator function with `Iterator[X] | T` return annotation
Author: MarcoGorelliCreated Sep 5, 2026Updated Sep 20, 2026
Labelsstalequansight
Describe the Bug
from collections.abc import Iterator
def gen(x: int) -> Iterator[int] | int:
yield from range(4)
return 5ERROR sandbox.py:6:12-13: Returned type `Literal[5]` is not assignable to declared return type `None` [[bad-return](https://pyrefly.org/en/docs/error-kinds/#bad-return)]All either type checkers are fine with this, but Pyrefly emits the error above
Noticed in huggingface-hub
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
Source: facebook/pyrefly