Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
rev: v0.14.14
hooks:
- id: ruff-check
args: [--exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black

- repo: https://github.com/PyCQA/bandit
rev: 1.9.2
rev: 1.9.3
hooks:
- id: bandit
args: [--severity-level=high]
files: ^src/

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
rev: v1.5.6
hooks:
- id: remove-tabs
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)
Expand Down Expand Up @@ -51,14 +51,14 @@ repos:
exclude: ^\.github/.*TEMPLATE|^Tests/(fonts|images)/

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.36.0
rev: 0.36.1
hooks:
- id: check-github-workflows
- id: check-readthedocs
- id: check-renovate

- repo: https://github.com/zizmorcore/zizmor-pre-commit
rev: v1.19.0
rev: v1.22.0
hooks:
- id: zizmor

Expand All @@ -68,7 +68,7 @@ repos:
- id: sphinx-lint

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.11.1
rev: v2.12.1
hooks:
- id: pyproject-fmt

Expand Down
4 changes: 2 additions & 2 deletions Tests/test_arro3.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class DataShape(NamedTuple):
),
)
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
(dtype, elt, elts_per_pixel) = data_tp
dtype, elt, elts_per_pixel = data_tp

ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
if dtype == fl_uint8_4_type:
Expand All @@ -239,7 +239,7 @@ def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> Non
)
@pytest.mark.parametrize("data_tp", (UINT32, INT32))
def test_from_int32array(mode: str, mask: list[int] | None, data_tp: DataShape) -> None:
(dtype, elt, elts_per_pixel) = data_tp
dtype, elt, elts_per_pixel = data_tp

ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
arr = Array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
Expand Down
8 changes: 4 additions & 4 deletions Tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_multiblock_l_image() -> None:
img = Image.new("L", size, 128)

with pytest.raises(ValueError):
(schema, arr) = img.__arrow_c_array__()
schema, arr = img.__arrow_c_array__()


def test_multiblock_rgba_image() -> None:
Expand All @@ -79,7 +79,7 @@ def test_multiblock_rgba_image() -> None:
img = Image.new("RGBA", size, (128, 127, 126, 125))

with pytest.raises(ValueError):
(schema, arr) = img.__arrow_c_array__()
schema, arr = img.__arrow_c_array__()


def test_multiblock_l_schema() -> None:
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_singleblock_l_image() -> None:
img = Image.new("L", size, 128)
assert img.im.isblock()

(schema, arr) = img.__arrow_c_array__()
schema, arr = img.__arrow_c_array__()
assert schema
assert arr

Expand All @@ -130,7 +130,7 @@ def test_singleblock_rgba_image() -> None:
img = Image.new("RGBA", size, (128, 127, 126, 125))
assert img.im.isblock()

(schema, arr) = img.__arrow_c_array__()
schema, arr = img.__arrow_c_array__()
assert schema
assert arr
Image.core.set_use_block_allocator(0)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ def test_getdata(monkeypatch: pytest.MonkeyPatch) -> None:
# with open('Tests/images/gif_header_data.pkl', 'wb') as f:
# pickle.dump((h, d), f, 1)
with open("Tests/images/gif_header_data.pkl", "rb") as f:
(h_target, d_target) = pickle.load(f)
h_target, d_target = pickle.load(f)

assert h == h_target
assert d == d_target
Expand Down
18 changes: 4 additions & 14 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,7 @@ def _n_qtables_helper(n: int, test_file: str) -> None:
assert im2.quantization == {0: bounds_qtable}

# values from wizard.txt in jpeg9-a src package.
standard_l_qtable = [
int(s)
for s in """
standard_l_qtable = [int(s) for s in """
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
Expand All @@ -601,14 +599,9 @@ 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 = [
int(s)
for s in """
standard_chrominance_qtable = [int(s) for s in """
17 18 24 47 99 99 99 99
18 21 26 66 99 99 99 99
24 26 56 99 99 99 99 99
Expand All @@ -617,10 +610,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)]

