Open allisonkarlitskaya opened 1 month ago
We hit a large number of new Mypy issues when we upgraded to Pillow 10.3.0, to the point where we may pin to 10.2.0 until they are addressed and all the missing type hints added (or py.typed
is removed until this is done).
Some of the errors can be suppressed in the Mypy config:
[tool.mypy]
untyped_calls_exclude = [
"PIL",
]
One example of a function missing type hints is PIL.Image.fromarray
.
While I don't feel comfortable making the decision to remove py.typed myself, I can help add further type hints. I've created #8030 to add verify()
, draft()
and _expand()
(I think you meant this, as ImageOps.expand()
is already typed in 10.3.0).
Edit: I've created #8042 for filter()
.
load()
.I know that to a certain extent, these were just examples you were mentioning, and there is plenty more work to go.
we call PIL.Image.Image.open() which (among many other function) is untyped
This should already be partially type hinted in 10.3.0.
Thanks to #7944, that has been improved in main. https://github.com/python-pillow/Pillow/blob/ddbf08fa78a1aeac83c8295b071f15c722615326/src/PIL/Image.py#L3250-L3254
One example of a function missing type hints is from PIL.Image.fromarray.
This has actually already been added to main in #7936
The next release of Pillow is scheduled for July 1st, so if there are any more specific methods you would like to see typed before then, feel free to request them.
I'd like to propose a PR, but I'm afraid I don't have the time to work on such a large change. Even the
Image
class has quite a lot of untyped methods (load()
,verify()
,draft()
,expand()
,filter()
, and many others).
Smaller PRs are very welcome and also preferred, they're easier to review and quicker to merge.
We're using Pillow from our strictly-typed Python code. We recently updated to Fedora 40, which brought us
python3-pillow-10.3.0-1.fc40.x86_64
.This version of Pillow ships a
py.typed
file, which was not present in the version in Fedora 39 (python3-pillow-10.2.0-1.fc39.x86_64
).Previously, our mypy setup was ignoring our import of
PIL.Image
from a typing perspective, but with thepy.typed
file, it tries to check types. This is problem, because we callPIL.Image.Image.open()
which (among many other function) is untyped: https://github.com/python-pillow/Pillow/blob/e542c9f89883473fd0b7652b5157e98e4e15cee3/src/PIL/Image.py#L837The following example produces no errors on Fedora 39, but fails on Fedora 40:
Output from
python3 -m PIL --report
:Out of curiosity, I got the current
main
branch of Pillow and addedto
pyproject.toml
. There's quite a lot of untyped defs:I'd like to propose a PR, but I'm afraid I don't have the time to work on such a large change. Even the
Image
class has quite a lot of untyped methods (load()
,verify()
,draft()
,expand()
,filter()
, and many others).In the meantime, I think the most appropriate course of action may be to temporarily remove the
py.typed
file.