[pre-commit.ci] pre-commit autoupdate (#9415)

This commit is contained in:
Hugo van Kemenade 2026-02-02 21:46:00 +01:00 committed by GitHub
commit 095cdb3c4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 69 additions and 90 deletions

View File

@ -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$)
@ -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
@ -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

View File

@ -213,7 +213,7 @@ INT32 = DataShape(
),
)
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:
@ -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)

View File

@ -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:
@ -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:
@ -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
@ -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)

View File

@ -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

View File

@ -590,9 +590,7 @@ class TestFileJpeg:
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
@ -601,14 +599,9 @@ class TestFileJpeg:
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
@ -617,10 +610,7 @@ class TestFileJpeg:
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(

View File

@ -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

View File

@ -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

View File

@ -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()
@ -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

View File

@ -278,8 +278,7 @@ class TestEmbeddable:
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[])
@ -300,8 +299,7 @@ int main(int argc, char* argv[])
return 0;
}}
"""
)
""")
objects = compiler.compile(["embed_pil.c"])
compiler.link_executable(objects, "embed_pil")

View File

@ -56,7 +56,7 @@ class TestImageTransform:
def test_extent(self) -> None:
im = hopper("RGB")
(w, h) = im.size
w, h = im.size
transformed = im.transform(
im.size,
Image.Transform.EXTENT,
@ -72,7 +72,7 @@ class TestImageTransform:
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,
@ -99,7 +99,7 @@ class TestImageTransform:
)
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,
@ -112,7 +112,7 @@ class TestImageTransform:
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,
@ -174,7 +174,7 @@ class TestImageTransform:
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
)
@ -216,7 +216,7 @@ class TestImageTransform:
@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
)
@ -255,7 +255,7 @@ class TestImageTransform:
@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]

View File

@ -22,8 +22,7 @@ def string_to_img(image_string: str) -> Image.Image:
return im
A = string_to_img(
"""
A = string_to_img("""
.......
.......
..111..
@ -31,8 +30,7 @@ A = string_to_img(
..111..
.......
.......
"""
)
""")
def img_to_string(im: Image.Image) -> str:

View File

@ -87,7 +87,7 @@ if is_win32():
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)

View File

@ -208,7 +208,7 @@ INT32 = DataShape(
),
)
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:
@ -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(

View File

@ -211,7 +211,7 @@ INT32 = DataShape(
),
)
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)
@ -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)

View File

@ -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)
@ -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"

View File

@ -20,6 +20,7 @@
"""
Parse X Bitmap Distribution Format (BDF)
"""
from __future__ import annotations
from typing import BinaryIO

View File

@ -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)

View File

@ -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

View File

