Skip to content

Commit 24e9485

Browse files
authored
Merge pull request #7671 from radarhere/imagetransform
Added type hints to ImageTransform
2 parents 57096f5 + 09ea121 commit 24e9485

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

docs/releasenotes/10.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,5 @@ Work has begun to add type annotations to Pillow, including:
149149
* :py:mod:`~PIL.ImageChops`
150150
* :py:mod:`~PIL.ImageMode`
151151
* :py:mod:`~PIL.ImageSequence`
152+
* :py:mod:`~PIL.ImageTransform`
152153
* :py:mod:`~PIL.TarIO`

src/PIL/Image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2643,7 +2643,7 @@ def transform(
26432643
resample=Resampling.NEAREST,
26442644
fill=1,
26452645
fillcolor=None,
2646-
):
2646+
) -> Image:
26472647
"""
26482648
Transforms this image. This method creates a new image with the
26492649
given size, and the same mode as the original, and copies data

src/PIL/ImageTransform.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@
1414
#
1515
from __future__ import annotations
1616

17+
from typing import Sequence
18+
1719
from . import Image
1820

1921

2022
class Transform(Image.ImageTransformHandler):
21-
def __init__(self, data):
23+
method: Image.Transform
24+
25+
def __init__(self, data: Sequence[int]) -> None:
2226
self.data = data
2327

24-
def getdata(self):
28+
def getdata(self) -> tuple[int, Sequence[int]]:
2529
return self.method, self.data
2630

27-
def transform(self, size, image, **options):
31+
def transform(
32+
self,
33+
size: tuple[int, int],
34+
image: Image.Image,
35+
**options: dict[str, str | int | tuple[int, ...] | list[int]],
36+
) -> Image.Image:
2837
# can be overridden
2938
method, data = self.getdata()
3039
return image.transform(size, method, data, **options)

0 commit comments

Comments
 (0)