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

Deprecated categories #5351

Merged
merged 2 commits into from Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions Tests/test_image.py
@@ -1,6 +1,7 @@
import io
import os
import shutil
import sys
import tempfile

import pytest
Expand Down Expand Up @@ -769,6 +770,20 @@ def test_exif_ifd(self):
reloaded_exif.load(exif.tobytes())
assert reloaded_exif.get_ifd(0x8769) == exif.get_ifd(0x8769)

@pytest.mark.skipif(
sys.version_info < (3, 7), reason="Python 3.7 or greater required"
)
def test_categories_deprecation(self):
with pytest.warns(DeprecationWarning):
assert hopper().category == 0

with pytest.warns(DeprecationWarning):
assert Image.NORMAL == 0
with pytest.warns(DeprecationWarning):
assert Image.SEQUENCE == 1
with pytest.warns(DeprecationWarning):
assert Image.CONTAINER == 2

@pytest.mark.parametrize(
"test_module",
[PIL, Image],
Expand Down
12 changes: 12 additions & 0 deletions docs/deprecations.rst
Expand Up @@ -33,6 +33,18 @@ Tk/Tcl 8.4
Support for Tk/Tcl 8.4 is deprecated and will be removed in Pillow 10.0.0 (2023-01-02),
when Tk/Tcl 8.5 will be the minimum supported.

Categories
~~~~~~~~~~

.. deprecated:: 8.2.0

``im.category`` is deprecated and will be removed in Pillow 10.0.0 (2023-01-02),
along with the related ``Image.NORMAL``, ``Image.SEQUENCE`` and
``Image.CONTAINER`` attributes.

To determine if an image has multiple frames or not,
``getattr(im, "is_animated", False)`` can be used instead.

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

Expand Down
7 changes: 0 additions & 7 deletions docs/reference/Image.rst
Expand Up @@ -502,10 +502,3 @@ Used to specify the quantization method to use for the :meth:`~Image.quantize` m

Check support using :py:func:`PIL.features.check_feature`
with ``feature="libimagequant"``.

.. comment: These are not referenced anywhere?
Categories
^^^^^^^^^^
.. data:: NORMAL
.. data:: SEQUENCE
.. data:: CONTAINER
10 changes: 10 additions & 0 deletions docs/releasenotes/8.2.0.rst
Expand Up @@ -10,6 +10,16 @@ Tk/Tcl 8.4
Support for Tk/Tcl 8.4 is deprecated and will be removed in Pillow 10.0.0 (2023-01-02),
when Tk/Tcl 8.5 will be the minimum supported.

Categories
^^^^^^^^^^

``im.category`` is deprecated and will be removed in Pillow 10.0.0 (2023-01-02),
along with the related ``Image.NORMAL``, ``Image.SEQUENCE`` and
``Image.CONTAINER`` attributes.

To determine if an image has multiple frames or not,
``getattr(im, "is_animated", False)`` can be used instead.

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

Expand Down
35 changes: 28 additions & 7 deletions src/PIL/Image.py
Expand Up @@ -59,6 +59,16 @@ 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]
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")


Expand All @@ -69,6 +79,11 @@ def __getattr__(name):
# Silence warning
assert PILLOW_VERSION

# categories
NORMAL = 0
SEQUENCE = 1
CONTAINER = 2


logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -187,11 +202,6 @@ def isImageType(t):
FASTOCTREE = 2
LIBIMAGEQUANT = 3

# categories
NORMAL = 0
SEQUENCE = 1
CONTAINER = 2

if hasattr(core, "DEFAULT_STRATEGY"):
DEFAULT_STRATEGY = core.DEFAULT_STRATEGY
FILTERED = core.FILTERED
Expand Down Expand Up @@ -535,11 +545,22 @@ def __init__(self):
self._size = (0, 0)
self.palette = None
self.info = {}
self.category = NORMAL
self._category = 0
self.readonly = 0
self.pyaccess = None
self._exif = None

def __getattr__(self, name):
if name == "category":
warnings.warn(
"Image categories are deprecated and will be removed in Pillow 10 "
"(2023-01-02). Use is_animated instead.",
DeprecationWarning,
stacklevel=2,
)
return self._category
raise AttributeError(name)

@property
def width(self):
return self.size[0]
Expand Down Expand Up @@ -648,7 +669,7 @@ def __eq__(self, other):
and self.mode == other.mode
and self.size == other.size
and self.info == other.info
and self.category == other.category
and self._category == other._category
and self.readonly == other.readonly
and self.getpalette() == other.getpalette()
and self.tobytes() == other.tobytes()
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/MicImagePlugin.py
Expand Up @@ -68,7 +68,7 @@ def _open(self):
self.is_animated = self._n_frames > 1

if len(self.images) > 1:
self.category = Image.CONTAINER
self._category = Image.CONTAINER

self.seek(0)

Expand Down