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 22, 2024
1 parent ce94c4f commit f38b2d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
22 changes: 10 additions & 12 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,38 +559,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

0 comments on commit f38b2d6

Please sign in to comment.