-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Re-add deprecated PILLOW_VERSION to give projects more time to upgrade #4494
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
Conversation
|
Does |
|
No, but we can do something like https://stackoverflow.com/a/880550/724176: # __init__.py
import sys
import warnings
class _Deprecated_Version(object):
def deprecated_version(self):
warnings.warn(
"PILLOW_VERSION is deprecated and will be removed in a future release. "
"Use __version__ instead.",
DeprecationWarning,
stacklevel=2,
)
return __version__
PILLOW_VERSION = property(deprecated_version)
sys.modules[__name__] = _Deprecated_Version()# 1.py
import PIL
print(dir(PIL))
print(PIL.PILLOW_VERSION)$ python -Wall 1.py
['PILLOW_VERSION', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'deprecated_version']
1.py:5: DeprecationWarning: PILLOW_VERSION is deprecated and will be removed in a future release. Use __version__ instead.
print(PIL.PILLOW_VERSION)
7.1.0.dev0 |
|
However, the >>> from PIL import Image
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Image' from '<unknown module name>' (unknown location) |
|
Alternatively, use PEP 562 to warn for at least Python 3.7+ (https://stackoverflow.com/a/57263518/724176), put this in both if sys.version_info >= (3, 7):
def __getattr__(name):
if name == 'PILLOW_VERSION':
warnings.warn(
"PILLOW_VERSION is deprecated and will be removed in a future release. "
"Use __version__ instead.",
DeprecationWarning,
stacklevel=2,
)
return __version__
raise AttributeError("module '{}' has no attribute '{}'".format(__name__, name))
else:
PILLOW_VERSION = __version__# 1.py
import PIL
from PIL import Image
print(PIL.PILLOW_VERSION)
print(Image.PILLOW_VERSION)$ python3.6 -Wall 1.py
7.1.0.dev0
7.1.0.dev0$ python3.7 -Wall 1.py
1.py:5: DeprecationWarning: PILLOW_VERSION is deprecated and will be removed in a future release. Use __version__ instead.
print(PIL.PILLOW_VERSION)
7.1.0.dev0
1.py:6: DeprecationWarning: PILLOW_VERSION is deprecated and will be removed in a future release. Use __version__ instead.
print(Image.PILLOW_VERSION)
7.1.0.dev0Of last month's pip downloads, there were about 7.2m downloads for Python 3.5+. About 52% were 3.5-3.6, about 48% for 3.7+. |
Raise a DeprecationWarning when comparing PILLOW_VERSION
|
Thanks to @radarhere, updated via hugovk#46 with deprecation warnings via a class for some common uses for Python 3.5-3.6, and using PEP 562/ |
PILLOW_VERSIONwas deprecated in Pillow 5.2.0 in July 2018 (#3090, #3782) and removed in 7.0.0 in January 2020 (#4107).However, it didn't raise a deprecation warning. The removal has caused problems for users of torchvision.
torchvision had already updated to use
__version__in October 2019 (pytorch/vision#1501) but when Pillow 7.0.0 came out on 2020-01-02, had not yet released it (pytorch/vision#1712).The fixed torchvision 0.5.0 was released on 2020-01-16.
However, some people are still having difficulties using torchvision 0.5.0 and Pillow 7.0.0 (pytorch/vision#1712) and are pinning to old Pillow versions or editing the source. As it's not much code for us, I suggest re-adding
PILLOW_VERSIONuntil some unspecified future release.As before, this still doesn't raise a deprecation warning. I don't know if it's possible to raise one when calling a constant (or calling something that looks like calling a constant), but that would be welcome for 7.1.0 or a later release.