From 40aefc6ba5a060d9ec06bc9dbdacbdb87c80d2a7 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 17 Jul 2020 10:55:20 +0300 Subject: [PATCH 1/5] Remove im.offset, deprecated in 2001; and fromstring and tostring, deprecated in 2013 --- Tests/test_image.py | 12 ------------ Tests/test_image_frombytes.py | 6 ------ docs/deprecations.rst | 27 +++++++++++++++++++++++++++ docs/reference/Image.rst | 4 ---- src/PIL/Image.py | 21 --------------------- 5 files changed, 27 insertions(+), 43 deletions(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 6d29ac80eec..068fb8172c5 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -466,18 +466,6 @@ def test_storage_neg(self): with pytest.raises(ValueError): Image.core.fill("RGB", (2, -2), (0, 0, 0)) - def test_offset_not_implemented(self): - # Arrange - with hopper() as im: - - # Act / Assert - with pytest.raises(NotImplementedError): - im.offset(None) - - def test_fromstring(self): - with pytest.raises(NotImplementedError): - Image.fromstring() - def test_linear_gradient_wrong_mode(self): # Arrange wrong_mode = "RGB" diff --git a/Tests/test_image_frombytes.py b/Tests/test_image_frombytes.py index faf94ac7794..7fb05cda7b2 100644 --- a/Tests/test_image_frombytes.py +++ b/Tests/test_image_frombytes.py @@ -1,4 +1,3 @@ -import pytest from PIL import Image from .helper import assert_image_equal, hopper @@ -9,8 +8,3 @@ def test_sanity(): im2 = Image.frombytes(im1.mode, im1.size, im1.tobytes()) assert_image_equal(im1, im2) - - -def test_not_implemented(): - with pytest.raises(NotImplementedError): - Image.fromstring() diff --git a/docs/deprecations.rst b/docs/deprecations.rst index b5ba00e40c7..f51961f1ba5 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -55,6 +55,33 @@ Removed features Deprecated features are only removed in major releases after an appropriate period of deprecation has passed. +im.offset +~~~~~~~~~ + +.. deprecated:: 1.1.2 +.. versionremoved:: 8.0.0 + +``im.offset()`` has been removed, call ``ImageChops.offset()`` instead. + +It was documented as deprecated in PIL 1.1.2, +raised a ``DeprecationWarning`` since 1.1.5, +an ``Exception`` since Pillow 3.0.0 +and ``NotImplementedError`` since 3.3.0. + +im.fromstring and tostring +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 2.0.0 +.. versionremoved:: 8.0.0 + +* ``Image.fromstring()`` has been removed, call ``frombytes()`` instead. +* ``im.fromstring()`` has been removed, call ``frombytes()`` instead. +* ``im.tostring()`` has been removed, call ``tobytes()`` instead. + +They issued a ``DeprecationWarning`` since 2.0.0, +an ``Exception`` since 3.0.0 +and ``NotImplementedError`` since 3.3.0. + ImageCms.CmsProfile attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/reference/Image.rst b/docs/reference/Image.rst index f24d382b846..d49bd7e62b1 100644 --- a/docs/reference/Image.rst +++ b/docs/reference/Image.rst @@ -196,7 +196,6 @@ This helps to get the bounding box coordinates of the input image: .. automethod:: PIL.Image.Image.getpixel .. automethod:: PIL.Image.Image.getprojection .. automethod:: PIL.Image.Image.histogram -.. automethod:: PIL.Image.Image.offset .. automethod:: PIL.Image.Image.paste .. automethod:: PIL.Image.Image.point .. automethod:: PIL.Image.Image.putalpha @@ -243,7 +242,6 @@ This rotates the input image by ``theta`` degrees counter clockwise: .. automethod:: PIL.Image.Image.thumbnail .. automethod:: PIL.Image.Image.tobitmap .. automethod:: PIL.Image.Image.tobytes -.. automethod:: PIL.Image.Image.tostring .. automethod:: PIL.Image.Image.transform .. automethod:: PIL.Image.Image.transpose @@ -263,8 +261,6 @@ This flips the input image by using the :data:`FLIP_LEFT_RIGHT` method. .. automethod:: PIL.Image.Image.verify -.. automethod:: PIL.Image.Image.fromstring - .. automethod:: PIL.Image.Image.load .. automethod:: PIL.Image.Image.close diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 03829d9a92b..f4361b2488f 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -746,11 +746,6 @@ def tobytes(self, encoder_name="raw", *args): return b"".join(data) - def tostring(self, *args, **kw): - raise NotImplementedError( - "tostring() has been removed. Please call tobytes() instead." - ) - def tobitmap(self, name="image"): """ Returns the image converted to an X11 bitmap. @@ -802,11 +797,6 @@ def frombytes(self, data, decoder_name="raw", *args): if s[1] != 0: raise ValueError("cannot decode image data") - def fromstring(self, *args, **kw): - raise NotImplementedError( - "fromstring() has been removed. Please call frombytes() instead." - ) - def load(self): """ Allocates storage for the image and loads the pixel data. In @@ -1434,11 +1424,6 @@ def entropy(self, mask=None, extrema=None): return self.im.entropy(extrema) return self.im.entropy() - def offset(self, xoffset, yoffset=None): - raise NotImplementedError( - "offset() has been removed. Please call ImageChops.offset() instead." - ) - def paste(self, im, box=None, mask=None): """ Pastes another image into this image. The box argument is either @@ -2672,12 +2657,6 @@ def frombytes(mode, size, data, decoder_name="raw", *args): return im -def fromstring(*args, **kw): - raise NotImplementedError( - "fromstring() has been removed. Please call frombytes() instead." - ) - - def frombuffer(mode, size, data, decoder_name="raw", *args): """ Creates an image memory referencing pixel data in a byte buffer. From 39bc25e28ac9da12e2fef3a741e22c6f37e50033 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 18 Jul 2020 10:09:15 +0300 Subject: [PATCH 2/5] Link to the replacement functions Co-authored-by: nulano --- docs/deprecations.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index f51961f1ba5..bd83849964e 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -74,9 +74,9 @@ im.fromstring and tostring .. deprecated:: 2.0.0 .. versionremoved:: 8.0.0 -* ``Image.fromstring()`` has been removed, call ``frombytes()`` instead. -* ``im.fromstring()`` has been removed, call ``frombytes()`` instead. -* ``im.tostring()`` has been removed, call ``tobytes()`` instead. +* ``Image.fromstring()`` has been removed, call :py:func:`.Image.frombytes()` instead. +* ``im.fromstring()`` has been removed, call :py:meth:`~PIL.Image.Image.frombytes()` instead. +* ``im.tostring()`` has been removed, call :py:meth:`~PIL.Image.Image.tobytes()` instead. They issued a ``DeprecationWarning`` since 2.0.0, an ``Exception`` since 3.0.0 From 415a4aa8ac9e91d3b66f7ae094f5bda262281cb8 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 18 Jul 2020 10:13:18 +0300 Subject: [PATCH 3/5] Add PIL.Image.Image.frombytes to docs --- docs/reference/Image.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/reference/Image.rst b/docs/reference/Image.rst index d49bd7e62b1..cd0bffc8b86 100644 --- a/docs/reference/Image.rst +++ b/docs/reference/Image.rst @@ -151,6 +151,7 @@ This crops the input image with the provided coordinates: .. automethod:: PIL.Image.Image.draft .. automethod:: PIL.Image.Image.effect_spread .. automethod:: PIL.Image.Image.entropy +.. automethod:: PIL.Image.Image.frombytes .. automethod:: PIL.Image.Image.filter This blurs the input image using a filter from the ``ImageFilter`` module: From b8ccd97d756efa0f0a328fe354e0f4dd4ec261a3 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 21 Jul 2020 15:55:32 +0300 Subject: [PATCH 4/5] Update title Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- docs/deprecations.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index bd83849964e..10ccec632eb 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -68,8 +68,8 @@ raised a ``DeprecationWarning`` since 1.1.5, an ``Exception`` since Pillow 3.0.0 and ``NotImplementedError`` since 3.3.0. -im.fromstring and tostring -~~~~~~~~~~~~~~~~~~~~~~~~~~ +Image.fromstring, im.fromstring and im.tostring +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. deprecated:: 2.0.0 .. versionremoved:: 8.0.0 From ea96cbeddc050433cead4cac063a6ca47063af55 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 22 Jul 2020 12:10:23 +0300 Subject: [PATCH 5/5] Alphabetise Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- docs/reference/Image.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/reference/Image.rst b/docs/reference/Image.rst index cd0bffc8b86..bd18a4dc4b5 100644 --- a/docs/reference/Image.rst +++ b/docs/reference/Image.rst @@ -151,8 +151,8 @@ This crops the input image with the provided coordinates: .. automethod:: PIL.Image.Image.draft .. automethod:: PIL.Image.Image.effect_spread .. automethod:: PIL.Image.Image.entropy -.. automethod:: PIL.Image.Image.frombytes .. automethod:: PIL.Image.Image.filter +.. automethod:: PIL.Image.Image.frombytes This blurs the input image using a filter from the ``ImageFilter`` module: