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 Aug 28, 2024
1 parent e1ec2f1 commit 906cb8e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
22 changes: 10 additions & 12 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,38 +585,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 @@ -701,7 +701,7 @@ def exif_transpose(image: Image.Image, *, in_place: bool = False) -> Image.Image
transposed_image = image.transpose(method)
if in_place:
image.im = transposed_image.im
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 906cb8e

Please sign in to comment.