-
Notifications
You must be signed in to change notification settings - Fork 1
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
Added type hints #40
Added type hints #40
Conversation
src/PIL/Image.py
Outdated
cast(Tuple[int, int, int], trns), # trns was converted to RGB | ||
new_im, | ||
) | ||
new_im.info["transparency"] = new_im.palette.getcolor(trns, new_im) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too sure about this change.
Although mypy does not complain either way, I can see a warning in PyCharm without the cast.
Running mypy with --strict
prints a warning that could explain why it (incorrectly) does not error without the cast:
src\PIL\Image.py:1158: error: Item "None" of "Optional[Any]" has no attribute
"getcolor" [union-attr]
... new_im.info["transparency"] = new_im.palette.getcol...
^~~~~~~~~~~~~~~~~~~~~~~
I suspect that the warning is only skipped because mypy doesn't realize that new_im.palette
is an ImagePalette
because it is set within an if block (unlike the cast above which is not in a nested if block).
Edit: clarify wording
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created python-pillow#8167, where I give up on the idea of requiring getcolor()
to have a length of exactly 3 or 4. If that is merged, then my next suggestion would be radarhere@dfc1b0f
But I am keen to get python-pillow#8032 in for this release, so at any stage if you say 'Hey, let's merge it as it is and debate this later', we absolutely can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'd prefer to discuss this commit separately then.
Could you rebase to remove the commit so I can merge the rest of this PR?
And put it in a separate PR to the main repo once python-pillow#8032 and python-pillow#8167 are merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I've removed the commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the PRs have been merged, so I've created python-pillow#8169
Co-authored-by: Ondrej Baranovič <ondreko.tiba@gmail.com>
Thanks |
Suggestions for python-pillow#8032