From a991234832dac9e30bc0d909c0e76422c00a6ff2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 17 Jan 2023 11:37:17 -0500 Subject: [PATCH] `types-Pillow`: Allow stubtest to validate `PIL.FpxImagePlugin` and `PIL.MicImagePlugin` (#9531) --- stubs/Pillow/@tests/requirements-stubtest.txt | 1 + stubs/Pillow/@tests/stubtest_allowlist.txt | 9 +++------ stubs/Pillow/PIL/FpxImagePlugin.pyi | 16 +++++++++++++--- stubs/Pillow/PIL/ImageQt.pyi | 12 ++++++------ stubs/Pillow/PIL/MicImagePlugin.pyi | 17 ++++++++++++----- 5 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 stubs/Pillow/@tests/requirements-stubtest.txt diff --git a/stubs/Pillow/@tests/requirements-stubtest.txt b/stubs/Pillow/@tests/requirements-stubtest.txt new file mode 100644 index 000000000..a2d775acd --- /dev/null +++ b/stubs/Pillow/@tests/requirements-stubtest.txt @@ -0,0 +1 @@ +olefile diff --git a/stubs/Pillow/@tests/stubtest_allowlist.txt b/stubs/Pillow/@tests/stubtest_allowlist.txt index bf5158dc9..423463d14 100644 --- a/stubs/Pillow/@tests/stubtest_allowlist.txt +++ b/stubs/Pillow/@tests/stubtest_allowlist.txt @@ -1,7 +1,4 @@ -PIL.FpxImagePlugin +# Requires Pyside or PyQt to be installed. +# Not worth adding to requirements-stubtest.txt +# because it's only used as a base type and it's a long install. PIL.ImageQt.ImageQt -PIL.MicImagePlugin -# Requires PySide or PyQt to be installed. -# We don't install either in stubtest so it can't see it -PIL.ImageQt.QImage -PIL.ImageQt.QPixmap diff --git a/stubs/Pillow/PIL/FpxImagePlugin.pyi b/stubs/Pillow/PIL/FpxImagePlugin.pyi index 069cb6b20..226a10f27 100644 --- a/stubs/Pillow/PIL/FpxImagePlugin.pyi +++ b/stubs/Pillow/PIL/FpxImagePlugin.pyi @@ -1,12 +1,22 @@ +from _typeshed import Incomplete from typing import Any, ClassVar -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .ImageFile import ImageFile -MODES: Any +_OleFileIO: TypeAlias = Any # olefile.OleFileIO +_OleStream: TypeAlias = Any # olefile.OleStream + +MODES: dict[tuple[int, ...], tuple[str, str]] class FpxImageFile(ImageFile): + ole: _OleFileIO format: ClassVar[Literal["FPX"]] format_description: ClassVar[str] - fp: Any + fp: _OleStream | None + maxid: int + rawmode: str + jpeg: dict[int, Incomplete] + tile_prefix: Incomplete + stream: list[str] def load(self): ... diff --git a/stubs/Pillow/PIL/ImageQt.pyi b/stubs/Pillow/PIL/ImageQt.pyi index 472837033..434ba4d7e 100644 --- a/stubs/Pillow/PIL/ImageQt.pyi +++ b/stubs/Pillow/PIL/ImageQt.pyi @@ -3,20 +3,20 @@ from typing_extensions import Literal, TypeAlias from .Image import Image -QImage: TypeAlias = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui -QPixmap: TypeAlias = Any +_QImage: TypeAlias = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui +_QPixmap: TypeAlias = Any qt_versions: Any qt_is_installed: bool qt_version: Any def rgb(r: int, g: int, b: int, a: int = ...) -> int: ... -def fromqimage(im: Image | QImage) -> Image: ... -def fromqpixmap(im: Image | QImage) -> Image: ... +def fromqimage(im: ImageQt | _QImage) -> Image: ... +def fromqpixmap(im: ImageQt | _QImage) -> Image: ... def align8to32(bytes: bytes, width: int, mode: Literal["1", "L", "P"]) -> bytes: ... -class ImageQt(QImage): +class ImageQt(_QImage): def __init__(self, im: Image) -> None: ... def toqimage(im: Image) -> ImageQt: ... -def toqpixmap(im: Image) -> QPixmap: ... +def toqpixmap(im: Image) -> _QPixmap: ... diff --git a/stubs/Pillow/PIL/MicImagePlugin.pyi b/stubs/Pillow/PIL/MicImagePlugin.pyi index b4fdc9d05..839f91cdd 100644 --- a/stubs/Pillow/PIL/MicImagePlugin.pyi +++ b/stubs/Pillow/PIL/MicImagePlugin.pyi @@ -1,11 +1,18 @@ from typing import Any, ClassVar -from typing_extensions import Literal +from typing_extensions import Literal, TypeAlias from .TiffImagePlugin import TiffImageFile +_OleFileIO: TypeAlias = Any # olefile.OleFileIO +_OleStream: TypeAlias = Any # olefile.OleStream + class MicImageFile(TiffImageFile): + ole: _OleFileIO format: ClassVar[Literal["MIC"]] - fp: Any - frame: Any - def seek(self, frame) -> None: ... - def tell(self): ... + format_description: ClassVar[str] + fp: _OleStream + frame: int | None + images: list[list[str]] + is_animated: bool + def seek(self, frame: int) -> None: ... + def tell(self) -> int | None: ... # type: ignore[override]