Skip to content

Commit

Permalink
Merge pull request #5776 from radarhere/removals
Browse files Browse the repository at this point in the history
Removed deprecated PILLOW_VERSION, Image.show command parameter, Image._showxv and ImageFile.raise_ioerror
  • Loading branch information
mergify[bot] committed Oct 18, 2021
2 parents 174fad7 + 20cf82b commit bc31502
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 225 deletions.
60 changes: 1 addition & 59 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import pytest

import PIL
from PIL import Image, ImageDraw, ImagePalette, ImageShow, UnidentifiedImageError
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError

from .helper import (
assert_image_equal,
Expand Down Expand Up @@ -626,22 +625,6 @@ def test_p_from_rgb_rgba(self):
expected = Image.new(mode, (100, 100), color)
assert_image_equal(im.convert(mode), expected)

def test_showxv_deprecation(self):
class TestViewer(ImageShow.Viewer):
def show_image(self, image, **options):
return True

viewer = TestViewer()
ImageShow.register(viewer, -1)

im = Image.new("RGB", (50, 50), "white")

with pytest.warns(DeprecationWarning):
Image._showxv(im)

# Restore original state
ImageShow._viewers.pop(0)

def test_no_resource_warning_on_save(self, tmp_path):
# https://github.com/python-pillow/Pillow/issues/835
# Arrange
Expand Down Expand Up @@ -813,35 +796,6 @@ def test_categories_deprecation(self):
with pytest.warns(DeprecationWarning):
assert Image.CONTAINER == 2

@pytest.mark.parametrize(
"test_module",
[PIL, Image],
)
def test_pillow_version(self, test_module):
with pytest.warns(DeprecationWarning):
assert test_module.PILLOW_VERSION == PIL.__version__

with pytest.warns(DeprecationWarning):
str(test_module.PILLOW_VERSION)

with pytest.warns(DeprecationWarning):
assert int(test_module.PILLOW_VERSION[0]) >= 7

with pytest.warns(DeprecationWarning):
assert test_module.PILLOW_VERSION < "9.9.0"

with pytest.warns(DeprecationWarning):
assert test_module.PILLOW_VERSION <= "9.9.0"

with pytest.warns(DeprecationWarning):
assert test_module.PILLOW_VERSION != "7.0.0"

with pytest.warns(DeprecationWarning):
assert test_module.PILLOW_VERSION >= "7.0.0"

with pytest.warns(DeprecationWarning):
assert test_module.PILLOW_VERSION > "7.0.0"

@pytest.mark.parametrize(
"path",
[
Expand Down Expand Up @@ -877,18 +831,6 @@ def test_fli_overrun2(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
6 changes: 0 additions & 6 deletions Tests/test_imagefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,6 @@ def test_safeblock(self):

assert_image_equal(im1, im2)

def test_raise_ioerror(self):
with pytest.raises(IOError):
with pytest.warns(DeprecationWarning) as record:
ImageFile.raise_ioerror(1)
assert len(record) == 1

def test_raise_oserror(self):
with pytest.raises(OSError):
ImageFile.raise_oserror(1)
Expand Down
76 changes: 39 additions & 37 deletions docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,6 @@ vulnerability introduced in FreeType 2.6 (:cve:`CVE-2020-15999`).

.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/

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

.. deprecated:: 7.2.0

The ``command`` parameter will be removed in Pillow 9.0.0 (2022-01-02).
Use a subclass of :py:class:`.ImageShow.Viewer` instead.

Image._showxv
~~~~~~~~~~~~~

.. deprecated:: 7.2.0

``Image._showxv`` will be removed in Pillow 9.0.0 (2022-01-02).
Use :py:meth:`.Image.Image.show` instead. If custom behaviour is required, use
:py:func:`.ImageShow.register` to add a custom :py:class:`.ImageShow.Viewer` class.

ImageFile.raise_ioerror
~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 7.2.0

``IOError`` was merged into ``OSError`` in Python 3.3.
So, ``ImageFile.raise_ioerror`` will be removed in Pillow 9.0.0 (2022-01-02).
Use ``ImageFile.raise_oserror`` instead.

PILLOW_VERSION constant
~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 5.2.0

``PILLOW_VERSION`` will be removed in Pillow 9.0.0 (2022-01-02).
Use ``__version__`` instead.

It was initially removed in Pillow 7.0.0, but brought back in 7.1.0 to give projects
more time to upgrade.

Tk/Tcl 8.4
~~~~~~~~~~

Expand Down Expand Up @@ -109,6 +72,45 @@ Removed features
Deprecated features are only removed in major releases after an appropriate
period of deprecation has passed.

PILLOW_VERSION constant
~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 5.2.0
.. versionremoved:: 9.0.0

Use ``__version__`` instead.

It was initially removed in Pillow 7.0.0, but temporarily brought back in 7.1.0
to give projects more time to upgrade.

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

.. deprecated:: 7.2.0
.. versionremoved:: 9.0.0

The ``command`` parameter has been removed. Use a subclass of
:py:class:`.ImageShow.Viewer` instead.

Image._showxv
~~~~~~~~~~~~~

.. deprecated:: 7.2.0
.. versionremoved:: 9.0.0

Use :py:meth:`.Image.Image.show` instead. If custom behaviour is required, use
:py:func:`.ImageShow.register` to add a custom :py:class:`.ImageShow.Viewer` class.

ImageFile.raise_ioerror
~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 7.2.0
.. versionremoved:: 9.0.0

``IOError`` was merged into ``OSError`` in Python 3.3.
So, ``ImageFile.raise_ioerror`` has been removed.
Use ``ImageFile.raise_oserror`` instead.

im.offset
~~~~~~~~~

Expand Down
61 changes: 61 additions & 0 deletions docs/releasenotes/9.0.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
9.0.0
-----

Backwards Incompatible Changes
==============================

PILLOW_VERSION constant
^^^^^^^^^^^^^^^^^^^^^^^

``PILLOW_VERSION`` has been removed. Use ``__version__`` instead.

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

The ``command`` parameter has been removed. Use a subclass of
:py:class:`PIL.ImageShow.Viewer` instead.

Image._showxv
~~~~~~~~~~~~~

``Image._showxv`` has been removed. Use :py:meth:`~PIL.Image.Image.show`
instead. If custom behaviour is required, use :py:meth:`~PIL.ImageShow.register` to add
a custom :py:class:`~PIL.ImageShow.Viewer` class.

ImageFile.raise_ioerror
~~~~~~~~~~~~~~~~~~~~~~~

``IOError`` was merged into ``OSError`` in Python 3.3. So, ``ImageFile.raise_ioerror``
has been removed. Use ``ImageFile.raise_oserror`` instead.

API Changes
===========

TODO
^^^^

TODO

API Additions
=============

TODO
^^^^

TODO

Security
========

TODO
^^^^

TODO

Other Changes
=============

TODO
^^^^

TODO
1 change: 1 addition & 0 deletions docs/releasenotes/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ expected to be backported to earlier versions.
.. toctree::
:maxdepth: 2

9.0.0
8.4.0
8.3.2
8.3.1
Expand Down
65 changes: 14 additions & 51 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,28 @@
ElementTree = None

# VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION is deprecated and will be removed in a future release.
# PILLOW_VERSION was removed in Pillow 9.0.0.
# Use __version__ instead.
from . import (
ImageMode,
TiffTags,
UnidentifiedImageError,
__version__,
_plugins,
_raise_version_warning,
)
from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins
from ._binary import i32le
from ._util import deferred_error, isPath

if sys.version_info >= (3, 7):

def __getattr__(name):
if name == "PILLOW_VERSION":
_raise_version_warning()
return __version__
else:
categories = {"NORMAL": 0, "SEQUENCE": 1, "CONTAINER": 2}
if name in categories:
warnings.warn(
"Image categories are deprecated and will be removed in Pillow 10 "
"(2023-01-02). Use is_animated instead.",
DeprecationWarning,
stacklevel=2,
)
return categories[name]
categories = {"NORMAL": 0, "SEQUENCE": 1, "CONTAINER": 2}
if name in categories:
warnings.warn(
"Image categories are deprecated and will be removed in Pillow 10 "
"(2023-01-02). Use is_animated instead.",
DeprecationWarning,
stacklevel=2,
)
return categories[name]
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")


else:

from . import PILLOW_VERSION

# Silence warning
assert PILLOW_VERSION

# categories
NORMAL = 0
SEQUENCE = 1
Expand Down Expand Up @@ -2264,7 +2247,7 @@ def seek(self, frame):
if frame != 0:
raise EOFError

def show(self, title=None, command=None):
def show(self, title=None):
"""
Displays this image. This method is mainly intended for debugging purposes.
Expand All @@ -2284,14 +2267,7 @@ def show(self, title=None, command=None):
: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 Pillow 9 "
"(2022-01-02). Use a subclass of ImageShow.Viewer instead.",
DeprecationWarning,
)

_show(self, title=title, command=command)
_show(self, title=title)

def split(self):
"""
Expand Down Expand Up @@ -3250,22 +3226,9 @@ def register_encoder(name, encoder):


def _show(image, **options):
options["_internal_pillow"] = True
_showxv(image, **options)


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

if "_internal_pillow" in options:
del options["_internal_pillow"]
else:
warnings.warn(
"_showxv is deprecated and will be removed in Pillow 9 (2022-01-02). "
"Use Image.show instead.",
DeprecationWarning,
)
ImageShow.show(image, title, **options)
ImageShow.show(image, **options)


# --------------------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import io
import struct
import sys
import warnings

from . import Image
from ._util import isPath
Expand Down Expand Up @@ -67,15 +66,6 @@ def raise_oserror(error):
raise OSError(message + " when reading image file")


def raise_ioerror(error):
warnings.warn(
"raise_ioerror is deprecated and will be removed in Pillow 9 (2022-01-02). "
"Use raise_oserror instead.",
DeprecationWarning,
)
return raise_oserror(error)


def _tilesort(t):
# sort on offset
return t[2]
Expand Down

0 comments on commit bc31502

Please sign in to comment.