Skip to content

Commit 58a4797

Browse files
authored
Merge pull request #8030 from radarhere/type_hints
2 parents ddbf08f + 8a56fee commit 58a4797

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/PIL/Image.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from collections.abc import Callable, MutableMapping
4242
from enum import IntEnum
4343
from types import ModuleType
44-
from typing import IO, TYPE_CHECKING, Any, Literal, Protocol, cast
44+
from typing import IO, TYPE_CHECKING, Any, Literal, Protocol, Sequence, cast
4545

4646
# VERSION was removed in Pillow 6.0.0.
4747
# PILLOW_VERSION was removed in Pillow 9.0.0.
@@ -877,7 +877,7 @@ def load(self):
877877
return self.pyaccess
878878
return self.im.pixel_access(self.readonly)
879879

880-
def verify(self):
880+
def verify(self) -> None:
881881
"""
882882
Verifies the contents of a file. For data read from a file, this
883883
method attempts to determine if the file is broken, without
@@ -1267,7 +1267,9 @@ def _crop(self, im, box):
12671267

12681268
return im.crop((x0, y0, x1, y1))
12691269

1270-
def draft(self, mode, size):
1270+
def draft(
1271+
self, mode: str, size: tuple[int, int]
1272+
) -> tuple[str, tuple[int, int, float, float]] | None:
12711273
"""
12721274
Configures the image file loader so it returns a version of the
12731275
image that as closely as possible matches the given mode and
@@ -1290,7 +1292,7 @@ def draft(self, mode, size):
12901292
"""
12911293
pass
12921294

1293-
def _expand(self, xmargin, ymargin=None):
1295+
def _expand(self, xmargin: int, ymargin: int | None = None) -> Image:
12941296
if ymargin is None:
12951297
ymargin = xmargin
12961298
self.load()
@@ -3450,7 +3452,7 @@ def eval(image, *args):
34503452
return image.point(args[0])
34513453

34523454

3453-
def merge(mode, bands):
3455+
def merge(mode: str, bands: Sequence[Image]) -> Image:
34543456
"""
34553457
Merge a set of single band images into a new multiband image.
34563458

src/PIL/ImageFile.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __setstate__(self, state):
163163
self.tile = []
164164
super().__setstate__(state)
165165

166-
def verify(self):
166+
def verify(self) -> None:
167167
"""Check file integrity"""
168168

169169
# raise exception if something's wrong. must be called

src/PIL/JpegImagePlugin.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -424,13 +424,15 @@ def load_read(self, read_bytes):
424424

425425
return s
426426

427-
def draft(self, mode, size):
427+
def draft(
428+
self, mode: str, size: tuple[int, int]
429+
) -> tuple[str, tuple[int, int, float, float]] | None:
428430
if len(self.tile) != 1:
429-
return
431+
return None
430432

431433
# Protect from second call
432434
if self.decoderconfig:
433-
return
435+
return None
434436

435437
d, e, o, a = self.tile[0]
436438
scale = 1

src/PIL/PngImagePlugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def text(self):
783783
self.seek(frame)
784784
return self._text
785785

786-
def verify(self):
786+
def verify(self) -> None:
787787
"""Verify PNG file"""
788788

789789
if self.fp is None:

0 commit comments

Comments
 (0)