From c0a44be33f0986d3233ea223d8e6385bc482f114 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Fri, 5 Apr 2024 13:30:27 +0200 Subject: [PATCH] Depend on Pillow instead of types-Pillow (#11720) --- .github/workflows/tests.yml | 4 +--- README.md | 4 ++-- .../@tests/test_cases/check_tk_compat.py | 21 ++++++++++++------- stubs/Pillow/PIL/ImageTk.pyi | 6 +++--- stubs/Pillow/PIL/PyAccess.pyi | 11 ++++++++-- stubs/PyAutoGUI/METADATA.toml | 2 +- stubs/PyScreeze/METADATA.toml | 2 +- stubs/fpdf2/METADATA.toml | 2 +- stubs/python-xlib/METADATA.toml | 1 - stubs/python-xlib/Xlib/xobject/drawable.pyi | 6 ++++-- 10 files changed, 35 insertions(+), 24 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ff01ff25e..096b38675 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -123,9 +123,7 @@ jobs: if [ -n "$DEPENDENCIES" ]; then source .venv/bin/activate echo "Installing packages: $DEPENDENCIES" - # https://github.com/python/typeshed/issues/11688 - echo "Pillow<10.3" > constraints.txt - uv pip install -c constraints.txt $DEPENDENCIES + uv pip install $DEPENDENCIES fi - name: Activate the isolated venv for the rest of the job run: echo "$PWD/.venv/bin" >> $GITHUB_PATH diff --git a/README.md b/README.md index 914be67b8..9f35705d6 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ If you're just using a type checker ([mypy](https://github.com/python/mypy/), developing it, you don't need to interact with the typeshed repo at all: a copy of standard library part of typeshed is bundled with type checkers. And type stubs for third party packages and modules you are using can -be installed from PyPI. For example, if you are using `Pillow` and `requests`, +be installed from PyPI. For example, if you are using `html5lib` and `requests`, you can install the type stubs using ```bash -$ pip install types-Pillow types-requests +$ pip install types-html5lib types-requests ``` These PyPI packages follow [PEP 561](http://www.python.org/dev/peps/pep-0561/) diff --git a/stubs/Pillow/@tests/test_cases/check_tk_compat.py b/stubs/Pillow/@tests/test_cases/check_tk_compat.py index 05332d505..3cd413602 100644 --- a/stubs/Pillow/@tests/test_cases/check_tk_compat.py +++ b/stubs/Pillow/@tests/test_cases/check_tk_compat.py @@ -1,15 +1,20 @@ # Verify that ImageTK images are valid to pass to TK code. from __future__ import annotations -import tkinter +# The following tests don't work at the moment, due to pyright getting +# confused by the existence of these stubs and annotations in the actual +# Pillow package. +# https://github.com/python/typeshed/issues/11688 -from PIL import ImageTk +# import tkinter -photo = ImageTk.PhotoImage() -bitmap = ImageTk.BitmapImage() +# from PIL import ImageTk -tkinter.Label(image=photo) -tkinter.Label(image=bitmap) +# photo = ImageTk.PhotoImage() +# bitmap = ImageTk.BitmapImage() -tkinter.Label().configure(image=photo) -tkinter.Label().configure(image=bitmap) +# tkinter.Label(image=photo) +# tkinter.Label(image=bitmap) + +# tkinter.Label().configure(image=photo) +# tkinter.Label().configure(image=bitmap) diff --git a/stubs/Pillow/PIL/ImageTk.pyi b/stubs/Pillow/PIL/ImageTk.pyi index 69fe38207..4b5d910b6 100644 --- a/stubs/Pillow/PIL/ImageTk.pyi +++ b/stubs/Pillow/PIL/ImageTk.pyi @@ -3,14 +3,14 @@ import tkinter from _typeshed import ReadableBuffer, StrOrBytesPath, SupportsRead from typing import Any -from PIL.Image import Image, _Mode, _Size +from PIL.Image import Image class PhotoImage(tkinter._PhotoImageLike): tk: _tkinter.TkappType def __init__( self, - image: Image | _Mode | None = None, - size: _Size | None = None, + image: Image | str | None = None, + size: tuple[int, int] | None = None, *, file: StrOrBytesPath | SupportsRead[bytes] = ..., data: ReadableBuffer = ..., diff --git a/stubs/Pillow/PIL/PyAccess.pyi b/stubs/Pillow/PIL/PyAccess.pyi index f50f15ae1..3d5b5f44c 100644 --- a/stubs/Pillow/PIL/PyAccess.pyi +++ b/stubs/Pillow/PIL/PyAccess.pyi @@ -1,9 +1,16 @@ from _typeshed import Incomplete - -from PIL._imaging import _PixelAccessor +from typing import Protocol ffi: Incomplete +# Copy of PIL._imaging.PixelAccess. +# See https://github.com/python/typeshed/issues/11688. +class _PixelAccessor(Protocol): + def __setitem__(self, xy: tuple[int, int], color, /) -> None: ... + def __getitem__(self, xy: tuple[int, int], /): ... + def putpixel(self, xy: tuple[int, int], color, /) -> None: ... + def getpixel(self, xy: tuple[int, int], /): ... + class PyAccess(_PixelAccessor): readonly: Incomplete image8: Incomplete diff --git a/stubs/PyAutoGUI/METADATA.toml b/stubs/PyAutoGUI/METADATA.toml index 11402b62e..66c268a99 100644 --- a/stubs/PyAutoGUI/METADATA.toml +++ b/stubs/PyAutoGUI/METADATA.toml @@ -1,3 +1,3 @@ version = "0.9.*" upstream_repository = "https://github.com/asweigart/pyautogui" -requires = ["types-Pillow", "types-PyScreeze"] +requires = ["types-PyScreeze"] diff --git a/stubs/PyScreeze/METADATA.toml b/stubs/PyScreeze/METADATA.toml index 885ff5b82..95aea7b61 100644 --- a/stubs/PyScreeze/METADATA.toml +++ b/stubs/PyScreeze/METADATA.toml @@ -1,6 +1,6 @@ version = "0.1.30" upstream_repository = "https://github.com/asweigart/pyscreeze" -requires = ["types-Pillow"] +requires = ["Pillow>=10.3.0"] [tool.stubtest] # Linux has extra constants, win32 has different definitions diff --git a/stubs/fpdf2/METADATA.toml b/stubs/fpdf2/METADATA.toml index 52b0219da..6d1cd18b9 100644 --- a/stubs/fpdf2/METADATA.toml +++ b/stubs/fpdf2/METADATA.toml @@ -1,6 +1,6 @@ version = "2.7.8" upstream_repository = "https://github.com/PyFPDF/fpdf2" -requires = ["types-Pillow>=9.2.0"] +requires = ["Pillow>=10.3.0"] [tool.stubtest] stubtest_requirements = ["cryptography"] diff --git a/stubs/python-xlib/METADATA.toml b/stubs/python-xlib/METADATA.toml index cf9a82a78..949a79c20 100644 --- a/stubs/python-xlib/METADATA.toml +++ b/stubs/python-xlib/METADATA.toml @@ -1,3 +1,2 @@ version = "0.33.*" upstream_repository = "https://github.com/python-xlib/python-xlib" -requires = ["types-Pillow"] diff --git a/stubs/python-xlib/Xlib/xobject/drawable.pyi b/stubs/python-xlib/Xlib/xobject/drawable.pyi index c6d6a1887..dc5c1c321 100644 --- a/stubs/python-xlib/Xlib/xobject/drawable.pyi +++ b/stubs/python-xlib/Xlib/xobject/drawable.pyi @@ -1,12 +1,14 @@ from collections.abc import Iterable, Sequence from typing import Any +from typing_extensions import TypeAlias -from PIL import Image from Xlib._typing import ErrorHandler from Xlib.protocol import request, rq from Xlib.protocol.structs import _Arc6IntSequence, _Rectangle4IntSequence, _RGB3IntIterable, _Segment4IntSequence from Xlib.xobject import colormap, cursor, fontable, resource +_Image: TypeAlias = Any # PIL.Image.Image + class Drawable(resource.Resource): __drawable__ = resource.Resource.__resource__ def get_geometry(self) -> request.GetGeometry: ... @@ -100,7 +102,7 @@ class Drawable(resource.Resource): data: bytes | bytearray, onerror: ErrorHandler[object] | None = None, ) -> None: ... - def put_pil_image(self, gc: int, x: int, y: int, image: Image.Image, onerror: ErrorHandler[object] | None = None) -> None: ... + def put_pil_image(self, gc: int, x: int, y: int, image: _Image, onerror: ErrorHandler[object] | None = None) -> None: ... def get_image(self, x: int, y: int, width: int, height: int, format: int, plane_mask: int) -> request.GetImage: ... def draw_text( self, gc: int, x: int, y: int, text: dict[str, str | int], onerror: ErrorHandler[object] | None = None