Skip to content

Mark ImageFile._open() as abstract - #9876

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:abstract
Open

Mark ImageFile._open() as abstract#9876
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:abstract

Conversation

@radarhere

@radarhere radarhere commented Aug 18, 2026

Copy link
Copy Markdown
Member

Pillow/src/PIL/ImageFile.py

Lines 175 to 176 in 1cdb9a4

def _open(self) -> None:
pass

must be implemented in an ImageFile subclass.

Without this change,

from PIL import ImageFile
import io

class DummyImageFile(ImageFile.ImageFile):
  pass

DummyImageFile(io.BytesIO(b""))

gives

Traceback (most recent call last):
  File "demo.py", line 7, in <module>
    DummyImageFile(io.BytesIO(b""))
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "PIL/ImageFile.py", line 166, in __init__
    raise SyntaxError(msg)
SyntaxError: not identified by this driver

With this change, there is the much clearer

Traceback (most recent call last):
  File "demo.py", line 7, in <module>
    DummyImageFile(io.BytesIO(b""))
TypeError: Can't instantiate abstract class DummyImageFile with abstract method _open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant