Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if self.im is not None #6108

Merged
merged 1 commit into from Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions Tests/test_image_access.py
Expand Up @@ -154,14 +154,17 @@ def check(self, mode, c=None):

# Check 0
im = Image.new(mode, (0, 0), None)
with pytest.raises(IndexError):
assert im.load() is not None

error = ValueError if self._need_cffi_access else IndexError
with pytest.raises(error):
im.putpixel((0, 0), c)
with pytest.raises(IndexError):
with pytest.raises(error):
im.getpixel((0, 0))
# Check 0 negative index
with pytest.raises(IndexError):
with pytest.raises(error):
im.putpixel((-1, -1), c)
with pytest.raises(IndexError):
with pytest.raises(error):
im.getpixel((-1, -1))

# check initial color
Expand All @@ -176,10 +179,10 @@ def check(self, mode, c=None):

# Check 0
im = Image.new(mode, (0, 0), c)
with pytest.raises(IndexError):
with pytest.raises(error):
im.getpixel((0, 0))
# Check 0 negative index
with pytest.raises(IndexError):
with pytest.raises(error):
im.getpixel((-1, -1))

def test_basic(self):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/GifImagePlugin.py
Expand Up @@ -298,7 +298,7 @@ def _rgb(color):
self.dispose = Image.core.fill(dispose_mode, dispose_size, color)
else:
# replace with previous contents
if self.im:
if self.im is not None:
# only dispose the extent in this frame
self.dispose = self._crop(self.im, self.dispose_extent)
elif frame_transparency is not None:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IcnsImagePlugin.py
Expand Up @@ -287,7 +287,7 @@ def load(self):
)

px = Image.Image.load(self)
if self.im and self.im.size == self.size:
if self.im is not None and self.im.size == self.size:
# Already loaded
return px
self.load_prepare()
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/IcoImagePlugin.py
Expand Up @@ -304,7 +304,7 @@ def size(self, value):
self._size = value

def load(self):
if self.im and self.im.size == self.size:
if self.im is not None and self.im.size == self.size:
# Already loaded
return Image.Image.load(self)
im = self.ico.getimage(self.size)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/Image.py
Expand Up @@ -847,7 +847,7 @@ def load(self):
:returns: An image access object.
:rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess`
"""
if self.im and self.palette and self.palette.dirty:
if self.im is not None and self.palette and self.palette.dirty:
# realize palette
mode, arr = self.palette.getdata()
self.im.putpalette(mode, arr)
Expand All @@ -864,7 +864,7 @@ def load(self):
self.palette.mode = palette_mode
self.palette.palette = self.im.getpalette(palette_mode, palette_mode)

if self.im:
if self.im is not None:
if cffi and USE_CFFI_ACCESS:
if self.pyaccess:
return self.pyaccess
Expand Down