@ -25,6 +25,7 @@
implementation is provided for convenience and demonstrational
purposes only.
"""
from __future__ import annotations
from typing import IO

View File

@ -18,6 +18,7 @@ Stuff to translate curve segments to palette values (derived from
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

View File

@ -42,7 +42,7 @@ def read_32t(
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
) -> dict[str, Image.Image]:
# The 128x128 icon seems to have an extra header for some reason.
(start, length) = start_length
start, length = start_length
fobj.seek(start)
sig = fobj.read(4)
if sig != b"\x00\x00\x00\x00":
@ -58,7 +58,7 @@ def read_32(
Read a 32bit RGB icon resource. Seems to be either uncompressed or
an RLE packbits-like scheme.
"""
(start, length) = start_length
start, length = start_length
fobj.seek(start)
pixel_size = (size[0] * size[2], size[1] * size[2])
sizesq = pixel_size[0] * pixel_size[1]
@ -111,7 +111,7 @@ def read_mk(
def read_png_or_jpeg2000(
fobj: IO[bytes], start_length: tuple[int, int], size: tuple[int, int, int]
) -> dict[str, Image.Image]:
(start, length) = start_length
start, length = start_length
fobj.seek(start)
sig = fobj.read(12)

View File

@ -2546,7 +2546,7 @@ class Image:
]
def transform(x: float, y: float, matrix: list[float]) -> tuple[float, float]:
(a, b, c, d, e, f) = matrix
a, b, c, d, e, f = matrix
return a * x + b * y + c, d * x + e * y + f
matrix[2], matrix[5] = transform(
@ -3489,7 +3489,7 @@ def fromarrow(
msg = "arrow_c_array interface not found"
raise ValueError(msg)
(schema_capsule, array_capsule) = obj.__arrow_c_array__()
schema_capsule, array_capsule = obj.__arrow_c_array__()
_im = core.new_arrow(mode, size, schema_capsule, array_capsule)
if _im:
return Image()._new(_im)

View File

@ -22,6 +22,7 @@
.. seealso:: :py:mod:`PIL.ImageDraw`
"""
from __future__ import annotations
from typing import Any, AnyStr, BinaryIO
@ -117,7 +118,7 @@ class Draw:
def settransform(self, offset: tuple[float, float]) -> None:
"""Sets a transformation offset."""
(xoffset, yoffset) = offset
xoffset, yoffset = offset
self.transform = (1, 0, xoffset, 0, 1, yoffset)
def arc(

View File

@ -801,9 +801,9 @@ class PyCodec:
self.im = im
if extents:
(x0, y0, x1, y1) = extents
x0, y0, x1, y1 = extents
else:
(x0, y0, x1, y1) = (0, 0, 0, 0)
x0, y0, x1, y1 = (0, 0, 0, 0)
if x0 == 0 and x1 == 0:
self.state.xsize, self.state.ysize = self.im.size

View File

@ -940,9 +940,7 @@ def load_default_imagefont() -> ImageFont:
f = ImageFont()
f._load_pilfont_data(
# courB08
BytesIO(
base64.b64decode(
b"""
BytesIO(base64.b64decode(b"""
UElMZm9udAo7Ozs7OzsxMDsKREFUQQoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@ -1034,13 +1032,8 @@ AJsAEQAGAAAAAP/6AAX//wCbAAoAoAAPAAYAAAAA//oABQABAKAACgClABEABgAA////+AAGAAAA
pQAKAKwAEgAGAAD////4AAYAAACsAAoAswASAAYAAP////gABgAAALMACgC6ABIABgAA////+QAG
AAAAugAKAMEAEQAGAAD////4AAYAAgDBAAoAyAAUAAYAAP////kABQACAMgACgDOABMABgAA////
+QAGAAIAzgAKANUAEw==
"""
)
),
Image.open(
BytesIO(
base64.b64decode(
b"""
""")),
Image.open(BytesIO(base64.b64decode(b"""
iVBORw0KGgoAAAANSUhEUgAAAx4AAAAUAQAAAAArMtZoAAAEwElEQVR4nABlAJr/AHVE4czCI/4u
Mc4b7vuds/xzjz5/3/7u/n9vMe7vnfH/9++vPn/xyf5zhxzjt8GHw8+2d83u8x27199/nxuQ6Od9
M43/5z2I+9n9ZtmDBwMQECDRQw/eQIQohJXxpBCNVE6QCCAAAAD//wBlAJr/AgALyj1t/wINwq0g
@ -1064,10 +1057,7 @@ evta/58PTEWzr21hufPjA8N+qlnBwAAAAAD//2JiWLci5v1+HmFXDqcnULE/MxgYGBj+f6CaJQAA
AAD//2Ji2FrkY3iYpYC5qDeGgeEMAwPDvwQBBoYvcTwOVLMEAAAA//9isDBgkP///0EOg9z35v//
Gc/eeW7BwPj5+QGZhANUswMAAAD//2JgqGBgYGBgqEMXlvhMPUsAAAAA//8iYDd1AAAAAP//AwDR
w7IkEbzhVQAAAABJRU5ErkJggg==
"""
)
)
),
"""))),
)
return f
@ -1088,9 +1078,7 @@ def load_default(size: float | None = None) -> FreeTypeFont | ImageFont:
"""
if isinstance(core, ModuleType) or size is not None:
return truetype(
BytesIO(
base64.b64decode(
b"""
BytesIO(base64.b64decode(b"""
AAEAAAAPAIAAAwBwRkZUTYwDlUAAADFoAAAAHEdERUYAqADnAAAo8AAAACRHUE9ThhmITwAAKfgAA
AduR1NVQnHxefoAACkUAAAA4k9TLzJovoHLAAABeAAAAGBjbWFw5lFQMQAAA6gAAAGqZ2FzcP//AA
MAACjoAAAACGdseWYmRXoPAAAGQAAAHfhoZWFkE18ayQAAAPwAAAA2aGhlYQboArEAAAE0AAAAJGh
@ -1311,9 +1299,7 @@ ABUADgAPAAAACwAQAAAAAAAAAAAAAAAAAAUAGAACAAIAAgAAAAIAGAAXAAAAGAAAABYAFgACABYAA
gAWAAAAEQADAAoAFAAMAA0ABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASAAAAEgAGAAEAHgAkAC
YAJwApACoALQAuAC8AMgAzADcAOAA5ADoAPAA9AEUASABOAE8AUgBTAFUAVwBZAFoAWwBcAF0AcwA
AAAAAAQAAAADa3tfFAAAAANAan9kAAAAA4QodoQ==
"""
)
),
""")),
10 if size is None else size,
layout_engine=Layout.BASIC,
)

View File

@ -140,7 +140,7 @@ class MspDecoder(ImageFile.PyDecoder):
runtype = row[idx]
idx += 1
if runtype == 0:
(runcount, runval) = struct.unpack_from("Bc", row, idx)
runcount, runval = struct.unpack_from("Bc", row, idx)
img.write(runval * runcount)
idx += 2
else:

View File

@ -22,6 +22,7 @@ and has been tested with a few sample files found using google.
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

View File

@ -13,6 +13,7 @@
"""Binary input/output support routines."""
from __future__ import annotations
from struct import pack, unpack_from