From b68e0e17c720f686a9804e29659719b8f54c6cda Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 7 Apr 2020 19:53:35 +1000 Subject: [PATCH 1/3] Raise DeprecationWarning on raise_ioerror --- Tests/test_imagefile.py | 5 +++++ src/PIL/ImageFile.py | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/Tests/test_imagefile.py b/Tests/test_imagefile.py index e2b52857d57..649b0ac9b1d 100644 --- a/Tests/test_imagefile.py +++ b/Tests/test_imagefile.py @@ -93,6 +93,11 @@ def test_safeblock(self): assert_image_equal(im1, im2) + def test_raise_ioerror(self): + with pytest.raises(IOError): + with pytest.raises(DeprecationWarning): + ImageFile.raise_ioerror(1) + def test_raise_oserror(self): with pytest.raises(OSError): ImageFile.raise_oserror(1) diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 2177dbf5255..8637a47f953 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -30,6 +30,7 @@ import io import struct import sys +import warnings from . import Image from ._util import isPath @@ -64,6 +65,15 @@ def raise_oserror(error): raise OSError(message + " when reading image file") +def raise_ioerror(error): + warnings.warn( + "raise_ioerror is deprecated and will be removed in a future release. " + "Use raise_oserror instead.", + DeprecationWarning, + ) + return raise_oserror(error) + + def _tilesort(t): # sort on offset return t[2] From 9b01826154d51262d10103f7ac430650b432edeb Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 7 Apr 2020 20:39:40 +1000 Subject: [PATCH 2/3] ImageFile.raise_ioerror is now deprecated [ci skip] --- docs/deprecations.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 227a5bc823e..350a6002c12 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -12,6 +12,15 @@ Deprecated features Below are features which are considered deprecated. Where appropriate, a ``DeprecationWarning`` is issued. +ImageFile.raise_ioerror +~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 7.2.0 + +IOError was merged into OSError in Python 3.3. So, ``ImageFile.raise_ioerror`` +is now deprecated and will be removed in a future released. Use +``ImageFile.raise_oserror`` instead. + PILLOW_VERSION constant ~~~~~~~~~~~~~~~~~~~~~~~ From 7de4a85e315256b1c4bfa5ea6b431f19a49218a0 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Tue, 7 Apr 2020 22:59:18 +1000 Subject: [PATCH 3/3] Highlighted errors [ci skip] Co-Authored-By: Hugo van Kemenade --- docs/deprecations.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 350a6002c12..203921c0b84 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -17,7 +17,7 @@ ImageFile.raise_ioerror .. deprecated:: 7.2.0 -IOError was merged into OSError in Python 3.3. So, ``ImageFile.raise_ioerror`` +``IOError`` was merged into ``OSError`` in Python 3.3. So, ``ImageFile.raise_ioerror`` is now deprecated and will be removed in a future released. Use ``ImageFile.raise_oserror`` instead.