Skip to content

Add deprecations helper#6184

Merged
radarhere merged 6 commits into
python-pillow:mainfrom
hugovk:deprecations-helper
Apr 16, 2022
Merged

Add deprecations helper#6184
radarhere merged 6 commits into
python-pillow:mainfrom
hugovk:deprecations-helper

Conversation

@hugovk

@hugovk hugovk commented Apr 5, 2022

Copy link
Copy Markdown
Member

I noticed in a project using Pillow that the deprecation warning resulted in a very long traceback:

=================================== FAILURES ===================================
  ___________________________________ test_pil ___________________________________
  
      def test_pil():
          image_manager = PILImageManager("RGB")
          osm = OSMManager(image_manager=image_manager)
          image, bounds = osm.create_osm_image((30, 31, -117, -116), 9)
          wh_ratio = float(image.size[0]) / image.size[1]
  >       image2 = image.resize((int([80](https://github.com/hugovk/osmviz/runs/5822426177?check_suite_focus=true#step:5:80)0 * wh_ratio), 800), Image.ANTIALIAS)
  
  test/functional/test_manager.py:11: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  name = 'ANTIALIAS'
  
      def __getattr__(name):
          deprecated = "deprecated and will be removed in Pillow 10 (2023-07-01). "
          categories = {"NORMAL": 0, "SEQUENCE": 1, "CONTAINER": 2}
          if name in categories:
              warnings.warn(
                  "Image categories are " + deprecated + "Use is_animated instead.",
                  DeprecationWarning,
                  stacklevel=2,
              )
              return categories[name]
          elif name in ("NEAREST", "NONE"):
              warnings.warn(
                  name
                  + " is "
                  + deprecated
                  + "Use Resampling.NEAREST or Dither.NONE instead.",
                  DeprecationWarning,
                  stacklevel=2,
              )
              return 0
          old_resampling = {
              "LINEAR": "BILINEAR",
              "CUBIC": "BICUBIC",
              "ANTIALIAS": "LANCZOS",
          }
          if name in old_resampling:
  >           warnings.warn(
                  name
                  + " is "
                  + deprecated
                  + "Use Resampling."
                  + old_resampling[name]
                  + " instead.",
                  DeprecationWarning,
                  stacklevel=2,
              )
  E           DeprecationWarning: ANTIALIAS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead.
  
  .tox/py310/lib/python3.10/site-packages/PIL/Image.py:[82](https://github.com/hugovk/osmviz/runs/5822426177?check_suite_focus=true#step:5:82): DeprecationWarning
  ----------------------------- Captured stdout call -----------------------------

https://github.com/hugovk/osmviz/runs/5822426177?check_suite_focus=true

I was going to shorten them using f-strings, but thought it could be useful to create a deprecation helper function.

@nulano

nulano commented Apr 5, 2022

Copy link
Copy Markdown
Contributor

@hugovk hugovk force-pushed the deprecations-helper branch from 4bf953b to 4cb8e4b Compare April 6, 2022 10:20
@hugovk

hugovk commented Apr 6, 2022

Copy link
Copy Markdown
Member Author

Comment thread Tests/test_deprecate.py Outdated
Comment thread Tests/test_deprecate.py Outdated
Co-authored-by: Andrew Murray <[email protected]>
Comment thread src/PIL/_deprecate.py Outdated
Comment thread src/PIL/_deprecate.py Outdated
@nulano nulano mentioned this pull request Apr 11, 2022
Comment thread src/PIL/Image.py Outdated
Co-authored-by: Andrew Murray <[email protected]>
@radarhere radarhere merged commit 535c457 into python-pillow:main Apr 16, 2022
@hugovk hugovk deleted the deprecations-helper branch April 16, 2022 09:05
@radarhere radarhere mentioned this pull request Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants