PERF203 and fixes
This commit is contained in:
parent
090ca9461b
commit
754c7ea3a0
@ -56,7 +56,7 @@ def test_questionable() -> None:
|
||||
im.load()
|
||||
if os.path.basename(f) not in supported:
|
||||
print(f"Please add {f} to the partially supported bmp specs.")
|
||||
except Exception: # as msg:
|
||||
except Exception: # noqa: PERF203
|
||||
if os.path.basename(f) in supported:
|
||||
raise
|
||||
|
||||
@ -106,7 +106,7 @@ def test_good() -> None:
|
||||
|
||||
assert_image_similar(im_converted, compare_converted, 5)
|
||||
|
||||
except Exception as msg:
|
||||
except Exception as msg: # noqa: PERF203
|
||||
# there are three here that are unsupported:
|
||||
unsupported = (
|
||||
os.path.join(base, "g", "rgb32bf.bmp"),
|
||||
|
||||
@ -224,10 +224,7 @@ class TestFileLibTiff(LibTiffTestCase):
|
||||
with Image.open("Tests/images/hopper_g4.tif") as im:
|
||||
assert isinstance(im, TiffImagePlugin.TiffImageFile)
|
||||
for tag in im.tag_v2:
|
||||
try:
|
||||
del core_items[tag]
|
||||
except KeyError:
|
||||
pass
|
||||
core_items.pop(tag, None)
|
||||
del core_items[320] # colormap is special, tested below
|
||||
|
||||
# Type codes:
|
||||
|
||||
@ -139,26 +139,22 @@ exclude = "wheels/multibuild"
|
||||
exclude = [ "wheels/multibuild" ]
|
||||
fix = true
|
||||
lint.select = [
|
||||
"C4", # flake8-comprehensions
|
||||
"E", # pycodestyle errors
|
||||
"EM", # flake8-errmsg
|
||||
"F", # pyflakes errors
|
||||
"I", # isort
|
||||
"ISC", # flake8-implicit-str-concat
|
||||
"LOG", # flake8-logging
|
||||
"PERF101", # perflint: unnecessary-list-cast
|
||||
"PERF102", # perflint: incorrect-dict-iterator
|
||||
"PERF401", # perflint: manual-list-comprehension
|
||||
"PERF402", # perflint: manual-list-copy
|
||||
"PERF403", # perflint: manual-dict-comprehension
|
||||
"PGH", # pygrep-hooks
|
||||
"PIE", # flake8-pie
|
||||
"PT", # flake8-pytest-style
|
||||
"PYI", # flake8-pyi
|
||||
"RUF100", # unused noqa (yesqa)
|
||||
"UP", # pyupgrade
|
||||
"W", # pycodestyle warnings
|
||||
"YTT", # flake8-2020
|
||||
"C4", # flake8-comprehensions
|
||||
"E", # pycodestyle errors
|
||||
"EM", # flake8-errmsg
|
||||
"F", # pyflakes errors
|
||||
"I", # isort
|
||||
"ISC", # flake8-implicit-str-concat
|
||||
"LOG", # flake8-logging
|
||||
"PERF", # perflint
|
||||
"PGH", # pygrep-hooks
|
||||
"PIE", # flake8-pie
|
||||
"PT", # flake8-pytest-style
|
||||
"PYI", # flake8-pyi
|
||||
"RUF100", # unused noqa (yesqa)
|
||||
"UP", # pyupgrade
|
||||
"W", # pycodestyle warnings
|
||||
"YTT", # flake8-2020
|
||||
]
|
||||
lint.ignore = [
|
||||
"E203", # Whitespace before ':'
|
||||
|
||||
2
setup.py
2
setup.py
@ -302,7 +302,7 @@ def _pkg_config(name: str) -> tuple[list[str], list[str]] | None:
|
||||
subprocess.check_output(command_cflags).decode("utf8").strip(),
|
||||
)[::2][1:]
|
||||
return libs, cflags
|
||||
except Exception:
|
||||
except Exception: # noqa: PERF203
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
@ -167,7 +167,7 @@ class GifImageFile(ImageFile.ImageFile):
|
||||
for f in range(self.__frame + 1, frame + 1):
|
||||
try:
|
||||
self._seek(f)
|
||||
except EOFError as e:
|
||||
except EOFError as e: # noqa: PERF203
|
||||
self.seek(last_frame)
|
||||
msg = "no more images in GIF file"
|
||||
raise EOFError(msg) from e
|
||||
|
||||
@ -488,7 +488,7 @@ def init() -> bool:
|
||||
try:
|
||||
logger.debug("Importing %s", plugin)
|
||||
__import__(f"{__spec__.parent}.{plugin}", globals(), locals(), [])
|
||||
except ImportError as e:
|
||||
except ImportError as e: # noqa: PERF203
|
||||
logger.debug("Image: failed to import %s: %s", plugin, e)
|
||||
|
||||
if OPEN or SAVE:
|
||||
|
||||
@ -930,7 +930,7 @@ def load_path(filename: str | bytes) -> ImageFont:
|
||||
for directory in sys.path:
|
||||
try:
|
||||
return load(os.path.join(directory, filename))
|
||||
except OSError:
|
||||
except OSError: # noqa: PERF203
|
||||
pass
|
||||
msg = f'cannot find font file "{filename}" in sys.path'
|
||||
if os.path.exists(filename):
|
||||
|
||||
@ -198,13 +198,11 @@ class ImagePalette:
|
||||
try:
|
||||
fp.write("# Palette\n")
|
||||
fp.write(f"# Mode: {self.mode}\n")
|
||||
palette_len = len(self.palette)
|
||||
for i in range(256):
|
||||
fp.write(f"{i}")
|
||||
for j in range(i * len(self.mode), (i + 1) * len(self.mode)):
|
||||
try:
|
||||
fp.write(f" {self.palette[j]}")
|
||||
except IndexError:
|
||||
fp.write(" 0")
|
||||
fp.write(f" {self.palette[j] if j < palette_len else 0}")
|
||||
fp.write("\n")
|
||||
finally:
|
||||
if open_fp:
|
||||
|
||||
@ -153,7 +153,7 @@ def APP(self: JpegImageFile, marker: int) -> None:
|
||||
photoshop[code] = data
|
||||
offset += size
|
||||
offset += offset & 1 # align
|
||||
except struct.error:
|
||||
except struct.error: # noqa: PERF203
|
||||
break # insufficient data
|
||||
|
||||
elif marker == 0xFFEE and s.startswith(b"Adobe"):
|
||||
@ -744,7 +744,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||
msg = "Invalid quantization table"
|
||||
raise TypeError(msg)
|
||||
table_array = array.array("H", table)
|
||||
except TypeError as e:
|
||||
except TypeError as e: # noqa: PERF203
|
||||
msg = "Invalid quantization table"
|
||||
raise ValueError(msg) from e
|
||||
else:
|
||||
|
||||
@ -251,7 +251,7 @@ class PcfFontFile(FontFile.FontFile):
|
||||
]
|
||||
if encoding_offset != 0xFFFF:
|
||||
encoding[i] = encoding_offset
|
||||
except UnicodeDecodeError:
|
||||
except UnicodeDecodeError: # noqa: PERF203
|
||||
# character is not supported in selected encoding
|
||||
pass
|
||||
|
||||
|
||||
@ -869,7 +869,7 @@ class PngImageFile(ImageFile.ImageFile):
|
||||
for f in range(self.__frame + 1, frame + 1):
|
||||
try:
|
||||
self._seek(f)
|
||||
except EOFError as e:
|
||||
except EOFError as e: # noqa: PERF203
|
||||
self.seek(last_frame)
|
||||
msg = "no more images in APNG file"
|
||||
raise EOFError(msg) from e
|
||||
|
||||
Loading…
Reference in New Issue
Block a user