Skip to content

Commit e1fb1ab

Browse files
bgilbertradarhere
andcommitted
Deprecate raise_oserror() for removal in Pillow 12
It's only useful if the caller has an IMAGING_CODEC_* error code, which are only produced by codec decode() methods and are automatically translated by ImageFile. Co-authored-by: Andrew Murray <[email protected]>
1 parent ec17dc1 commit e1fb1ab

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

Tests/test_imagefile.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ def test_safeblock(self):
115115
assert_image_equal(im1, im2)
116116

117117
def test_raise_oserror(self):
118-
with pytest.raises(OSError):
119-
ImageFile.raise_oserror(1)
118+
with pytest.warns(DeprecationWarning):
119+
with pytest.raises(OSError):
120+
ImageFile.raise_oserror(1)
120121

121122
def test_raise_typeerror(self):
122123
with pytest.raises(TypeError):

docs/deprecations.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ Since Pillow's C API is now faster than PyAccess on PyPy,
3434
``Image.USE_CFFI_ACCESS``, for switching from the C API to PyAccess, is
3535
similarly deprecated.
3636

37+
ImageFile.raise_oserror
38+
~~~~~~~~~~~~~~~~~~~~~~~
39+
40+
.. deprecated:: 10.2.0
41+
42+
``ImageFile.raise_oserror()`` has been deprecated and will be removed in Pillow
43+
12.0.0 (2025-10-15). The function is undocumented and is only useful for translating
44+
error codes returned by a codec's ``decode()`` method, which ImageFile already does
45+
automatically.
46+
3747
Removed features
3848
----------------
3949

docs/releasenotes/10.2.0.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ TODO
1212
Deprecations
1313
============
1414

15+
ImageFile.raise_oserror
16+
^^^^^^^^^^^^^^^^^^^^^^^
17+
18+
``ImageFile.raise_oserror()`` has been deprecated and will be removed in Pillow
19+
12.0.0 (2025-10-15). The function is undocumented and is only useful for translating
20+
error codes returned by a codec's ``decode()`` method, which ImageFile already does
21+
automatically.
22+
1523
TODO
1624
^^^^
1725

src/PIL/ImageFile.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from typing import NamedTuple
3636

3737
from . import Image
38+
from ._deprecate import deprecate
3839
from ._util import is_path
3940

4041
MAXBLOCK = 65536
@@ -75,6 +76,12 @@ def _get_oserror(error, *, encoder):
7576

7677

7778
def raise_oserror(error):
79+
deprecate(
80+
"raise_oserror",
81+
12,
82+
action="It is only useful for translating error codes returned by a codec's "
83+
"decode() method, which ImageFile already does automatically.",
84+
)
7885
raise _get_oserror(error, encoder=False)
7986

8087

@@ -298,7 +305,7 @@ def load(self):
298305

299306
if not self.map and not LOAD_TRUNCATED_IMAGES and err_code < 0:
300307
# still raised if decoder fails to return anything
301-
raise_oserror(err_code)
308+
raise _get_oserror(err_code, encoder=False)
302309

303310
return Image.Image.load(self)
304311

@@ -425,7 +432,7 @@ def feed(self, data):
425432
if e < 0:
426433
# decoding error
427434
self.image = None
428-
raise_oserror(e)
435+
raise _get_oserror(e, encoder=False)
429436
else:
430437
# end of image
431438
return

src/PIL/_deprecate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def deprecate(
4747
raise RuntimeError(msg)
4848
elif when == 11:
4949
removed = "Pillow 11 (2024-10-15)"
50+
elif when == 12:
51+
removed = "Pillow 12 (2025-10-15)"
5052
else:
5153
msg = f"Unknown removal version: {when}. Update {__name__}?"
5254
raise ValueError(msg)

0 commit comments

Comments
 (0)