Skip to content

Commit

Permalink
Merge pull request #7480 from radarhere/lint
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Oct 19, 2023
2 parents 0a6fcc2 + e760b02 commit a10dec0
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 21 deletions.
3 changes: 1 addition & 2 deletions Tests/test_file_palm.py
Expand Up @@ -26,8 +26,7 @@ def open_with_magick(magick, tmp_path, f):
rc = subprocess.call(
magick + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
)
if rc:
raise OSError
assert not rc
return Image.open(outfile)


Expand Down
3 changes: 2 additions & 1 deletion src/PIL/FliImagePlugin.py
Expand Up @@ -150,7 +150,8 @@ def _seek(self, frame):

s = self.fp.read(4)
if not s:
raise EOFError
msg = "missing frame size"
raise EOFError(msg)

framesize = i32(s)

Expand Down
6 changes: 4 additions & 2 deletions src/PIL/GifImagePlugin.py
Expand Up @@ -183,7 +183,8 @@ def _seek(self, frame, update_image=True):

s = self.fp.read(1)
if not s or s == b";":
raise EOFError
msg = "no more images in GIF file"
raise EOFError(msg)

palette = None

Expand Down Expand Up @@ -288,7 +289,8 @@ def _seek(self, frame, update_image=True):

if interlace is None:
# self._fp = None
raise EOFError
msg = "image not found in GIF frame"
raise EOFError(msg)

self.__frame = frame
if not update_image:
Expand Down
6 changes: 4 additions & 2 deletions src/PIL/Image.py
Expand Up @@ -1862,7 +1862,8 @@ def putalpha(self, alpha):
# do things the hard way
im = self.im.convert(mode)
if im.mode not in ("LA", "PA", "RGBA"):
raise ValueError from e # sanity check
msg = "alpha channel could not be added"
raise ValueError(msg) from e # sanity check
self.im = im
self.pyaccess = None
self._mode = self.im.mode
Expand Down Expand Up @@ -2467,7 +2468,8 @@ def seek(self, frame):

# overridden by file handlers
if frame != 0:
raise EOFError
msg = "no more images in file"
raise EOFError(msg)

def show(self, title=None):
"""
Expand Down
10 changes: 6 additions & 4 deletions src/PIL/ImageFile.py
Expand Up @@ -200,8 +200,8 @@ def load(self):
with open(self.filename) as fp:
self.map = mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)
if offset + self.size[1] * args[1] > self.map.size():
# buffer is not large enough
raise OSError
msg = "buffer is not large enough"
raise OSError(msg)
self.im = Image.core.map_buffer(
self.map, self.size, decoder_name, offset, args
)
Expand Down Expand Up @@ -690,7 +690,8 @@ def decode(self, buffer):
If finished with decoding return -1 for the bytes consumed.
Err codes are from :data:`.ImageFile.ERRORS`.
"""
raise NotImplementedError()
msg = "unavailable in base decoder"
raise NotImplementedError(msg)

def set_as_raw(self, data, rawmode=None):
"""
Expand Down Expand Up @@ -739,7 +740,8 @@ def encode(self, bufsize):
If finished with encoding return 1 for the error code.
Err codes are from :data:`.ImageFile.ERRORS`.
"""
raise NotImplementedError()
msg = "unavailable in base encoder"
raise NotImplementedError(msg)

def encode_to_pyfd(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/ImagePalette.py
Expand Up @@ -205,7 +205,8 @@ def make_linear_lut(black, white):
for i in range(256):
lut.append(white * i // 255)
else:
raise NotImplementedError # FIXME
msg = "unavailable when black is non-zero"
raise NotImplementedError(msg) # FIXME
return lut


Expand Down
6 changes: 4 additions & 2 deletions src/PIL/ImageSequence.py
Expand Up @@ -40,7 +40,8 @@ def __getitem__(self, ix):
self.im.seek(ix)
return self.im
except EOFError as e:
raise IndexError from e # end of sequence
msg = "end of sequence"
raise IndexError(msg) from e

def __iter__(self):
return self
Expand All @@ -51,7 +52,8 @@ def __next__(self):
self.position += 1
return self.im
except EOFError as e:
raise StopIteration from e
msg = "end of sequence"
raise StopIteration(msg) from e


def all_frames(im, func=None):
Expand Down
3 changes: 2 additions & 1 deletion src/PIL/ImageShow.py
Expand Up @@ -99,7 +99,8 @@ def get_command(self, file, **options):
Returns the command used to display the file.
Not implemented in the base class.
"""
raise NotImplementedError
msg = "unavailable in base viewer"
raise NotImplementedError(msg)

def save_image(self, image):
"""Save to temporary file and return filename."""
Expand Down
6 changes: 4 additions & 2 deletions src/PIL/JpegImagePlugin.py
Expand Up @@ -165,7 +165,8 @@ def APP(self, marker):
except TypeError:
dpi = x_resolution
if math.isnan(dpi):
raise ValueError
msg = "DPI is not a number"
raise ValueError(msg)
if resolution_unit == 3: # cm
# 1 dpcm = 2.54 dpi
dpi *= 2.54
Expand Down Expand Up @@ -719,7 +720,8 @@ def validate_qtables(qtables):
for idx, table in enumerate(qtables):
try:
if len(table) != 64:
raise TypeError
msg = "Invalid quantization table"
raise TypeError(msg)
table = array.array("H", table)
except TypeError as e:
msg = "Invalid quantization table"
Expand Down
10 changes: 6 additions & 4 deletions src/PIL/PngImagePlugin.py
Expand Up @@ -438,11 +438,12 @@ def chunk_IDAT(self, pos, length):
tile = [("zip", (0, 0) + self.im_size, pos, self.im_rawmode)]
self.im_tile = tile
self.im_idat = length
raise EOFError
msg = "image data found"
raise EOFError(msg)

def chunk_IEND(self, pos, length):
# end of PNG image
raise EOFError
msg = "end of PNG image"
raise EOFError(msg)

def chunk_PLTE(self, pos, length):
# palette
Expand Down Expand Up @@ -891,7 +892,8 @@ def _seek(self, frame, rewind=False):
self.dispose_extent = self.info.get("bbox")

if not self.tile:
raise EOFError
msg = "image not found in APNG frame"
raise EOFError(msg)

# setup frame disposal (actual disposal done when needed in the next _seek())
if self._prev_im is None and self.dispose_op == Disposal.OP_PREVIOUS:
Expand Down

0 comments on commit a10dec0

Please sign in to comment.