Skip to content

Commit

Permalink
Merge pull request #7671 from radarhere/imagetransform
Browse files Browse the repository at this point in the history
Added type hints to ImageTransform
  • Loading branch information
radarhere authored Jan 1, 2024
2 parents 57096f5 + 09ea121 commit 24e9485
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/releasenotes/10.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
2 changes: 1 addition & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2643,7 +2643,7 @@ def transform(
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
Expand Down
15 changes: 12 additions & 3 deletions src/PIL/ImageTransform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 24e9485

Please sign in to comment.