diff --git a/src/PIL/BufrStubImagePlugin.py b/src/PIL/BufrStubImagePlugin.py index 264564d2bbb..d82c4c746c3 100644 --- a/src/PIL/BufrStubImagePlugin.py +++ b/src/PIL/BufrStubImagePlugin.py @@ -52,10 +52,6 @@ def _open(self) -> None: self._mode = "F" self._size = 1, 1 - loader = self._load() - if loader: - loader.open(self) - def _load(self) -> ImageFile.StubHandler | None: return _handler diff --git a/src/PIL/GribStubImagePlugin.py b/src/PIL/GribStubImagePlugin.py index 146a6fa0df0..3784ef2f134 100644 --- a/src/PIL/GribStubImagePlugin.py +++ b/src/PIL/GribStubImagePlugin.py @@ -52,10 +52,6 @@ def _open(self) -> None: self._mode = "F" self._size = 1, 1 - loader = self._load() - if loader: - loader.open(self) - def _load(self) -> ImageFile.StubHandler | None: return _handler diff --git a/src/PIL/Hdf5StubImagePlugin.py b/src/PIL/Hdf5StubImagePlugin.py index 1523e95d58c..1a56660f7bd 100644 --- a/src/PIL/Hdf5StubImagePlugin.py +++ b/src/PIL/Hdf5StubImagePlugin.py @@ -52,10 +52,6 @@ def _open(self) -> None: self._mode = "F" self._size = 1, 1 - loader = self._load() - if loader: - loader.open(self) - def _load(self) -> ImageFile.StubHandler | None: return _handler diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 78abe3c77be..45df3be0363 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -148,6 +148,10 @@ def __init__( try: try: self._open() + + if isinstance(self, StubImageFile): + if loader := self._load(): + loader.open(self) except ( IndexError, # end of data TypeError, # end of data (ord) diff --git a/src/PIL/WmfImagePlugin.py b/src/PIL/WmfImagePlugin.py index 3ae86242a8b..79d54df4ed7 100644 --- a/src/PIL/WmfImagePlugin.py +++ b/src/PIL/WmfImagePlugin.py @@ -148,10 +148,6 @@ def _open(self) -> None: self._mode = "RGB" self._size = size - loader = self._load() - if loader: - loader.open(self) - def _load(self) -> ImageFile.StubHandler | None: return _handler