Skip to content

Commit

Permalink
Merge pull request #4646 from nulano/show-command
Browse files Browse the repository at this point in the history
Deprecate Image.show(command="...")
  • Loading branch information
radarhere authored Jun 23, 2020
2 parents b667fd8 + c15dda4 commit 9979eff
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
12 changes: 12 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,18 @@ def test_overrun(self):
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
Expand Down
8 changes: 8 additions & 0 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ Deprecated features
Below are features which are considered deprecated. Where appropriate,
a ``DeprecationWarning`` is issued.

Image.show command parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. 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
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
17 changes: 12 additions & 5 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2181,8 +2181,10 @@ def seek(self, frame):

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.
Expand All @@ -2194,11 +2196,16 @@ def show(self, title=None, command=None):
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 command: command used to show the image
:param title: Optional title to use for the image window, where possible.
"""

if command is not None:
warnings.warn(
"The command parameter is 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):
Expand Down

0 comments on commit 9979eff

Please sign in to comment.