Skip to content

Mark ImageFile._open() as abstract - #9876

Merged
hugovk merged 1 commit into
python-pillow:mainfrom
radarhere:abstract
Sep 15, 2026
Merged

hugovk merged 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

@hugovk
hugovk merged commit 3078cab into python-pillow:main Sep 15, 2026
64 of 66 checks passed
@radarhere
radarhere deleted the abstract branch September 15, 2026 22:29
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.

2 participants