Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created January 14, 2026 16:51
Show Gist options
  • Select an option

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

Select an option

Save mypy-play/0367d191a66e57a9856d9e7ece5c4bdf to your computer and use it in GitHub Desktop.
Shared via mypy Playground
class Shape:
def area(self) -> float:
return 1.0
class Circle(Shape):
def radius(self) -> float:
return 2.0
# T is constrained to be Shape or a subclass of Shape
def total_area[T: Shape](shapes: tuple[T, ...]) -> float:
return sum(s.area() for s in shapes)
total_area(shapes=(Shape(),Circle()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment