From 44b2a94f2a088286fe1e218d8e061c38b124a810 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Thu, 23 Feb 2023 14:05:48 +0200 Subject: [PATCH] Apply ruff autofixes/noqas --- src/PIL/BdfFontFile.py | 2 +- src/PIL/GdImageFile.py | 2 +- src/PIL/Image.py | 4 ++-- src/PIL/ImageFile.py | 4 ++-- src/PIL/IptcImagePlugin.py | 3 +-- src/PIL/PcfFontFile.py | 4 ++-- src/PIL/PyAccess.py | 4 ++-- src/PIL/TiffImagePlugin.py | 2 +- src/PIL/features.py | 2 +- 9 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/PIL/BdfFontFile.py b/src/PIL/BdfFontFile.py index e0dd4dedefe..8d94b707110 100644 --- a/src/PIL/BdfFontFile.py +++ b/src/PIL/BdfFontFile.py @@ -64,7 +64,7 @@ def bdf_char(f): bitmap.append(s[:-1]) bitmap = b"".join(bitmap) - [x, y, l, d] = [int(p) for p in props["BBX"].split()] + [x, y, l, d] = [int(p) for p in props["BBX"].split()] # noqa: E741 [dx, dy] = [int(p) for p in props["DWIDTH"].split()] bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y) diff --git a/src/PIL/GdImageFile.py b/src/PIL/GdImageFile.py index 7dda4f14301..bafc43a19d4 100644 --- a/src/PIL/GdImageFile.py +++ b/src/PIL/GdImageFile.py @@ -47,7 +47,7 @@ def _open(self): # Header s = self.fp.read(1037) - if not i16(s) in [65534, 65535]: + if i16(s) not in [65534, 65535]: msg = "Not a valid GD 2.x .gd file" raise SyntaxError(msg) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 63bad83a1c3..27e5e0320d4 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -767,7 +767,7 @@ def tobytes(self, encoder_name="raw", *args): data = [] while True: - l, s, d = e.encode(bufsize) + l, s, d = e.encode(bufsize) # noqa: E741 data.append(d) if s: break @@ -1756,7 +1756,7 @@ def alpha_composite(self, im, dest=(0, 0), source=(0, 0)): if not isinstance(dest, (list, tuple)): msg = "Destination must be a tuple" raise ValueError(msg) - if not len(source) in (2, 4): + if len(source) not in (2, 4): msg = "Source must be a 2 or 4-tuple" raise ValueError(msg) if not len(dest) == 2: diff --git a/src/PIL/ImageFile.py b/src/PIL/ImageFile.py index 132490a8e23..f954f04a748 100644 --- a/src/PIL/ImageFile.py +++ b/src/PIL/ImageFile.py @@ -530,12 +530,12 @@ def _encode_tile(im, fp, tile, bufsize, fh, exc=None): encoder.setimage(im.im, b) if encoder.pushes_fd: encoder.setfd(fp) - l, s = encoder.encode_to_pyfd() + l, s = encoder.encode_to_pyfd() # noqa: E741 else: if exc: # compress to Python file-compatible object while True: - l, s, d = encoder.encode(bufsize) + l, s, d = encoder.encode(bufsize) # noqa: E741 fp.write(d) if s: break diff --git a/src/PIL/IptcImagePlugin.py b/src/PIL/IptcImagePlugin.py index 4c47b55c1a5..a08788c9123 100644 --- a/src/PIL/IptcImagePlugin.py +++ b/src/PIL/IptcImagePlugin.py @@ -18,10 +18,9 @@ import tempfile from . import Image, ImageFile -from ._binary import i8 +from ._binary import i8, o8 from ._binary import i16be as i16 from ._binary import i32be as i32 -from ._binary import o8 COMPRESSION = {1: "raw", 5: "jpeg"} diff --git a/src/PIL/PcfFontFile.py b/src/PIL/PcfFontFile.py index d5f510f0355..fe65853de04 100644 --- a/src/PIL/PcfFontFile.py +++ b/src/PIL/PcfFontFile.py @@ -86,7 +86,7 @@ def __init__(self, fp, charset_encoding="iso8859-1"): for ch, ix in enumerate(encoding): if ix is not None: - x, y, l, r, w, a, d, f = metrics[ix] + x, y, l, r, w, a, d, f = metrics[ix] # noqa: E741 glyph = (w, 0), (l, d - y, x + l, d), (0, 0, x, y), bitmaps[ix] self.glyph[ch] = glyph @@ -206,7 +206,7 @@ def _load_bitmaps(self, metrics): mode = "1" for i in range(nbitmaps): - x, y, l, r, w, a, d, f = metrics[i] + x, y, l, r, w, a, d, f = metrics[i] # noqa: E741 b, e = offsets[i], offsets[i + 1] bitmaps.append(Image.frombytes("1", (x, y), data[b:e], "raw", mode, pad(x))) diff --git a/src/PIL/PyAccess.py b/src/PIL/PyAccess.py index e9cb34ceda1..c68dfaea3ec 100644 --- a/src/PIL/PyAccess.py +++ b/src/PIL/PyAccess.py @@ -241,7 +241,7 @@ def set_pixel(self, x, y, color): except TypeError: color = min(color[0], 65535) - pixel.l = color & 0xFF # noqa: E741 + pixel.l = color & 0xFF pixel.r = color >> 8 @@ -262,7 +262,7 @@ def set_pixel(self, x, y, color): except Exception: color = min(color[0], 65535) - pixel.l = color >> 8 # noqa: E741 + pixel.l = color >> 8 pixel.r = color & 0xFF diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index aaaf8fcb928..c6e2a7d49bb 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1845,7 +1845,7 @@ def _save(im, fp, filename): e.setimage(im.im, (0, 0) + im.size) while True: # undone, change to self.decodermaxblock: - l, s, d = e.encode(16 * 1024) + l, s, d = e.encode(16 * 1024) # noqa: E741 if not _fp: fp.write(d) if s: diff --git a/src/PIL/features.py b/src/PIL/features.py index 6f9d99e765a..814099f27f3 100644 --- a/src/PIL/features.py +++ b/src/PIL/features.py @@ -24,7 +24,7 @@ def check_module(feature): :returns: ``True`` if available, ``False`` otherwise. :raises ValueError: If the module is not defined in this version of Pillow. """ - if not (feature in modules): + if feature not in modules: msg = f"Unknown module {feature}" raise ValueError(msg)