Typing: Image.transform

This commit is contained in:
Eric Soroos 2018-01-05 12:46:30 +00:00
parent 404d6f31c7
commit a5c66e456b

View File

@ -2202,7 +2202,7 @@ class Image(object):
# instead of bloating the method docs, add a separate chapter. # instead of bloating the method docs, add a separate chapter.
def transform(self, size, method, data=None, resample=NEAREST, def transform(self, size, method, data=None, resample=NEAREST,
fill=1, fillcolor=None): fill=1, fillcolor=None):
# type: (Size, int, Optional[List[float]], int, int, Optional[Color]) -> Image # type: (Size, int, Optional[Union[List[float], List[Tuple[LURD,LURD]]]], int, int, Optional[Color]) -> Image
""" """
Transforms this image. This method creates a new image with the Transforms this image. This method creates a new image with the
given size, and the same mode as the original, and copies data given size, and the same mode as the original, and copies data
@ -2241,7 +2241,8 @@ class Image(object):
if hasattr(method, "getdata"): if hasattr(method, "getdata"):
# compatibility w. old-style transform objects # compatibility w. old-style transform objects
method, data = method.getdata() # ignoring for typing, this is old compatibility
method, data = method.getdata() # type: ignore
if data is None: if data is None:
raise ValueError("missing method data") raise ValueError("missing method data")
@ -2249,11 +2250,15 @@ class Image(object):
im = new(self.mode, size, fillcolor) im = new(self.mode, size, fillcolor)
if method == MESH: if method == MESH:
# list of quads # list of quads
for box, quad in data: data_mesh = None # type: List[Tuple[LURD,LURD]]
data_mesh = data # type: ignore
for box, quad in data_mesh:
im.__transformer(box, self, QUAD, quad, resample, im.__transformer(box, self, QUAD, quad, resample,
fillcolor is None) fillcolor is None)
else: else:
im.__transformer((0, 0)+size, self, method, data, box_lurd = None # type: LURD
box_lurd = (0, 0)+size # type: ignore
im.__transformer(box_lurd, self, method, data,
resample, fillcolor is None) resample, fillcolor is None)
return im return im