Skip to content

Commit 97a83de

Browse files
committed
Added type hints
1 parent 6782a07 commit 97a83de

File tree

4 files changed

+130
-66
lines changed

4 files changed

+130
-66
lines changed

src/PIL/Image.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ def get_value(element):
14181418
root = ElementTree.fromstring(xmp_tags)
14191419
return {get_name(root.tag): get_value(root)}
14201420

1421-
def getexif(self):
1421+
def getexif(self) -> Exif:
14221422
"""
14231423
Gets EXIF data from the image.
14241424
@@ -1513,7 +1513,7 @@ def getim(self):
15131513
self.load()
15141514
return self.im.ptr
15151515

1516-
def getpalette(self, rawmode="RGB"):
1516+
def getpalette(self, rawmode: str = "RGB") -> list[int, ...]:
15171517
"""
15181518
Returns the image palette as a list.
15191519
@@ -1603,7 +1603,7 @@ def getprojection(self):
16031603
x, y = self.im.getprojection()
16041604
return list(x), list(y)
16051605

1606-
def histogram(self, mask=None, extrema=None):
1606+
def histogram(self, mask=None, extrema=None) -> list[int, ...]:
16071607
"""
16081608
Returns a histogram for the image. The histogram is returned as a
16091609
list of pixel counts, one for each pixel value in the source
@@ -1792,7 +1792,7 @@ def alpha_composite(self, im, dest=(0, 0), source=(0, 0)):
17921792
result = alpha_composite(background, overlay)
17931793
self.paste(result, box)
17941794

1795-
def point(self, lut, mode=None):
1795+
def point(self, lut, mode: str | None = None) -> Image:
17961796
"""
17971797
Maps this image through a lookup table or function.
17981798
@@ -1916,7 +1916,7 @@ def putdata(self, data, scale=1.0, offset=0.0):
19161916

19171917
self.im.putdata(data, scale, offset)
19181918

1919-
def putpalette(self, data, rawmode="RGB"):
1919+
def putpalette(self, data, rawmode="RGB") -> None:
19201920
"""
19211921
Attaches a palette to this image. The image must be a "P", "PA", "L"
19221922
or "LA" image.
@@ -2096,7 +2096,7 @@ def _get_safe_box(self, size, resample, box):
20962096
min(self.size[1], math.ceil(box[3] + support_y)),
20972097
)
20982098

2099-
def resize(self, size, resample=None, box=None, reducing_gap=None):
2099+
def resize(self, size, resample=None, box=None, reducing_gap=None) -> Image:
21002100
"""
21012101
Returns a resized copy of this image.
21022102
@@ -2810,7 +2810,7 @@ def __transformer(
28102810

28112811
self.im.transform2(box, image.im, method, data, resample, fill)
28122812

2813-
def transpose(self, method):
2813+
def transpose(self, method: Transpose) -> Image:
28142814
"""
28152815
Transpose image (flip or rotate in 90 degree steps)
28162816
@@ -3782,7 +3782,7 @@ def _get_merged_dict(self):
37823782

37833783
return merged_dict
37843784

3785-
def tobytes(self, offset=8):
3785+
def tobytes(self, offset: int = 8) -> bytes:
37863786
from . import TiffImagePlugin
37873787

37883788
head = self._get_head()
@@ -3937,7 +3937,7 @@ def __setitem__(self, tag, value):
39373937
del self._info[tag]
39383938
self._data[tag] = value
39393939

3940-
def __delitem__(self, tag):
3940+
def __delitem__(self, tag: int) -> None:
39413941
if self._info is not None and tag in self._info:
39423942
del self._info[tag]
39433943
else:

src/PIL/ImageColor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def getrgb(color):
124124

125125

126126
@lru_cache
127-
def getcolor(color, mode):
127+
def getcolor(color, mode: str) -> tuple[int, ...]:
128128
"""
129129
Same as :py:func:`~PIL.ImageColor.getrgb` for most modes. However, if
130130
``mode`` is HSV, converts the RGB value to a HSV value, or if ``mode`` is

0 commit comments

Comments
 (0)