From 66954ad17611b3bb26091a7bd6c8b28a9f91f603 Mon Sep 17 00:00:00 2001 From: nulano Date: Mon, 25 May 2020 18:51:30 +0200 Subject: [PATCH 1/5] deprecate Image.show(command="...") --- Tests/test_image.py | 12 ++++++++++++ docs/deprecations.rst | 8 ++++++++ src/PIL/Image.py | 8 +++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Tests/test_image.py b/Tests/test_image.py index 4d1b66dff..f284f89a7 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -664,6 +664,18 @@ class TestImage: except OSError as e: assert str(e) == "buffer overrun when reading image file" + def test_show_deprecation(self, monkeypatch): + monkeypatch.setattr(Image, "_show", lambda *args, **kwargs: None) + + im = Image.new("RGB", (50, 50), "white") + + with pytest.warns(None) as raised: + im.show() + assert not raised + + with pytest.warns(DeprecationWarning): + im.show(command="mock") + class MockEncoder: pass diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 203921c0b..508b1242b 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -12,6 +12,14 @@ Deprecated features Below are features which are considered deprecated. Where appropriate, a ``DeprecationWarning`` is issued. +Image.show +~~~~~~~~~~ + +.. deprecated:: 7.2.0 + +The ``command`` parameter was deprecated and will be removed in a future release. +Use a subclass of ``ImageShow.Viewer`` instead. + ImageFile.raise_ioerror ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 8c5fff8ed..3d6da8b84 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2172,9 +2172,15 @@ class Image: :param title: Optional title to use for the image window, where possible. - :param command: command used to show the image """ + if command is not None: + warnings.warn( + "The command parameter was deprecated and will be removed in a future" + "release. Use a subclass of ImageShow.Viewer instead.", + DeprecationWarning, + ) + _show(self, title=title, command=command) def split(self): From 5e8854b8dbcdd20b29356fbd7f1b99a983430953 Mon Sep 17 00:00:00 2001 From: nulano Date: Mon, 15 Jun 2020 14:54:38 +0200 Subject: [PATCH 2/5] add note about overriding Image.show behaviour --- src/PIL/Image.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 3d6da8b84..d75fcc6b0 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2157,8 +2157,10 @@ class Image: def show(self, title=None, command=None): """ - Displays this image. This method is mainly intended for - debugging purposes. + Displays this image. This method is mainly intended for debugging purposes. + + This method calls :py:func:`PIL.ImageShow.show` internally. You can use + :py:func:`PIL.ImageShow.register` to override its default behaviour. The image is first saved to a temporary file. By default, it will be in PNG format. @@ -2170,8 +2172,7 @@ class Image: On Windows, the image is opened with the standard PNG display utility. - :param title: Optional title to use for the image window, - where possible. + :param title: Optional title to use for the image window, where possible. """ if command is not None: From 2155c16ae0e8736736b613dc700eaae7a14199d4 Mon Sep 17 00:00:00 2001 From: nulano Date: Sat, 20 Jun 2020 12:00:30 +0100 Subject: [PATCH 3/5] improve warning wording Co-authored-by: Hugo van Kemenade --- src/PIL/Image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index d75fcc6b0..c4f8380df 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2177,7 +2177,7 @@ class Image: if command is not None: warnings.warn( - "The command parameter was deprecated and will be removed in a future" + "The command parameter is deprecated and will be removed in a future" "release. Use a subclass of ImageShow.Viewer instead.", DeprecationWarning, ) From 29dbabd54473b584ca670d6e915b631b4fde7772 Mon Sep 17 00:00:00 2001 From: nulano Date: Sun, 21 Jun 2020 11:35:47 +0100 Subject: [PATCH 4/5] improve wording 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 508b1242b..08906a9b6 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -12,8 +12,8 @@ Deprecated features Below are features which are considered deprecated. Where appropriate, a ``DeprecationWarning`` is issued. -Image.show -~~~~~~~~~~ +Image.show command parameter +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. deprecated:: 7.2.0 From c15dda4308c1aa0d02c2ade7af528d2182b9a90c Mon Sep 17 00:00:00 2001 From: nulano Date: Sun, 21 Jun 2020 12:16:27 +0100 Subject: [PATCH 5/5] fix typo Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/Image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index c4f8380df..051996c09 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2177,7 +2177,7 @@ class Image: if command is not None: warnings.warn( - "The command parameter is deprecated and will be removed in a future" + "The command parameter is deprecated and will be removed in a future " "release. Use a subclass of ImageShow.Viewer instead.", DeprecationWarning, )