Skip to content

Commit

Permalink
add typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed May 23, 2024
1 parent c9c8f5f commit 92b0424
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _open(self) -> None:
)

@Image.Image.size.setter
def size(self, value):
def size(self, value: tuple[int, int]) -> None:
info_size = value
if info_size not in self.info["sizes"] and len(info_size) == 2:
info_size = (info_size[0], info_size[1], 1)
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IcoImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def _open(self) -> None:
self.load()

@Image.Image.size.setter
def size(self, value):
def size(self, value: tuple[int, int]) -> None:
if value not in self.info["sizes"]:
msg = "This is not one of the allowed sizes of this image"
raise ValueError(msg)
Expand Down
12 changes: 6 additions & 6 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def __init__(self):
self.pyaccess = None
self._exif = None

def _use_im_values(self):
def _use_im_values(self) -> bool:
"""
Whether or not to try using values from self.im
in addition to the values in this class.
Expand All @@ -553,27 +553,27 @@ def size(self) -> tuple[int, int]:
return self.im.size
return self.__size

def _size(self, value):
def _size(self, value: tuple[int, int]) -> None:
# set im.size first in case it raises an exception
if self._use_im_values():
self.im.size = value
self.__size = value

_size = property(fset=_size)
_size: tuple[int, int] = property(fset=_size)

@property
def mode(self):
def mode(self) -> str:
if self._use_im_values():
return self.im.mode
return self.__mode

def _mode(self, value):
def _mode(self, value: str) -> None:
# set im.mode first in case it raises an exception
if self._use_im_values():
self.im.mode = value
self.__mode = value

_mode = property(fset=_mode)
_mode: str = property(fset=_mode)

def _new(self, im) -> Image:
new = Image()
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def get_format_mimetype(self):
if self.format is not None:
return Image.MIME.get(self.format.upper())

def _use_im_values(self):
def _use_im_values(self) -> bool:
return self.tile is None and self.im is not None

def __setstate__(self, state):
Expand Down

0 comments on commit 92b0424

Please sign in to comment.