for quality in range(101):
qtable_from_qtable_quality = self.roundtrip(
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_font_pcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_textsize(request: pytest.FixtureRequest, tmp_path: Path) -> None:
tempname = save_font(request, tmp_path)
font = ImageFont.load(tempname)
for i in range(255):
(ox, oy, dx, dy) = font.getbbox(chr(i))
ox, oy, dx, dy = font.getbbox(chr(i))
assert ox == 0
assert oy == 0
assert dy == 20
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_font_pcf_charsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_textsize(
tempname = save_font(request, tmp_path, encoding)
font = ImageFont.load(tempname)
for i in range(255):
(ox, oy, dx, dy) = font.getbbox(bytearray([i]))
ox, oy, dx, dy = font.getbbox(bytearray([i]))
assert ox == 0
assert oy == 0
assert dy == 20
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_format_hsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def linear_gradient() -> Image.Image:
im = Image.linear_gradient(mode="L")
im90 = im.rotate(90)

(px, h) = im.size
px, h = im.size

r = Image.new("L", (px * 3, h))
g = r.copy()
Expand All @@ -54,7 +54,7 @@ def to_xxx_colorsys(
) -> Image.Image:
# convert the hard way using the library colorsys routines.

(r, g, b) = im.split()
r, g, b = im.split()

conv_func = int_to_float

Expand Down
6 changes: 2 additions & 4 deletions Tests/test_image_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ def test_embeddable(self) -> None:

with open("embed_pil.c", "w", encoding="utf-8") as fh:
home = sys.prefix.replace("\\", "\\\\")
fh.write(
f"""
fh.write(f"""
#include "Python.h"

int main(int argc, char* argv[])
Expand All @@ -300,8 +299,7 @@ def test_embeddable(self) -> None:

return 0;
}}
"""
)
""")

objects = compiler.compile(["embed_pil.c"])
compiler.link_executable(objects, "embed_pil")
Expand Down
14 changes: 7 additions & 7 deletions Tests/test_image_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_palette(self) -> None:

