-
-
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
py.typed
present, but not all methods have types
#8029
Comments
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 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 |
Pillow upstream added a `py.typed` file in their last release, which is causing us problems because: - we `from PIL import Image`, which kinda looks like the class `Image` in the `PIL` module, but is actually a submodule. In particular, `PIL.Image.open()` is not a static method, but a function call, and it doesn't return `PIL.Image`, but rather `PIL.Image.Image`. Fix a couple of annotations. - our hacks for setting `Image = None` if the import is missing are no longer working (since the import now has a better type than `Any`). Let's make the import unconditional. `dnf install python3-pillow`. - several methods are unannotated in the upstream code, leading to warnings about "untyped call from typed code". We use an #ignore for those; cf. python-pillow/Pillow#8029
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 Edit: I've created #8042 for #8032 has been created to add type hints for I know that to a certain extent, these were just examples you were mentioning, and there is plenty more work to go.
This should already be partially type hinted in 10.3.0. Line 3225 in 5c89d88
Thanks to #7944, that has been improved in main. Lines 3250 to 3254 in ddbf08f
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. |
Smaller PRs are very welcome and also preferred, they're easier to review and quicker to merge. |
Pillow upstream added a `py.typed` file in their last release, which is causing us problems because: - we `from PIL import Image`, which kinda looks like the class `Image` in the `PIL` module, but is actually a submodule. In particular, `PIL.Image.open()` is not a static method, but a function call, and it doesn't return `PIL.Image`, but rather `PIL.Image.Image`. Fix a couple of annotations. - our hacks for setting `Image = None` if the import is missing are no longer working (since the import now has a better type than `Any`). Let's make the import unconditional. `dnf install python3-pillow`. - several methods are unannotated in the upstream code, leading to warnings about "untyped call from typed code". We use an #ignore for those; cf. python-pillow/Pillow#8029
As a progress update, that number is now halved - we're down to
|
Pillow 10.4.0 has now been released, with type hints for all of the methods explicitly mentioned in this issue. |
@radarhere 10.4.0 allowed us to remove a lot of In our particular codebase, the only remaining untyped call we hit after upgrading to 10.4.0 is: Line 99 in 8c26622
|
#8191 has now typed that method. |
We're now down to
|
Looks like
to me on 71876cf :) |
If you're happy with that, great! However, the OP wanted us to meet a different standard - not showing any errors when With that setting, we're still at
|
Ah, I thought we were going with what |
To avoid regressions, I'd recommend turning this on in this repo once the remaining missing types are fixed. |
typeshed's Pillow stubs have now been removed in favour of ours. In main, we're now down to
Those improvements will be part of Pillow 11.0.0, due out on the 15th of this month. #8362 and #8227 are open to handle the remaining errors. After that, sure, adding |
Pillow upstream added a `py.typed` file in their last release, which is causing us problems because: - we `from PIL import Image`, which kinda looks like the class `Image` in the `PIL` module, but is actually a submodule. In particular, `PIL.Image.open()` is not a static method, but a function call, and it doesn't return `PIL.Image`, but rather `PIL.Image.Image`. Fix a couple of annotations. - our hacks for setting `Image = None` if the import is missing are no longer working (since the import now has a better type than `Any`). Let's make the import unconditional. `dnf install python3-pillow`. - several methods are unannotated in the upstream code, leading to warnings about "untyped call from typed code". We use an #ignore for those; cf. python-pillow/Pillow#8029
Pillow 11.0.0 has now been released, with
#8362 will handle the remaining errors, and also add |
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:Pillow/src/PIL/Image.py
Line 837 in e542c9f
The 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.The text was updated successfully, but these errors were encountered: