Merge pull request #7671 from radarhere/imagetransform

Added type hints to ImageTransform
This commit is contained in:
Andrew Murray 2024-01-01 21:45:56 +11:00 committed by GitHub
commit 24e9485e6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -149,4 +149,5 @@ Work has begun to add type annotations to Pillow, including:
* :py:mod:`~PIL.ImageChops`
* :py:mod:`~PIL.ImageMode`
* :py:mod:`~PIL.ImageSequence`
* :py:mod:`~PIL.ImageTransform`
* :py:mod:`~PIL.TarIO`

View File

@ -2643,7 +2643,7 @@ class Image:
resample=Resampling.NEAREST,
fill=1,
fillcolor=None,
):
) -> Image:
"""
Transforms this image. This method creates a new image with the
given size, and the same mode as the original, and copies data

View File

@ -14,17 +14,26 @@
#
from __future__ import annotations
from typing import Sequence
from . import Image
class Transform(Image.ImageTransformHandler):
def __init__(self, data):
method: Image.Transform
def __init__(self, data: Sequence[int]) -> None:
self.data = data
def getdata(self):
def getdata(self) -> tuple[int, Sequence[int]]:
return self.method, self.data
def transform(self, size, image, **options):
def transform(
self,
size: tuple[int, int],
image: Image.Image,
**options: dict[str, str | int | tuple[int, ...] | list[int]],
) -> Image.Image:
# can be overridden
method, data = self.getdata()
return image.transform(size, method, data, **options)