From 4eb6f7d4d253bcf427911754bcb0232db660c88c Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 30 Oct 2023 20:14:30 +0200 Subject: [PATCH] Adjust code for ruff-format style --- Tests/helper.py | 4 ++-- Tests/test_file_jpeg.py | 8 ++------ Tests/test_file_libtiff.py | 3 +-- Tests/test_font_leaks.py | 5 ++++- Tests/test_imagedraw.py | 2 +- Tests/test_imagepath.py | 2 +- setup.py | 9 ++++----- src/PIL/BdfFontFile.py | 1 + src/PIL/ExifTags.py | 1 + src/PIL/FontFile.py | 4 +++- src/PIL/GdImageFile.py | 1 + src/PIL/GimpGradientFile.py | 1 + src/PIL/ImageDraw2.py | 1 + src/PIL/JpegImagePlugin.py | 2 +- src/PIL/PdfParser.py | 16 +++++++++------- src/PIL/WalImageFile.py | 1 + src/PIL/_binary.py | 1 + src/PIL/_tkinter_finder.py | 3 +-- 18 files changed, 36 insertions(+), 29 deletions(-) diff --git a/Tests/helper.py b/Tests/helper.py index d6a93a8030b..c266fc90e32 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -122,8 +122,8 @@ def assert_image_similar( ave_diff = diff / (a.size[0] * a.size[1]) try: assert epsilon >= ave_diff, ( - (msg or "") - + f" average pixel value difference {ave_diff:.4f} > epsilon {epsilon:.4f}" + f"{msg or ""} average pixel value difference " + f"{ave_diff:.4f} > epsilon {epsilon:.4f}" ) except Exception as e: try: diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index df589e24a1b..7c4d1b2592b 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -577,9 +577,7 @@ def _n_qtables_helper(n: int, test_file: str) -> None: 24 35 55 64 81 104 113 92 49 64 78 87 103 121 120 101 72 92 95 98 112 100 103 99 - """.split( - None - ) + """.split(None) ] standard_chrominance_qtable = [ @@ -593,9 +591,7 @@ def _n_qtables_helper(n: int, test_file: str) -> None: 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 - """.split( - None - ) + """.split(None) ] # list of qtable lists assert_image_similar( diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 62f8719af53..0fa669c69f7 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -313,7 +313,7 @@ class Tc(NamedTuple): } def check_tags( - tiffinfo: TiffImagePlugin.ImageFileDirectory_v2 | dict[int, str] + tiffinfo: TiffImagePlugin.ImageFileDirectory_v2 | dict[int, str], ) -> None: im = hopper() @@ -626,7 +626,6 @@ def test_4bit(self, monkeypatch: pytest.MonkeyPatch) -> None: # Act monkeypatch.setattr(TiffImagePlugin, "READ_LIBTIFF", True) with Image.open(test_file) as im: - # Assert assert im.size == (128, 128) assert im.mode == "L" diff --git a/Tests/test_font_leaks.py b/Tests/test_font_leaks.py index ab8a7f9ecca..6cebc59421b 100644 --- a/Tests/test_font_leaks.py +++ b/Tests/test_font_leaks.py @@ -17,7 +17,10 @@ def _test_font(self, font: ImageFont.FreeTypeFont | ImageFont.ImageFont) -> None draw = ImageDraw.ImageDraw(im) self._test_leak( lambda: draw.text( - (0, 0), "some text " * 1024, font=font, fill="black" # ~10k + (0, 0), + "some text " * 1024, # ~10k + font=font, + fill="black", ) ) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index e397978cbbf..2a3484d486c 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -812,7 +812,7 @@ def test_rounded_rectangle( tuple[int, int, int, int] | tuple[list[int]] | tuple[tuple[int, int], tuple[int, int]] - ) + ), ) -> None: # Arrange im = Image.new("RGB", (200, 200)) diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index cda2584e77b..c5de8a36079 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -79,7 +79,7 @@ def test_path_constructors( ), ) def test_invalid_path_constructors( - coords: tuple[str, str] | Sequence[Sequence[int]] + coords: tuple[str, str] | Sequence[Sequence[int]], ) -> None: # Act with pytest.raises(ValueError) as e: diff --git a/setup.py b/setup.py index b26852b0b07..40ad775e6e0 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,6 @@ def get_version(): ) ) - _IMAGING = ("decode", "encode", "map", "display", "outline", "path") _LIB_IMAGING = ( @@ -431,11 +430,11 @@ def get_macos_sdk_path(self): ) except Exception: sdk_path = None - if ( - not sdk_path - or sdk_path == "/Applications/Xcode.app/Contents/Developer" + xcode_sdk_path = ( + "/Applications/Xcode.app/Contents/Developer" "/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" - ): + ) + if not sdk_path or sdk_path == xcode_sdk_path: commandlinetools_sdk_path = ( "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" ) diff --git a/src/PIL/BdfFontFile.py b/src/PIL/BdfFontFile.py index bc1416c74c6..b4a3fd17e72 100644 --- a/src/PIL/BdfFontFile.py +++ b/src/PIL/BdfFontFile.py @@ -20,6 +20,7 @@ """ Parse X Bitmap Distribution Format (BDF) """ + from __future__ import annotations from typing import BinaryIO diff --git a/src/PIL/ExifTags.py b/src/PIL/ExifTags.py index 39b4aa55262..a90e8f43083 100644 --- a/src/PIL/ExifTags.py +++ b/src/PIL/ExifTags.py @@ -13,6 +13,7 @@ This module provides constants and clear-text names for various well-known EXIF tags. """ + from __future__ import annotations from enum import IntEnum diff --git a/src/PIL/FontFile.py b/src/PIL/FontFile.py index 1e0c1c166b5..3ec1ae819fc 100644 --- a/src/PIL/FontFile.py +++ b/src/PIL/FontFile.py @@ -50,7 +50,9 @@ def __init__(self) -> None: | None ] = [None] * 256 - def __getitem__(self, ix: int) -> ( + def __getitem__( + self, ix: int + ) -> ( tuple[ tuple[int, int], tuple[int, int, int, int], diff --git a/src/PIL/GdImageFile.py b/src/PIL/GdImageFile.py index 88b87a22cd6..243688bc5c1 100644 --- a/src/PIL/GdImageFile.py +++ b/src/PIL/GdImageFile.py @@ -25,6 +25,7 @@ class is not registered for use with :py:func:`PIL.Image.open()`. To open a implementation is provided for convenience and demonstrational purposes only. """ + from __future__ import annotations from typing import IO diff --git a/src/PIL/GimpGradientFile.py b/src/PIL/GimpGradientFile.py index 220eac57e38..f7d676d3ac8 100644 --- a/src/PIL/GimpGradientFile.py +++ b/src/PIL/GimpGradientFile.py @@ -18,6 +18,7 @@ the corresponding code in GIMP, written by Federico Mena Quintero. See the GIMP distribution for more information.) """ + from __future__ import annotations from math import log, pi, sin, sqrt diff --git a/src/PIL/ImageDraw2.py b/src/PIL/ImageDraw2.py index 3d68658ed5b..3f7036e83d3 100644 --- a/src/PIL/ImageDraw2.py +++ b/src/PIL/ImageDraw2.py @@ -22,6 +22,7 @@ .. seealso:: :py:mod:`PIL.ImageDraw` """ + from __future__ import annotations from typing import Any, AnyStr, BinaryIO diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index fc897e2b919..52dfe4c32a7 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -698,7 +698,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: def validate_qtables( qtables: ( str | tuple[list[int], ...] | list[list[int]] | dict[int, list[int]] | None - ) + ), ) -> list[list[int]] | None: if qtables is None: return qtables diff --git a/src/PIL/PdfParser.py b/src/PIL/PdfParser.py index 7cb2d241bc2..6fc507624a6 100644 --- a/src/PIL/PdfParser.py +++ b/src/PIL/PdfParser.py @@ -113,13 +113,15 @@ def __str__(self) -> str: class XrefTable: def __init__(self) -> None: - self.existing_entries: dict[int, tuple[int, int]] = ( - {} - ) # object ID => (offset, generation) - self.new_entries: dict[int, tuple[int, int]] = ( - {} - ) # object ID => (offset, generation) - self.deleted_entries = {0: 65536} # object ID => generation + # object ID => (offset, generation) + self.existing_entries: dict[int, tuple[int, int]] = {} + + # object ID => (offset, generation) + self.new_entries: dict[int, tuple[int, int]] = {} + + # object ID => generation + self.deleted_entries = {0: 65536} + self.reading_finished = False def __setitem__(self, key: int, value: tuple[int, int]) -> None: diff --git a/src/PIL/WalImageFile.py b/src/PIL/WalImageFile.py index ec5c7490001..1599bc74ffc 100644 --- a/src/PIL/WalImageFile.py +++ b/src/PIL/WalImageFile.py @@ -22,6 +22,7 @@ is not registered for use with :py:func:`PIL.Image.open()`. To open a WAL file, use the :py:func:`PIL.WalImageFile.open()` function instead. """ + from __future__ import annotations from typing import IO diff --git a/src/PIL/_binary.py b/src/PIL/_binary.py index 4594ccce361..d3236c17abb 100644 --- a/src/PIL/_binary.py +++ b/src/PIL/_binary.py @@ -13,6 +13,7 @@ """Binary input/output support routines.""" + from __future__ import annotations from struct import pack, unpack_from diff --git a/src/PIL/_tkinter_finder.py b/src/PIL/_tkinter_finder.py index beddfb0628a..9c0143003a7 100644 --- a/src/PIL/_tkinter_finder.py +++ b/src/PIL/_tkinter_finder.py @@ -1,5 +1,4 @@ -""" Find compiled module linking to Tcl / Tk libraries -""" +"""Find compiled module linking to Tcl / Tk libraries""" from __future__ import annotations