Skip to content

Commit

Permalink
Adjust code for ruff-format style
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Aug 6, 2024
1 parent 4672bd3 commit 4eb6f7d
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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"
Expand Down
5 changes: 4 additions & 1 deletion Tests/test_font_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
)

Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagepath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 4 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def get_version():
)
)


_IMAGING = ("decode", "encode", "map", "display", "outline", "path")

_LIB_IMAGING = (
Expand Down Expand Up @@ -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"
)
Expand Down
1 change: 1 addition & 0 deletions src/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""
Parse X Bitmap Distribution Format (BDF)
"""

from __future__ import annotations

from typing import BinaryIO
Expand Down
1 change: 1 addition & 0 deletions src/PIL/ExifTags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/PIL/FontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions src/PIL/GdImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/PIL/GimpGradientFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/PIL/ImageDraw2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
.. seealso:: :py:mod:`PIL.ImageDraw`
"""

from __future__ import annotations

from typing import Any, AnyStr, BinaryIO
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/PIL/PdfParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/PIL/WalImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/PIL/_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


"""Binary input/output support routines."""

from __future__ import annotations

from struct import pack, unpack_from
Expand Down
3 changes: 1 addition & 2 deletions src/PIL/_tkinter_finder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
""" Find compiled module linking to Tcl / Tk libraries
"""
"""Find compiled module linking to Tcl / Tk libraries"""

from __future__ import annotations

Expand Down

0 comments on commit 4eb6f7d

Please sign in to comment.