mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Raise a DeprecationWarning when comparing PILLOW_VERSION
This commit is contained in:
parent
afa758eb33
commit
027d180eda
|
@ -3,6 +3,7 @@ import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
|
import PIL
|
||||||
import pytest
|
import pytest
|
||||||
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError
|
from PIL import Image, ImageDraw, ImagePalette, UnidentifiedImageError
|
||||||
|
|
||||||
|
@ -608,6 +609,13 @@ class TestImage:
|
||||||
|
|
||||||
assert not fp.closed
|
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):
|
def test_overrun(self):
|
||||||
for file in [
|
for file in [
|
||||||
"fli_overrun.bin",
|
"fli_overrun.bin",
|
||||||
|
|
|
@ -13,12 +13,35 @@ Use PIL.__version__ for this Pillow version.
|
||||||
;-)
|
;-)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
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__
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
# PILLOW_VERSION is deprecated and will be removed in a future release.
|
||||||
# Use __version__ instead.
|
# Use __version__ instead.
|
||||||
PILLOW_VERSION = __version__ = _version.__version__
|
PILLOW_VERSION = _Deprecated_Version(__version__)
|
||||||
|
|
||||||
del _version
|
del _version
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user