Description
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 the py.typed
file, it tries to check types. This is problem, because we call PIL.Image.Image.open()
which (among many other function) is untyped:
Line 837 in e542c9f
The following example produces no errors on Fedora 39, but fails on Fedora 40:
from PIL import Image
with open('file.png', 'rb') as file:
Image.open(file).load()
$ mypy --strict bzzt.py
bzzt.py:4: error: Call to untyped function "load" in typed context [no-untyped-call]
Found 1 error in 1 file (checked 1 source file)
Output from python3 -m PIL --report
:
--------------------------------------------------------------------
Pillow 10.3.0
Python 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 14.0.1 20240217 (Red Hat 14.0.1-0)]
--------------------------------------------------------------------
Python executable is /usr/bin/python3
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /usr/lib64/python3.12/site-packages/PIL
Binary Pillow modules loaded from /usr/lib64/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.0.zlib-ng
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.8.0
--- LIBIMAGEQUANT (Quantization method) support ok, loaded 4.2.2
--- XCB (X protocol) support ok
--------------------------------------------------------------------
Out of curiosity, I got the current main
branch of Pillow and added
[tool.mypy]
disallow_untyped_defs = true
to pyproject.toml
. There's quite a lot of untyped defs:
Found 853 errors in 58 files (checked 102 source files)
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.