mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-06 06:03:14 +03:00
Merge pull request #5776 from radarhere/removals
Removed deprecated PILLOW_VERSION, Image.show command parameter, Image._showxv and ImageFile.raise_ioerror
This commit is contained in:
commit
bc31502183
|
@ -6,8 +6,7 @@ import tempfile
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import PIL
|
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError
|
||||||
from PIL import Image, ImageDraw, ImagePalette, ImageShow, UnidentifiedImageError
|
|
||||||
|
|
||||||
from .helper import (
|
from .helper import (
|
||||||
assert_image_equal,
|
assert_image_equal,
|
||||||
|
@ -626,22 +625,6 @@ class TestImage:
|
||||||
expected = Image.new(mode, (100, 100), color)
|
expected = Image.new(mode, (100, 100), color)
|
||||||
assert_image_equal(im.convert(mode), expected)
|
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):
|
def test_no_resource_warning_on_save(self, tmp_path):
|
||||||
# https://github.com/python-pillow/Pillow/issues/835
|
# https://github.com/python-pillow/Pillow/issues/835
|
||||||
# Arrange
|
# Arrange
|
||||||
|
@ -813,35 +796,6 @@ class TestImage:
|
||||||
with pytest.warns(DeprecationWarning):
|
with pytest.warns(DeprecationWarning):
|
||||||
assert Image.CONTAINER == 2
|
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(
|
@pytest.mark.parametrize(
|
||||||
"path",
|
"path",
|
||||||
[
|
[
|
||||||
|
@ -877,18 +831,6 @@ class TestImage:
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
assert str(e) == "buffer overrun when reading image file"
|
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:
|
class MockEncoder:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -94,12 +94,6 @@ class TestImageFile:
|
||||||
|
|
||||||
assert_image_equal(im1, im2)
|
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):
|
def test_raise_oserror(self):
|
||||||
with pytest.raises(OSError):
|
with pytest.raises(OSError):
|
||||||
ImageFile.raise_oserror(1)
|
ImageFile.raise_oserror(1)
|
||||||
|
|
|
@ -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/
|
.. _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
|
Tk/Tcl 8.4
|
||||||
~~~~~~~~~~
|
~~~~~~~~~~
|
||||||
|
|
||||||
|
@ -109,6 +72,45 @@ Removed features
|
||||||
Deprecated features are only removed in major releases after an appropriate
|
Deprecated features are only removed in major releases after an appropriate
|
||||||
period of deprecation has passed.
|
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
|
im.offset
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
|
|
61
docs/releasenotes/9.0.0.rst
Normal file
61
docs/releasenotes/9.0.0.rst
Normal file
|
@ -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
|
|
@ -14,6 +14,7 @@ expected to be backported to earlier versions.
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
|
9.0.0
|
||||||
8.4.0
|
8.4.0
|
||||||
8.3.2
|
8.3.2
|
||||||
8.3.1
|
8.3.1
|
||||||
|
|
|
@ -45,45 +45,28 @@ except ImportError:
|
||||||
ElementTree = None
|
ElementTree = None
|
||||||
|
|
||||||
# VERSION was removed in Pillow 6.0.0.
|
# 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.
|
# Use __version__ instead.
|
||||||
from . import (
|
from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins
|
||||||
ImageMode,
|
|
||||||
TiffTags,
|
|
||||||
UnidentifiedImageError,
|
|
||||||
__version__,
|
|
||||||
_plugins,
|
|
||||||
_raise_version_warning,
|
|
||||||
)
|
|
||||||
from ._binary import i32le
|
from ._binary import i32le
|
||||||
from ._util import deferred_error, isPath
|
from ._util import deferred_error, isPath
|
||||||
|
|
||||||
if sys.version_info >= (3, 7):
|
if sys.version_info >= (3, 7):
|
||||||
|
|
||||||
def __getattr__(name):
|
def __getattr__(name):
|
||||||
if name == "PILLOW_VERSION":
|
categories = {"NORMAL": 0, "SEQUENCE": 1, "CONTAINER": 2}
|
||||||
_raise_version_warning()
|
if name in categories:
|
||||||
return __version__
|
warnings.warn(
|
||||||
else:
|
"Image categories are deprecated and will be removed in Pillow 10 "
|
||||||
categories = {"NORMAL": 0, "SEQUENCE": 1, "CONTAINER": 2}
|
"(2023-01-02). Use is_animated instead.",
|
||||||
if name in categories:
|
DeprecationWarning,
|
||||||
warnings.warn(
|
stacklevel=2,
|
||||||
"Image categories are deprecated and will be removed in Pillow 10 "
|
)
|
||||||
"(2023-01-02). Use is_animated instead.",
|
return categories[name]
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
return categories[name]
|
|
||||||
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
from . import PILLOW_VERSION
|
|
||||||
|
|
||||||
# Silence warning
|
|
||||||
assert PILLOW_VERSION
|
|
||||||
|
|
||||||
# categories
|
# categories
|
||||||
NORMAL = 0
|
NORMAL = 0
|
||||||
SEQUENCE = 1
|
SEQUENCE = 1
|
||||||
|
@ -2264,7 +2247,7 @@ class Image:
|
||||||
if frame != 0:
|
if frame != 0:
|
||||||
raise EOFError
|
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.
|
Displays this image. This method is mainly intended for debugging purposes.
|
||||||
|
|
||||||
|
@ -2284,14 +2267,7 @@ class Image:
|
||||||
:param title: Optional title to use for the image window, where possible.
|
:param title: Optional title to use for the image window, where possible.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if command is not None:
|
_show(self, title=title)
|
||||||
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)
|
|
||||||
|
|
||||||
def split(self):
|
def split(self):
|
||||||
"""
|
"""
|
||||||
|
@ -3250,22 +3226,9 @@ def register_encoder(name, encoder):
|
||||||
|
|
||||||
|
|
||||||
def _show(image, **options):
|
def _show(image, **options):
|
||||||
options["_internal_pillow"] = True
|
|
||||||
_showxv(image, **options)
|
|
||||||
|
|
||||||
|
|
||||||
def _showxv(image, title=None, **options):
|
|
||||||
from . import ImageShow
|
from . import ImageShow
|
||||||
|
|
||||||
if "_internal_pillow" in options:
|
ImageShow.show(image, **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)
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
import io
|
import io
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
|
||||||
|
|
||||||
from . import Image
|
from . import Image
|
||||||
from ._util import isPath
|
from ._util import isPath
|
||||||
|
@ -67,15 +66,6 @@ def raise_oserror(error):
|
||||||
raise OSError(message + " when reading image file")
|
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):
|
def _tilesort(t):
|
||||||
# sort on offset
|
# sort on offset
|
||||||
return t[2]
|
return t[2]
|
||||||
|
|
|
@ -13,72 +13,12 @@ Use PIL.__version__ for this Pillow version.
|
||||||
;-)
|
;-)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
|
||||||
import warnings
|
|
||||||
|
|
||||||
from . import _version
|
from . import _version
|
||||||
|
|
||||||
# VERSION was removed in Pillow 6.0.0.
|
# VERSION was removed in Pillow 6.0.0.
|
||||||
__version__ = _version.__version__
|
# PILLOW_VERSION was removed in Pillow 9.0.0.
|
||||||
|
|
||||||
|
|
||||||
# PILLOW_VERSION is deprecated and will be removed in a future release.
|
|
||||||
# Use __version__ instead.
|
# Use __version__ instead.
|
||||||
def _raise_version_warning():
|
__version__ = _version.__version__
|
||||||
warnings.warn(
|
|
||||||
"PILLOW_VERSION is deprecated and will be removed in Pillow 9 (2022-01-02). "
|
|
||||||
"Use __version__ instead.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=3,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info >= (3, 7):
|
|
||||||
|
|
||||||
def __getattr__(name):
|
|
||||||
if name == "PILLOW_VERSION":
|
|
||||||
_raise_version_warning()
|
|
||||||
return __version__
|
|
||||||
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
class _Deprecated_Version(str):
|
|
||||||
def __str__(self):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__str__()
|
|
||||||
|
|
||||||
def __getitem__(self, key):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__getitem__(key)
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__eq__(other)
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__ne__(other)
|
|
||||||
|
|
||||||
def __gt__(self, other):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__gt__(other)
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__lt__(other)
|
|
||||||
|
|
||||||
def __ge__(self, other):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__gt__(other)
|
|
||||||
|
|
||||||
def __le__(self, other):
|
|
||||||
_raise_version_warning()
|
|
||||||
return super().__lt__(other)
|
|
||||||
|
|
||||||
PILLOW_VERSION = _Deprecated_Version(__version__)
|
|
||||||
|
|
||||||
del _version
|
del _version
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user