def test_extent(self) -> None:
im = hopper("RGB")
(w, h) = im.size
w, h = im.size
transformed = im.transform(
im.size,
Image.Transform.EXTENT,
Expand All @@ -72,7 +72,7 @@ def test_extent(self) -> None:
def test_quad(self) -> None:
# one simple quad transform, equivalent to scale & crop upper left quad
im = hopper("RGB")
(w, h) = im.size
w, h = im.size
transformed = im.transform(
im.size,
Image.Transform.QUAD,
Expand All @@ -99,7 +99,7 @@ def test_quad(self) -> None:
)
def test_fill(self, mode: str, expected_pixel: tuple[int, ...]) -> None:
im = hopper(mode)
(w, h) = im.size
w, h = im.size
transformed = im.transform(
im.size,
Image.Transform.EXTENT,
Expand All @@ -112,7 +112,7 @@ def test_fill(self, mode: str, expected_pixel: tuple[int, ...]) -> None:
def test_mesh(self) -> None:
# this should be a checkerboard of halfsized hoppers in ul, lr
im = hopper("RGBA")
(w, h) = im.size
w, h = im.size
transformed = im.transform(
im.size,
Image.Transform.MESH,
Expand Down Expand Up @@ -174,7 +174,7 @@ def op(im: Image.Image, sz: tuple[int, int]) -> Image.Image:

def test_alpha_premult_transform(self) -> None:
def op(im: Image.Image, sz: tuple[int, int]) -> Image.Image:
(w, h) = im.size
w, h = im.size
return im.transform(
sz, Image.Transform.EXTENT, (0, 0, w, h), Image.Resampling.BILINEAR
)
Expand Down Expand Up @@ -216,7 +216,7 @@ def op(im: Image.Image, sz: tuple[int, int]) -> Image.Image:
@pytest.mark.parametrize("mode", ("RGBA", "LA"))
def test_nearest_transform(self, mode: str) -> None:
def op(im: Image.Image, sz: tuple[int, int]) -> Image.Image:
(w, h) = im.size
w, h = im.size
return im.transform(
sz, Image.Transform.EXTENT, (0, 0, w, h), Image.Resampling.NEAREST
)
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_missing_method_data(self) -> None:
@pytest.mark.parametrize("resample", (Image.Resampling.BOX, "unknown"))
def test_unknown_resampling_filter(self, resample: Image.Resampling | str) -> None:
with hopper() as im:
(w, h) = im.size
w, h = im.size
with pytest.raises(ValueError):
im.transform((100, 100), Image.Transform.EXTENT, (0, 0, w, h), resample) # type: ignore[arg-type]

Expand Down
6 changes: 2 additions & 4 deletions Tests/test_imagemorph.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ def string_to_img(image_string: str) -> Image.Image:
return im


A = string_to_img(
"""
A = string_to_img("""
.......
.......
..111..
..111..
..111..
.......
.......
"""
)
""")


def img_to_string(im: Image.Image) -> str:
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagewin_pointers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def serialize_dib(bi: BITMAPINFOHEADER, pixels: ctypes.c_void_p) -> bytearray:

def test_pointer(tmp_path: Path) -> None:
im = hopper()
(width, height) = im.size
width, height = im.size
opath = tmp_path / "temp.png"
imdib = ImageWin.Dib(im)

Expand Down
4 changes: 2 additions & 2 deletions Tests/test_nanoarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class DataShape(NamedTuple):
),
)
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
(dtype, elt, elts_per_pixel) = data_tp
dtype, elt, elts_per_pixel = data_tp

ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
if dtype == fl_uint8_4_type:
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> Non
)
@pytest.mark.parametrize("data_tp", (UINT32, INT32))
def test_from_int32array(mode: str, mask: list[int] | None, data_tp: DataShape) -> None:
(dtype, elt, elts_per_pixel) = data_tp
dtype, elt, elts_per_pixel = data_tp

ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
arr = nanoarrow.Array(
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_pyarrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class DataShape(NamedTuple):
),
)
def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
(dtype, elt, elts_per_pixel) = data_tp
dtype, elt, elts_per_pixel = data_tp

ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
arr = pyarrow.array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
Expand All @@ -238,7 +238,7 @@ def test_fromarray(mode: str, data_tp: DataShape, mask: list[int] | None) -> Non
),
)
def test_from_int32array(mode: str, data_tp: DataShape, mask: list[int] | None) -> None:
(dtype, elt, elts_per_pixel) = data_tp
dtype, elt, elts_per_pixel = data_tp

ct_pixels = TEST_IMAGE_SIZE[0] * TEST_IMAGE_SIZE[1]
arr = pyarrow.array([elt] * (ct_pixels * elts_per_pixel), type=dtype)
Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ test-requires = [
]
xbuild-tools = [ ]

[tool.cibuildwheel.macos]
# Disable platform guessing on macOS to avoid picking up Homebrew etc.
config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable platform-guessing=disable"

[tool.cibuildwheel.macos.environment]
# Isolate macOS build environment from Homebrew etc.
PATH = "$(pwd)/build/deps/darwin/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"

[tool.cibuildwheel.ios]
# Disable platform guessing on iOS, and disable raqm (since there won't be a
# vendor version, and we can't distribute it due to licensing)
Expand All @@ -139,6 +131,14 @@ test-command = [
# There's no numpy wheel for iOS (yet...)
test-requires = [ ]

[tool.cibuildwheel.macos]
# Disable platform guessing on macOS to avoid picking up Homebrew etc.
config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable platform-guessing=disable"

[tool.cibuildwheel.macos.environment]
# Isolate macOS build environment from Homebrew etc.
PATH = "$(pwd)/build/deps/darwin/bin:$(dirname $(which python3)):/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"

[[tool.cibuildwheel.overrides]]
# iOS environment is isolated by cibuildwheel, but needs the dependencies
select = "*_iphoneos"
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
2 changes: 1 addition & 1 deletion src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class EpsImageFile(ImageFile.ImageFile):

def _open(self) -> None:
assert self.fp is not None
(length, offset) = self._find_offset(self.fp)
length, offset = self._find_offset(self.fp)

# go to offset - start of "%!PS"
self.fp.seek(offset)
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
Loading
Loading