Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created January 24, 2026 18:56
Show Gist options
  • Select an option

  • Save mypy-play/9c7b83d3104aa414bd2a9eeb6c3e2974 to your computer and use it in GitHub Desktop.

Select an option

Save mypy-play/9c7b83d3104aa414bd2a9eeb6c3e2974 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from __future__ import annotations
from typing import overload, Iterator
class Foo:
@overload
def method(self: Bar) -> Iterator[Bar]: ...
@overload
def method(self: Foo) -> Iterator[Foo]: ...
def method(self) -> Iterator[Foo] | Iterator[Bar]:
raise NotImplementedError
class Bar: ...
class Baz(Foo):
def method(self) -> Iterator[Foo]:
raise NotImplementedError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment