Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Image.show(command="...") #4646

Merged
merged 5 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
~~~~~~~~~~

.. 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 @@ -2157,8 +2157,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 @@ -2170,11 +2172,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 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):
Expand Down