Merge branch 'main' into type_hints

This commit is contained in:
Andrew Murray 2024-04-30 19:41:34 +10:00 committed by GitHub
commit a304fd5f41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 10 deletions

View File

@ -41,7 +41,16 @@ import warnings
from collections.abc import Callable, MutableMapping from collections.abc import Callable, MutableMapping
from enum import IntEnum from enum import IntEnum
from types import ModuleType from types import ModuleType
from typing import IO, TYPE_CHECKING, Any, Literal, Protocol, SupportsInt, cast from typing import (
IO,
TYPE_CHECKING,
Any,
Literal,
Protocol,
Sequence,
SupportsInt,
cast,
)
# VERSION was removed in Pillow 6.0.0. # VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0. # PILLOW_VERSION was removed in Pillow 9.0.0.
@ -903,7 +912,7 @@ class Image:
return self.im.pixel_access(self.readonly) return self.im.pixel_access(self.readonly)
return None return None
def verify(self): def verify(self) -> None:
""" """
Verifies the contents of a file. For data read from a file, this Verifies the contents of a file. For data read from a file, this
method attempts to determine if the file is broken, without method attempts to determine if the file is broken, without
@ -1293,7 +1302,9 @@ class Image:
return im.crop((x0, y0, x1, y1)) 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 Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and image that as closely as possible matches the given mode and
@ -1316,7 +1327,7 @@ class Image:
""" """
pass pass
def _expand(self, xmargin, ymargin=None): def _expand(self, xmargin: int, ymargin: int | None = None) -> Image:
if ymargin is None: if ymargin is None:
ymargin = xmargin ymargin = xmargin
self.load() self.load()
@ -3477,7 +3488,7 @@ def eval(image, *args):
return image.point(args[0]) 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. Merge a set of single band images into a new multiband image.

View File

@ -163,7 +163,7 @@ class ImageFile(Image.Image):
self.tile = [] self.tile = []
super().__setstate__(state) super().__setstate__(state)
def verify(self): def verify(self) -> None:
"""Check file integrity""" """Check file integrity"""
# raise exception if something's wrong. must be called # raise exception if something's wrong. must be called

View File

@ -424,13 +424,15 @@ class JpegImageFile(ImageFile.ImageFile):
return s 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: if len(self.tile) != 1:
return return None
# Protect from second call # Protect from second call
if self.decoderconfig: if self.decoderconfig:
return return None
d, e, o, a = self.tile[0] d, e, o, a = self.tile[0]
scale = 1 scale = 1

View File

@ -783,7 +783,7 @@ class PngImageFile(ImageFile.ImageFile):
self.seek(frame) self.seek(frame)
return self._text return self._text
def verify(self): def verify(self) -> None:
"""Verify PNG file""" """Verify PNG file"""
if self.fp is None: if self.fp is None: