Question

The following Python code intends to enforce that all `Worker` subclasses implement a `work` method. However, it's not working as expected. class Worker:     def work(self):         raise NotImplementedError("Subclasses must implement this method") class Engineer(Worker):     pass eng = Engineer() eng.work() What is the most Pythonic way to fix this to ensure `Engineer` *must* implement `work` at compile/definition time?

A Add `@abstractmethod` decorator to `work` in `Worker` and inherit from `ABC`.
B Add `assert False, "Implement work"` in `Engineer.work`.
C Change `Worker` to an interface.
D Manually check for `work` method in `Engineer` after its definition.
E Make `work` a private method in `Worker`.
Practice Next

Hey! Ask a query