Skip to content

[types-pillow] update deprecated PIL.Image constants#8419

Merged
hauntsaninja merged 11 commits intopython:masterfrom
owocado:update-deprecated-PIL-Image-constants
Jul 28, 2022
Merged

[types-pillow] update deprecated PIL.Image constants#8419
hauntsaninja merged 11 commits intopython:masterfrom
owocado:update-deprecated-PIL-Image-constants

Conversation

@owocado
Copy link
Contributor

@owocado owocado commented Jul 28, 2022

Hi,

As per my opened issue #8366 , this PR updates deprecated PIL.Image constants (since Pillow >9.1.0) to the documented ones as per Pillow library documentation.
Pillow docs for reference: https://pillow.readthedocs.io/en/stable/deprecations.html#constants
Reference to Pillow v9.1.0 release notes where the deprecation notice was intially documented: https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#constants

I would like to wholeheartedly thank @hauntsaninja for providing the guidance on how and where to make necessary changes and the valuable opportunity to contribute to this open source project.

I have read the contribution guidelines of this project and tried to follow them to the best of my abilities. Please guide me on right path in case I have made the changes inappropriately as this is my first PR on this project and I am a bit unsure if I have done it right! 😅

This PR resolves #8366

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@srittau
Copy link
Collaborator

srittau commented Jul 28, 2022

Thanks! The old numeric constants still work (with a warning), right? In that case we should keep them for now. The primer output show that a quite a few projects still use the outdated constants.

Edit: By "keep them" I mean allow both the constants and the enum for now.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@owocado
Copy link
Contributor Author

owocado commented Jul 28, 2022

Yes you are right. Old deprecated constants still work and are stated for removal in Pillow 10.0.0 onwards as per the documentation. I have tried to incorporate changes in above commits to allow both the old deprecated constants and new enums but the stubtest CI suddenly fails. I am unsure why, though I did make attempt to fix it but to no avail. If someone can guide me in the right direction to pass the failing CI, it would be tremendously appreciated. Thank you for your valuable time!

Edit: passed the CI checks (including stubtest)

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@AlexWaygood
Copy link
Member

One of us will take a look soon and try to help you out with the primer diff :)

@owocado
Copy link
Contributor Author

owocado commented Jul 28, 2022

ok, thank you very much!

@AlexWaygood
Copy link
Member

ok, thank you very much!

Thank you for the PR!

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for filing the issue and the fix, this lgtm!

Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
@hauntsaninja
Copy link
Collaborator

There's a similar change you could make to def transpose by making method be Transpose as well as Literal (Github wouldn't let me add the suggestion in the code review)

@github-actions

This comment has been minimized.

@owocado
Copy link
Contributor Author

owocado commented Jul 28, 2022

There's a similar change you could make to def transpose by making method be Transpose as well as Literal (Github wouldn't let me add the suggestion in the code review)

makes sense. I have made the changes to address that! 👍🏽

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

vision (https://github.com/pytorch/vision)
- torchvision/transforms/_pil_constants.py:7: error: Module has no attribute "Resampling"  [attr-defined]
- torchvision/transforms/_pil_constants.py:8: error: Module has no attribute "Resampling"  [attr-defined]
- torchvision/transforms/_pil_constants.py:9: error: Module has no attribute "Resampling"  [attr-defined]
- torchvision/transforms/_pil_constants.py:10: error: Module has no attribute "Resampling"  [attr-defined]
- torchvision/transforms/_pil_constants.py:12: error: Module has no attribute "Transform"  [attr-defined]
- torchvision/transforms/_pil_constants.py:13: error: Module has no attribute "Transpose"  [attr-defined]
- torchvision/transforms/_pil_constants.py:14: error: Module has no attribute "Transpose"  [attr-defined]
- torchvision/transforms/_pil_constants.py:15: error: Module has no attribute "Transform"  [attr-defined]
+ torchvision/transforms/_pil_constants.py:17: error: Incompatible types in assignment (expression has type "Literal[3]", variable has type "Resampling")  [assignment]
+ torchvision/transforms/_pil_constants.py:18: error: Incompatible types in assignment (expression has type "Literal[2]", variable has type "Resampling")  [assignment]
+ torchvision/transforms/_pil_constants.py:19: error: Incompatible types in assignment (expression has type "Literal[0]", variable has type "Resampling")  [assignment]
+ torchvision/transforms/_pil_constants.py:20: error: Incompatible types in assignment (expression has type "Literal[2]", variable has type "Resampling")  [assignment]
+ torchvision/transforms/_pil_constants.py:22: error: Incompatible types in assignment (expression has type "Literal[0]", variable has type "Transform")  [assignment]
+ torchvision/transforms/_pil_constants.py:23: error: Incompatible types in assignment (expression has type "Literal[0]", variable has type "Transpose")  [assignment]
+ torchvision/transforms/_pil_constants.py:24: error: Incompatible types in assignment (expression has type "Literal[1]", variable has type "Transpose")  [assignment]
+ torchvision/transforms/_pil_constants.py:25: error: Incompatible types in assignment (expression has type "Literal[2]", variable has type "Transform")  [assignment]
- torchvision/transforms/functional_pil.py:252: error: Argument 2 to "resize" of "Image" has incompatible type "int"; expected "Optional[Literal[0, 1, 2, 3, 4, 5]]"  [arg-type]
+ torchvision/transforms/functional_pil.py:252: error: Argument 2 to "resize" of "Image" has incompatible type "int"; expected "Union[Resampling, Literal[0, 1, 2, 3, 4, 5], None]"  [arg-type]
- torchvision/transforms/functional_pil.py:297: error: Argument 4 to "transform" of "Image" has incompatible type "int"; expected "Literal[0, 1, 2, 3, 4, 5]"  [arg-type]
+ torchvision/transforms/functional_pil.py:297: error: Argument 4 to "transform" of "Image" has incompatible type "int"; expected "Union[Resampling, Literal[0, 1, 2, 3, 4, 5]]"  [arg-type]
- torchvision/transforms/functional_pil.py:314: error: Argument 2 to "rotate" of "Image" has incompatible type "int"; expected "Literal[0, 1, 2, 3, 4, 5]"  [arg-type]
+ torchvision/transforms/functional_pil.py:314: error: Argument 2 to "rotate" of "Image" has incompatible type "int"; expected "Union[Resampling, Literal[0, 1, 2, 3, 4, 5]]"  [arg-type]
- torchvision/transforms/functional_pil.py:330: error: Argument 4 to "transform" of "Image" has incompatible type "int"; expected "Literal[0, 1, 2, 3, 4, 5]"  [arg-type]
+ torchvision/transforms/functional_pil.py:330: error: Argument 4 to "transform" of "Image" has incompatible type "int"; expected "Union[Resampling, Literal[0, 1, 2, 3, 4, 5]]"  [arg-type]

@hauntsaninja hauntsaninja merged commit f074ef6 into python:master Jul 28, 2022
@owocado owocado deleted the update-deprecated-PIL-Image-constants branch July 28, 2022 21:20
@hauntsaninja
Copy link
Collaborator

Thank you again! :-)

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.

[Pillow] Module has no attribute "Resampling"

4 participants