Skip to content

Commit

Permalink
remove _size and _mode getters
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Jun 28, 2024
1 parent 7e65933 commit aba2b93
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def _seek(self, frame: int, update_image: bool = True) -> None:
x1, y1 = x0 + i16(s, 4), y0 + i16(s, 6)
if (x1 > self.size[0] or y1 > self.size[1]) and update_image:
self._size = max(x1, self.size[0]), max(y1, self.size[1])
Image._decompression_bomb_check(self._size)
Image._decompression_bomb_check(self.size)
frame_dispose_extent = x0, y0, x1, y1
flags = s[8]

Expand Down
22 changes: 10 additions & 12 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,38 +570,36 @@ def height(self) -> int:

@property
def size(self) -> tuple[int, int]:
return self._size

@property
def _size(self) -> tuple[int, int]:
if self._use_im_values():
return self.im.size
return self.__size

@_size.setter
def _size(self, value: tuple[int, int]) -> None:
def _set_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

@property
def mode(self) -> str:
return self._mode
# MyPy doesn't support "x = property(...)"
# https://github.com/python/mypy/issues/8083
_size: tuple[int, int] = cast(Tuple[int, int], property(fset=_set_size))

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

@_mode.setter
def _mode(self, value: str) -> None:
def _set_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

# MyPy doesn't support "x = property(...)"
# https://github.com/python/mypy/issues/8083
_mode: str = cast(str, property(fset=_set_mode))

def _new(self, im: core.ImagingCore) -> Image:
new = Image()
new.im = im
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image
if in_place:
image.im = transposed_image.im
image.pyaccess = None
image._size = transposed_image._size
image._size = transposed_image.size
exif_image = image if in_place else transposed_image

exif = exif_image.getexif()
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _open(self) -> None:
# Don't trust the passed in stride.
# Calculate the approximate position for ourselves.
# CVE-2020-35653
stride = (self._size[0] * bits + 7) // 8
stride = (self.size[0] * bits + 7) // 8

# While the specification states that this must be even,
# not all images follow this
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/QoiImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _open(self) -> None:
self._mode = "RGB" if channels == 3 else "RGBA"

self.fp.seek(1, os.SEEK_CUR) # colorspace
self.tile = [("qoi", (0, 0) + self._size, self.fp.tell(), None)]
self.tile = [("qoi", (0, 0) + self.size, self.fp.tell(), None)]


class QoiDecoder(ImageFile.PyDecoder):
Expand Down

0 comments on commit aba2b93

Please sign in to comment.