Skip to content

Commit

Permalink
Merge pull request #8030 from radarhere/type_hints
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored Apr 30, 2024
2 parents ddbf08f + 8a56fee commit 58a4797
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from collections.abc import Callable, MutableMapping
from enum import IntEnum
from types import ModuleType
from typing import IO, TYPE_CHECKING, Any, Literal, Protocol, cast
from typing import IO, TYPE_CHECKING, Any, Literal, Protocol, Sequence, cast

# VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0.
Expand Down Expand Up @@ -877,7 +877,7 @@ def load(self):
return self.pyaccess
return self.im.pixel_access(self.readonly)

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

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

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

def _expand(self, xmargin, ymargin=None):
def _expand(self, xmargin: int, ymargin: int | None = None) -> Image:
if ymargin is None:
ymargin = xmargin
self.load()
Expand Down Expand Up @@ -3450,7 +3452,7 @@ def eval(image, *args):
return image.point(args[0])


def merge(mode, bands):
def merge(mode: str, bands: Sequence[Image]) -> Image:
"""
Merge a set of single band images into a new multiband image.
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def __setstate__(self, state):
self.tile = []
super().__setstate__(state)

def verify(self):
def verify(self) -> None:
"""Check file integrity"""

# raise exception if something's wrong. must be called
Expand Down
8 changes: 5 additions & 3 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,15 @@ def load_read(self, read_bytes):

return s

def draft(self, mode, size):
def draft(
self, mode: str, size: tuple[int, int]
) -> tuple[str, tuple[int, int, float, float]] | None:
if len(self.tile) != 1:
return
return None

# Protect from second call
if self.decoderconfig:
return
return None

d, e, o, a = self.tile[0]
scale = 1
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PngImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ def text(self):
self.seek(frame)
return self._text

def verify(self):
def verify(self) -> None:
"""Verify PNG file"""

if self.fp is None:
Expand Down

0 comments on commit 58a4797

Please sign in to comment.