[types-pillow] update deprecated PIL.Image constants#8419
[types-pillow] update deprecated PIL.Image constants#8419hauntsaninja merged 11 commits intopython:masterfrom owocado:update-deprecated-PIL-Image-constants
PIL.Image constants#8419Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
One of us will take a look soon and try to help you out with the primer diff :) |
|
ok, thank you very much! |
Thank you for the PR! |
hauntsaninja
left a comment
There was a problem hiding this comment.
Thank you for filing the issue and the fix, this lgtm!
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
|
There's a similar change you could make to |
This comment has been minimized.
This comment has been minimized.
makes sense. I have made the changes to address that! 👍🏽 |
|
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]
|
|
Thank you again! :-) |
Hi,
As per my opened issue #8366 , this PR updates deprecated
PIL.Imageconstants (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