Skip to content

Commit a991234

Browse files
authored
types-Pillow: Allow stubtest to validate PIL.FpxImagePlugin and PIL.MicImagePlugin (#9531)
1 parent 5b04889 commit a991234

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
olefile
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
PIL.FpxImagePlugin
1+
# Requires Pyside or PyQt to be installed.
2+
# Not worth adding to requirements-stubtest.txt
3+
# because it's only used as a base type and it's a long install.
24
PIL.ImageQt.ImageQt
3-
PIL.MicImagePlugin
4-
# Requires PySide or PyQt to be installed.
5-
# We don't install either in stubtest so it can't see it
6-
PIL.ImageQt.QImage
7-
PIL.ImageQt.QPixmap

stubs/Pillow/PIL/FpxImagePlugin.pyi

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
from _typeshed import Incomplete
12
from typing import Any, ClassVar
2-
from typing_extensions import Literal
3+
from typing_extensions import Literal, TypeAlias
34

45
from .ImageFile import ImageFile
56

6-
MODES: Any
7+
_OleFileIO: TypeAlias = Any # olefile.OleFileIO
8+
_OleStream: TypeAlias = Any # olefile.OleStream
9+
10+
MODES: dict[tuple[int, ...], tuple[str, str]]
711

812
class FpxImageFile(ImageFile):
13+
ole: _OleFileIO
914
format: ClassVar[Literal["FPX"]]
1015
format_description: ClassVar[str]
11-
fp: Any
16+
fp: _OleStream | None
17+
maxid: int
18+
rawmode: str
19+
jpeg: dict[int, Incomplete]
20+
tile_prefix: Incomplete
21+
stream: list[str]
1222
def load(self): ...

stubs/Pillow/PIL/ImageQt.pyi

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ from typing_extensions import Literal, TypeAlias
33

44
from .Image import Image
55

6-
QImage: TypeAlias = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui
7-
QPixmap: TypeAlias = Any
6+
_QImage: TypeAlias = Any # imported from either of {PyQt6,PySide6,PyQt5,PySide2}.QtGui
7+
_QPixmap: TypeAlias = Any
88

99
qt_versions: Any
1010
qt_is_installed: bool
1111
qt_version: Any
1212

1313
def rgb(r: int, g: int, b: int, a: int = ...) -> int: ...
14-
def fromqimage(im: Image | QImage) -> Image: ...
15-
def fromqpixmap(im: Image | QImage) -> Image: ...
14+
def fromqimage(im: ImageQt | _QImage) -> Image: ...
15+
def fromqpixmap(im: ImageQt | _QImage) -> Image: ...
1616
def align8to32(bytes: bytes, width: int, mode: Literal["1", "L", "P"]) -> bytes: ...
1717

18-
class ImageQt(QImage):
18+
class ImageQt(_QImage):
1919
def __init__(self, im: Image) -> None: ...
2020

2121
def toqimage(im: Image) -> ImageQt: ...
22-
def toqpixmap(im: Image) -> QPixmap: ...
22+
def toqpixmap(im: Image) -> _QPixmap: ...

stubs/Pillow/PIL/MicImagePlugin.pyi

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
from typing import Any, ClassVar
2-
from typing_extensions import Literal
2+
from typing_extensions import Literal, TypeAlias
33

44
from .TiffImagePlugin import TiffImageFile
55

6+
_OleFileIO: TypeAlias = Any # olefile.OleFileIO
7+
_OleStream: TypeAlias = Any # olefile.OleStream
8+
69
class MicImageFile(TiffImageFile):
10+
ole: _OleFileIO
711
format: ClassVar[Literal["MIC"]]
8-
fp: Any
9-
frame: Any
10-
def seek(self, frame) -> None: ...
11-
def tell(self): ...
12+
format_description: ClassVar[str]
13+
fp: _OleStream
14+
frame: int | None
15+
images: list[list[str]]
16+
is_animated: bool
17+
def seek(self, frame: int) -> None: ...
18+
def tell(self) -> int | None: ... # type: ignore[override]

0 commit comments

Comments
 (0)