Raise a DeprecationWarning when comparing PILLOW_VERSION

This commit is contained in:
Andrew Murray 2020-03-30 21:53:02 +11:00
parent afa758eb33
commit 027d180eda
2 changed files with 32 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import os
import shutil
import tempfile
import PIL
import pytest
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError
@ -608,6 +609,13 @@ class TestImage:
assert not fp.closed
def test_pillow_version(self):
with pytest.warns(DeprecationWarning):
assert PIL.__version__ == PIL.PILLOW_VERSION
with pytest.warns(DeprecationWarning):
assert int(PIL.PILLOW_VERSION[0]) >= 7
def test_overrun(self):
for file in [
"fli_overrun.bin",

View File

@ -13,12 +13,35 @@ Use PIL.__version__ for this Pillow version.
;-)
"""
import warnings
from . import _version
# VERSION was removed in Pillow 6.0.0.
__version__ = _version.__version__
class _Deprecated_Version(str):
def _raise_warning(self):
warnings.warn(
"PILLOW_VERSION is deprecated and will be removed in a future release. "
"Use __version__ instead.",
DeprecationWarning,
stacklevel=3,
)
def __getitem__(self, key):
self._raise_warning()
return super().__getitem__(key)
def __eq__(self, other):
self._raise_warning()
return super().__eq__(other)
# PILLOW_VERSION is deprecated and will be removed in a future release.
# Use __version__ instead.
PILLOW_VERSION = __version__ = _version.__version__
PILLOW_VERSION = _Deprecated_Version(__version__)
del _version