lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.39k stars 674 forks source link

Change constants usage to remove pillow future updates warnings #282

Closed alfreedom closed 1 year ago

alfreedom commented 2 years ago

Change constants usage to fix the deprecation warnings for PIL >= 10

This is a simple change to use the constants from the Enum defined in the PIL.Image module to remove the deprecation messages from pillow:

.../qrcode/image/styledpil.py:49: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
    self.embeded_image_resample = kwargs.get("embeded_image_resample", Image.LANCZOS)

.../qrcode/image/styles/moduledrawers.py:128: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
    self.NW_ROUND = base.resize((self.corner_width, self.corner_width), Image.LANCZOS)

.../qrcode/image/styles/moduledrawers.py:129: DeprecationWarning: FLIP_TOP_BOTTOM is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.FLIP_TOP_BOTTOM instead.
    self.SW_ROUND = self.NW_ROUND.transpose(Image.FLIP_TOP_BOTTOM)

.../qrcode/image/styles/moduledrawers.py:130: DeprecationWarning: ROTATE_180 is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.ROTATE_180 instead.
    self.SE_ROUND = self.NW_ROUND.transpose(Image.ROTATE_180)

.../qrcode/image/styles/moduledrawers.py:131: DeprecationWarning: FLIP_LEFT_RIGHT is deprecated and will be removed in Pillow 10 (2023-07-01). Use Transpose.FLIP_LEFT_RIGHT instead.
    self.NE_ROUND = self.NW_ROUND.transpose(Image.FLIP_LEFT_RIGHT)
SmileyChris commented 2 years ago

(rebase this against the latest master and it should fix the failing tests)

alfreedom commented 2 years ago

Hey, this looks good. Can you find which version of pillow these constants were moved, and add that as a minimum version for pillow in setup.cfg?

Sure, this deprecation was informed in the 9.1.0 release version so this may be the minimum required version.

Release of pillow 10.0.0 will be until 2023-07-01