Skip to content

Commit 5e9eea1

Browse files
authored
Merge pull request #8803 from radarhere/abstract
Use ABCMeta in classes with abstractmethod
2 parents c23bf05 + d186a2a commit 5e9eea1

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/PIL/BlpImagePlugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def _open(self) -> None:
291291
self.tile = [ImageFile._Tile(decoder, (0, 0) + self.size, offset, args)]
292292

293293

294-
class _BLPBaseDecoder(ImageFile.PyDecoder):
294+
class _BLPBaseDecoder(abc.ABC, ImageFile.PyDecoder):
295295
_pulls_fd = True
296296

297297
def decode(self, buffer: bytes | Image.SupportsArrayInterface) -> tuple[int, int]:

src/PIL/Image.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ def toqpixmap(self) -> ImageQt.QPixmap:
29802980
# Abstract handlers.
29812981

29822982

2983-
class ImagePointHandler:
2983+
class ImagePointHandler(abc.ABC):
29842984
"""
29852985
Used as a mixin by point transforms
29862986
(for use with :py:meth:`~PIL.Image.Image.point`)
@@ -2991,7 +2991,7 @@ def point(self, im: Image) -> Image:
29912991
pass
29922992

29932993

2994-
class ImageTransformHandler:
2994+
class ImageTransformHandler(abc.ABC):
29952995
"""
29962996
Used as a mixin by geometry transforms
29972997
(for use with :py:meth:`~PIL.Image.Image.transform`)

src/PIL/ImageFile.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def _seek_check(self, frame: int) -> bool:
438438
return self.tell() != frame
439439

440440

441-
class StubHandler:
441+
class StubHandler(abc.ABC):
442442
def open(self, im: StubImageFile) -> None:
443443
pass
444444

@@ -447,17 +447,17 @@ def load(self, im: StubImageFile) -> Image.Image:
447447
pass
448448

449449

450-
class StubImageFile(ImageFile):
450+
class StubImageFile(ImageFile, metaclass=abc.ABCMeta):
451451
"""
452452
Base class for stub image loaders.
453453
454454
A stub loader is an image loader that can identify files of a
455455
certain format, but relies on external code to load the file.
456456
"""
457457

458+
@abc.abstractmethod
458459
def _open(self) -> None:
459-
msg = "StubImageFile subclass must implement _open"
460-
raise NotImplementedError(msg)
460+
pass
461461

462462
def load(self) -> Image.core.PixelAccess | None:
463463
loader = self._load()
@@ -471,10 +471,10 @@ def load(self) -> Image.core.PixelAccess | None:
471471
self.__dict__ = image.__dict__
472472
return image.load()
473473

474+
@abc.abstractmethod
474475
def _load(self) -> StubHandler | None:
475476
"""(Hook) Find actual image loader."""
476-
msg = "StubImageFile subclass must implement _load"
477-
raise NotImplementedError(msg)
477+
pass
478478

479479

480480
class Parser:

src/PIL/ImageFilter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ._typing import NumpyArray
2828

2929

30-
class Filter:
30+
class Filter(abc.ABC):
3131
@abc.abstractmethod
3232
def filter(self, image: _imaging.ImagingCore) -> _imaging.ImagingCore:
3333
pass

src/PIL/ImageShow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def show_file(self, path: str, **options: Any) -> int:
192192
register(MacViewer)
193193

194194

195-
class UnixViewer(Viewer):
195+
class UnixViewer(abc.ABC, Viewer):
196196
format = "PNG"
197197
options = {"compress_level": 1, "save_all": True}
198198

0 commit comments

Comments
 (0)