mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Raise warning for more operations
This commit is contained in:
parent
027d180eda
commit
7597a9fbfd
|
@ -611,11 +611,29 @@ class TestImage:
|
|||
|
||||
def test_pillow_version(self):
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert PIL.__version__ == PIL.PILLOW_VERSION
|
||||
assert PIL.PILLOW_VERSION == PIL.__version__
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
str(PIL.PILLOW_VERSION)
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert int(PIL.PILLOW_VERSION[0]) >= 7
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert PIL.PILLOW_VERSION < "9.9.0"
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert PIL.PILLOW_VERSION <= "9.9.0"
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert PIL.PILLOW_VERSION != "7.0.0"
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert PIL.PILLOW_VERSION >= "7.0.0"
|
||||
|
||||
with pytest.warns(DeprecationWarning):
|
||||
assert PIL.PILLOW_VERSION > "7.0.0"
|
||||
|
||||
def test_overrun(self):
|
||||
for file in [
|
||||
"fli_overrun.bin",
|
||||
|
|
|
@ -42,18 +42,32 @@ from pathlib import Path
|
|||
# PILLOW_VERSION is deprecated and will be removed in a future release.
|
||||
# Use __version__ instead.
|
||||
from . import (
|
||||
PILLOW_VERSION,
|
||||
ImageMode,
|
||||
TiffTags,
|
||||
UnidentifiedImageError,
|
||||
__version__,
|
||||
_plugins,
|
||||
_raise_version_warning,
|
||||
)
|
||||
from ._binary import i8, i32le
|
||||
from ._util import deferred_error, isPath
|
||||
|
||||
# Silence warning
|
||||
assert PILLOW_VERSION
|
||||
if sys.version_info >= (3, 7):
|
||||
|
||||
def __getattr__(name):
|
||||
if name == "PILLOW_VERSION":
|
||||
_raise_version_warning()
|
||||
return __version__
|
||||
raise AttributeError("module '{}' has no attribute '{}'".format(__name__, name))
|
||||
|
||||
|
||||
else:
|
||||
|
||||
from . import PILLOW_VERSION
|
||||
|
||||
# Silence warning
|
||||
assert PILLOW_VERSION
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ Use PIL.__version__ for this Pillow version.
|
|||
;-)
|
||||
"""
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from . import _version
|
||||
|
@ -21,27 +22,62 @@ from . import _version
|
|||
__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 = _Deprecated_Version(__version__)
|
||||
def _raise_version_warning():
|
||||
warnings.warn(
|
||||
"PILLOW_VERSION is deprecated and will be removed in a future release. "
|
||||
"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("module '{}' has no attribute '{}'".format(__name__, 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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user