Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added type hints to ImageTransform #7671

Merged
merged 4 commits into from Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PIL/Image.py
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
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: int
radarhere marked this conversation as resolved.
Show resolved Hide resolved

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