Abstract base classes

Sometimes you want subclasses to be forced to write a method. Inherit from abc.ABC and mark the method with @abstractmethod.

Python then refuses to create an instance of any class that still has abstract methods. Storage() fails, and so does Broken(), which forgot to write save. The error comes when you create the object, not later when some rarely used code path calls the missing method.

The base class can also hold shared code. save_all is written once and calls self.save, which each subclass fills in.

Protocol versus ABC: a protocol needs no inheritance and is checked by type checkers. An ABC needs inheritance, is checked at runtime, and can share code. Both are fine answers. Say which trade-off you want.

Run it, then add a save method to Broken.