Created
January 14, 2026 16:51
-
-
Save mypy-play/0367d191a66e57a9856d9e7ece5c4bdf to your computer and use it in GitHub Desktop.
Shared via mypy Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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