Use ABCMeta in classes with abstractmethod by radarhere · Pull Request #8803 · python-pillow/Pillow
https://docs.python.org/3/library/abc.html#abc.abstractmethod
@abc.abstractmethod
A decorator indicating abstract methods.Using this decorator requires that the class’s metaclass is ABCMeta or is derived from it.
This is true. In main,
>>> from PIL import Image >>> Image.ImagePointHandler() <PIL.Image.ImagePointHandler object at 0x1044f93d0>
but once this PR changes the class to inherit from abc.ABC,
>>> from PIL import Image >>> Image.ImagePointHandler() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: Can't instantiate abstract class ImagePointHandler with abstract method point
While I'm here, I'm also going to replace
| def _open(self) -> None: | |
| msg = "StubImageFile subclass must implement _open" | |
| raise NotImplementedError(msg) |
and
| def _load(self) -> StubHandler | None: | |
| """(Hook) Find actual image loader.""" | |
| msg = "StubImageFile subclass must implement _load" | |
| raise NotImplementedError(msg) |
with abstract methods.