Skip to content

Commit

Permalink
Added type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Feb 7, 2024
1 parent 6782a07 commit 97a83de
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 66 deletions.
18 changes: 9 additions & 9 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ def get_value(element):
root = ElementTree.fromstring(xmp_tags)
return {get_name(root.tag): get_value(root)}

def getexif(self):
def getexif(self) -> Exif:
"""
Gets EXIF data from the image.
Expand Down Expand Up @@ -1513,7 +1513,7 @@ def getim(self):
self.load()
return self.im.ptr

def getpalette(self, rawmode="RGB"):
def getpalette(self, rawmode: str = "RGB") -> list[int, ...]:
"""
Returns the image palette as a list.
Expand Down Expand Up @@ -1603,7 +1603,7 @@ def getprojection(self):
x, y = self.im.getprojection()
return list(x), list(y)

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

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

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

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

def resize(self, size, resample=None, box=None, reducing_gap=None):
def resize(self, size, resample=None, box=None, reducing_gap=None) -> Image:
"""
Returns a resized copy of this image.
Expand Down Expand Up @@ -2810,7 +2810,7 @@ def __transformer(

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

def transpose(self, method):
def transpose(self, method: Transpose) -> Image:
"""
Transpose image (flip or rotate in 90 degree steps)
Expand Down Expand Up @@ -3782,7 +3782,7 @@ def _get_merged_dict(self):

return merged_dict

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

head = self._get_head()
Expand Down Expand Up @@ -3937,7 +3937,7 @@ def __setitem__(self, tag, value):
del self._info[tag]
self._data[tag] = value

def __delitem__(self, tag):
def __delitem__(self, tag: int) -> None:
if self._info is not None and tag in self._info:
del self._info[tag]
else:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageColor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def getrgb(color):


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

0 comments on commit 97a83de

Please sign in to comment.