Skip to content

Commit ee06255

Browse files
committed
Deprecated _showxv
1 parent c9745f4 commit ee06255

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

Tests/test_image.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import PIL
77
import pytest
8-
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError
8+
from PIL import Image, ImageDraw, ImagePalette, ImageShow, UnidentifiedImageError
99

1010
from .helper import (
1111
assert_image_equal,
@@ -585,6 +585,22 @@ def test_p_from_rgb_rgba(self):
585585
expected = Image.new(mode, (100, 100), color)
586586
assert_image_equal(im.convert(mode), expected)
587587

588+
def test_showxv_deprecation(self):
589+
class TestViewer(ImageShow.Viewer):
590+
def show_image(self, image, **options):
591+
return True
592+
593+
viewer = TestViewer()
594+
ImageShow.register(viewer, -1)
595+
596+
im = Image.new("RGB", (50, 50), "white")
597+
598+
with pytest.warns(DeprecationWarning):
599+
Image._showxv(im)
600+
601+
# Restore original state
602+
ImageShow._viewers.pop(0)
603+
588604
def test_no_resource_warning_on_save(self, tmp_path):
589605
# https://github.com/python-pillow/Pillow/issues/835
590606
# Arrange

docs/deprecations.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ Image.show command parameter
2020
The ``command`` parameter was deprecated and will be removed in a future release.
2121
Use a subclass of ``ImageShow.Viewer`` instead.
2222

23+
Image._showxv
24+
~~~~~~~~~~~~~
25+
26+
.. deprecated:: 7.2.0
27+
28+
``Image._showxv`` has been deprecated. Use :py:meth:`~PIL.Image.Image.show`
29+
instead. If custom behaviour is required, use :py:meth:`~PIL.ImageShow.register` to add
30+
a custom :py:class:`~PIL.ImageShow.Viewer` class.
31+
2332
ImageFile.raise_ioerror
2433
~~~~~~~~~~~~~~~~~~~~~~~
2534

docs/releasenotes/7.2.0.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Image.show command parameter
4343
The ``command`` parameter was deprecated and will be removed in a future release.
4444
Use a subclass of :py:class:`PIL.ImageShow.Viewer` instead.
4545

46+
Image._showxv
47+
~~~~~~~~~~~~~
48+
49+
``Image._showxv`` has been deprecated. Use :py:meth:`~PIL.Image.Image.show`
50+
instead. If custom behaviour is required, use :py:meth:`~PIL.ImageShow.register` to add
51+
a custom :py:class:`~PIL.ImageShow.Viewer` class.
52+
4653
ImageFile.raise_ioerror
4754
~~~~~~~~~~~~~~~~~~~~~~~
4855

src/PIL/Image.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3150,12 +3150,21 @@ def register_encoder(name, encoder):
31503150

31513151

31523152
def _show(image, **options):
3153+
options["_internal_pillow"] = True
31533154
_showxv(image, **options)
31543155

31553156

31563157
def _showxv(image, title=None, **options):
31573158
from . import ImageShow
31583159

3160+
if "_internal_pillow" in options:
3161+
del options["_internal_pillow"]
3162+
else:
3163+
warnings.warn(
3164+
"_showxv is deprecated and will be removed in a future release. "
3165+
"Use Image.show instead.",
3166+
DeprecationWarning,
3167+
)
31593168
ImageShow.show(image, title, **options)
31603169

31613170

0 commit comments

Comments
 (0)