-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add type hints to _binary #7659
Conversation
This looks fine, please can you split this into two PRs, one to deprecate and the other to add type hints? I think it will be clearer to keep them separate. If you want, it's okay to leave this PR as-is, and create another one that is the first step, and we can merge that one first. |
OK, I've removed the deprecation commits and created #7664 for that. |
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.
Thanks!
Helps #2625.
There are two tricky parts in adding type hints to
PIL._binary
:The
i16*
andi32*
give a "Returning Any from function declared to return int" in--strict
mode due to the use ofstruct.unpack_from
. This can be properly silenced with#type: ignore[no-any-return]
, but that gives a "Unused type ignore comment" when running without--strict
, so I have left it out for now.The
i8
function distinguishes betweenint
andbytes
inputs in a way that mypy doesn't recognize. Sincei8
is called with anint
input only fromIptcImagePlugin
, I have removed those calls there and removedint
support as input toi8
.Although the values in
self.info[(3, 60)]
andself.info[(3, 65)]
can be lists if the tags are duplicated, these tags are marked as "non-repeatable" in the specification (pg. 13-14). The specification recommends using the first entry if the tags are duplicated (sec. 1.5-d), but this recommendation was already ignored inIptcImagePlugin
and I was unable to find any images to test this with.In doing so, I found that
IptcImagePlugin.dump
,IptcImagePlugin.i
, andIptcImagePlugin.PAD
are simple helpers that should probably be deprecated (edit: #7664).