Skip to content

Commit 9979eff

Browse files
authored
Merge pull request #4646 from nulano/show-command
Deprecate Image.show(command="...")
2 parents b667fd8 + c15dda4 commit 9979eff

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

Tests/test_image.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,18 @@ def test_overrun(self):
664664
except OSError as e:
665665
assert str(e) == "buffer overrun when reading image file"
666666

667+
def test_show_deprecation(self, monkeypatch):
668+
monkeypatch.setattr(Image, "_show", lambda *args, **kwargs: None)
669+
670+
im = Image.new("RGB", (50, 50), "white")
671+
672+
with pytest.warns(None) as raised:
673+
im.show()
674+
assert not raised
675+
676+
with pytest.warns(DeprecationWarning):
677+
im.show(command="mock")
678+
667679

668680
class MockEncoder:
669681
pass

docs/deprecations.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ Deprecated features
1212
Below are features which are considered deprecated. Where appropriate,
1313
a ``DeprecationWarning`` is issued.
1414

15+
Image.show command parameter
16+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17+
18+
.. deprecated:: 7.2.0
19+
20+
The ``command`` parameter was deprecated and will be removed in a future release.
21+
Use a subclass of ``ImageShow.Viewer`` instead.
22+
1523
ImageFile.raise_ioerror
1624
~~~~~~~~~~~~~~~~~~~~~~~
1725

src/PIL/Image.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,8 +2181,10 @@ def seek(self, frame):
21812181

21822182
def show(self, title=None, command=None):
21832183
"""
2184-
Displays this image. This method is mainly intended for
2185-
debugging purposes.
2184+
Displays this image. This method is mainly intended for debugging purposes.
2185+
2186+
This method calls :py:func:`PIL.ImageShow.show` internally. You can use
2187+
:py:func:`PIL.ImageShow.register` to override its default behaviour.
21862188
21872189
The image is first saved to a temporary file. By default, it will be in
21882190
PNG format.
@@ -2194,11 +2196,16 @@ def show(self, title=None, command=None):
21942196
21952197
On Windows, the image is opened with the standard PNG display utility.
21962198
2197-
:param title: Optional title to use for the image window,
2198-
where possible.
2199-
:param command: command used to show the image
2199+
:param title: Optional title to use for the image window, where possible.
22002200
"""
22012201

2202+
if command is not None:
2203+
warnings.warn(
2204+
"The command parameter is deprecated and will be removed in a future "
2205+
"release. Use a subclass of ImageShow.Viewer instead.",
2206+
DeprecationWarning,
2207+
)
2208+
22022209
_show(self, title=title, command=command)
22032210

22042211
def split(self):

0 commit comments

Comments
 (0)