Skip to content

Commit

Permalink
Merge pull request #8729 from python-pillow/pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
[pre-commit.ci] pre-commit autoupdate
  • Loading branch information
radarhere authored Feb 3, 2025
2 parents 4d1f874 + 00790e9 commit 92eb11e
Show file tree
Hide file tree
Showing 24 changed files with 98 additions and 99 deletions.
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.4
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]

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

- repo: https://github.com/PyCQA/bandit
rev: 1.8.0
rev: 1.8.2
hooks:
- id: bandit
args: [--severity-level=high]
Expand All @@ -24,7 +24,7 @@ repos:
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.6
rev: v19.1.7
hooks:
- id: clang-format
types: [c]
Expand All @@ -50,14 +50,14 @@ repos:
exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/

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

- repo: https://github.com/woodruffw/zizmor-pre-commit
rev: v1.0.0
rev: v1.3.0
hooks:
- id: zizmor

Expand All @@ -78,7 +78,7 @@ repos:
additional_dependencies: [trove-classifiers>=2024.10.12]

- repo: https://github.com/tox-dev/tox-ini-fmt
rev: 1.4.1
rev: 1.5.0
hooks:
- id: tox-ini-fmt

Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def test_icc_after_SOF(self) -> None:

def test_jpeg_magic_number(self, monkeypatch: pytest.MonkeyPatch) -> None:
size = 4097
buffer = BytesIO(b"\xFF" * size) # Many xFF bytes
buffer = BytesIO(b"\xff" * size) # Many xff bytes
max_pos = 0
orig_read = buffer.read

Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_libtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,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
4 changes: 2 additions & 2 deletions Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def test_pdf_append(tmp_path: Path) -> None:
# append some info
pdf.info.Title = "abc"
pdf.info.Author = "def"
pdf.info.Subject = "ghi\uABCD"
pdf.info.Subject = "ghi\uabcd"
pdf.info.Keywords = "qw)e\\r(ty"
pdf.info.Creator = "hopper()"
pdf.start_writing()
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_pdf_append(tmp_path: Path) -> None:
assert pdf.info.Title == "abc"
assert pdf.info.Producer == "PdfParser"
assert pdf.info.Keywords == "qw)e\\r(ty"
assert pdf.info.Subject == "ghi\uABCD"
assert pdf.info.Subject == "ghi\uabcd"
assert b"CreationDate" in pdf.info
assert b"ModDate" in pdf.info
check_pdf_pages_consistency(pdf)
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_ppm.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_sanity() -> None:
(b"P5 3 1 257 \x00\x00\x00\x80\x01\x01", "I", (0, 32640, 65535)),
# P6 with maxval < 255
(
b"P6 3 1 17 \x00\x01\x02\x08\x09\x0A\x0F\x10\x11",
b"P6 3 1 17 \x00\x01\x02\x08\x09\x0a\x0f\x10\x11",
"RGB",
(
(0, 15, 30),
Expand All @@ -60,7 +60,7 @@ def test_sanity() -> None:
# P6 with maxval > 255
(
b"P6 3 1 257 \x00\x00\x00\x01\x00\x02"
b"\x00\x80\x00\x81\x00\x82\x01\x00\x01\x01\xFF\xFF",
b"\x00\x80\x00\x81\x00\x82\x01\x00\x01\x01\xff\xff",
"RGB",
(
(0, 1, 2),
Expand Down
10 changes: 5 additions & 5 deletions Tests/test_file_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ def im_generator(ims: list[Image.Image]) -> Generator[Image.Image, None, None]:
assert reread.n_frames == 3

def test_fixoffsets(self) -> None:
b = BytesIO(b"II\x2A\x00\x00\x00\x00\x00")
b = BytesIO(b"II\x2a\x00\x00\x00\x00\x00")
with TiffImagePlugin.AppendingTiffWriter(b) as a:
b.seek(0)
a.fixOffsets(1, isShort=True)
Expand All @@ -759,14 +759,14 @@ def test_fixoffsets(self) -> None:
with pytest.raises(RuntimeError):
a.fixOffsets(1)

b = BytesIO(b"II\x2A\x00\x00\x00\x00\x00")
b = BytesIO(b"II\x2a\x00\x00\x00\x00\x00")
with TiffImagePlugin.AppendingTiffWriter(b) as a:
a.offsetOfNewPage = 2**16

b.seek(0)
a.fixOffsets(1, isShort=True)

b = BytesIO(b"II\x2B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
b = BytesIO(b"II\x2b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
with TiffImagePlugin.AppendingTiffWriter(b) as a:
a.offsetOfNewPage = 2**32

Expand All @@ -777,15 +777,15 @@ def test_fixoffsets(self) -> None:
a.fixOffsets(1, isLong=True)

def test_appending_tiff_writer_writelong(self) -> None:
data = b"II\x2A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
data = b"II\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b = BytesIO(data)
with TiffImagePlugin.AppendingTiffWriter(b) as a:
a.seek(-4, os.SEEK_CUR)
a.writeLong(2**32 - 1)
assert b.getvalue() == data[:-4] + b"\xff\xff\xff\xff"

def test_appending_tiff_writer_rewritelastshorttolong(self) -> None:
data = b"II\x2A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
data = b"II\x2a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b = BytesIO(data)
with TiffImagePlugin.AppendingTiffWriter(b) as a:
a.seek(-2, os.SEEK_CUR)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_wmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_load_float_dpi() -> None:

with open("Tests/images/drawing.emf", "rb") as fp:
data = fp.read()
b = BytesIO(data[:8] + b"\x06\xFA" + data[10:])
b = BytesIO(data[:8] + b"\x06\xfa" + data[10:])
with Image.open(b) as im:
assert im.info["dpi"][0] == 2540

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
6 changes: 3 additions & 3 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def test_render_empty(font: ImageFont.FreeTypeFont) -> None:

def test_unicode_extended(layout_engine: ImageFont.Layout) -> None:
# issue #3777
text = "A\u278A\U0001F12B"
text = "A\u278a\U0001f12b"
target = "Tests/images/unicode_extended.png"

ttf = ImageFont.truetype(
Expand Down Expand Up @@ -1026,7 +1026,7 @@ def test_sbix(layout_engine: ImageFont.Layout) -> None:
im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)

d.text((50, 50), "\uE901", font=font, embedded_color=True)
d.text((50, 50), "\ue901", font=font, embedded_color=True)

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix.png", 1)
except OSError as e: # pragma: no cover
Expand All @@ -1043,7 +1043,7 @@ def test_sbix_mask(layout_engine: ImageFont.Layout) -> None:
im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)

d.text((50, 50), "\uE901", (100, 0, 0), font=font)
d.text((50, 50), "\ue901", (100, 0, 0), font=font)

assert_image_similar_tofile(im, "Tests/images/chromacheck-sbix_mask.png", 1)
except OSError as e: # pragma: no cover
Expand Down
42 changes: 21 additions & 21 deletions Tests/test_imagefontctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_getlength(
@pytest.mark.parametrize("direction", ("ltr", "ttb"))
@pytest.mark.parametrize(
"text",
("i" + ("\u030C" * 15) + "i", "i" + "\u032C" * 15 + "i", "\u035Cii", "i\u0305i"),
("i" + ("\u030c" * 15) + "i", "i" + "\u032c" * 15 + "i", "\u035cii", "i\u0305i"),
ids=("caron-above", "caron-below", "double-breve", "overline"),
)
def test_getlength_combine(mode: str, direction: str, text: str) -> None:
Expand Down Expand Up @@ -272,27 +272,27 @@ def test_anchor_ttb(anchor: str) -> None:

combine_tests = (
# extends above (e.g. issue #4553)
("caron", "a\u030C\u030C\u030C\u030C\u030Cb", None, None, 0.08),
("caron_la", "a\u030C\u030C\u030C\u030C\u030Cb", "la", None, 0.08),
("caron_lt", "a\u030C\u030C\u030C\u030C\u030Cb", "lt", None, 0.08),
("caron_ls", "a\u030C\u030C\u030C\u030C\u030Cb", "ls", None, 0.08),
("caron_ttb", "ca" + ("\u030C" * 15) + "b", None, "ttb", 0.3),
("caron_ttb_lt", "ca" + ("\u030C" * 15) + "b", "lt", "ttb", 0.3),
("caron", "a\u030c\u030c\u030c\u030c\u030cb", None, None, 0.08),
("caron_la", "a\u030c\u030c\u030c\u030c\u030cb", "la", None, 0.08),
("caron_lt", "a\u030c\u030c\u030c\u030c\u030cb", "lt", None, 0.08),
("caron_ls", "a\u030c\u030c\u030c\u030c\u030cb", "ls", None, 0.08),
("caron_ttb", "ca" + ("\u030c" * 15) + "b", None, "ttb", 0.3),
("caron_ttb_lt", "ca" + ("\u030c" * 15) + "b", "lt", "ttb", 0.3),
# extends below
("caron_below", "a\u032C\u032C\u032C\u032C\u032Cb", None, None, 0.02),
("caron_below_ld", "a\u032C\u032C\u032C\u032C\u032Cb", "ld", None, 0.02),
("caron_below_lb", "a\u032C\u032C\u032C\u032C\u032Cb", "lb", None, 0.02),
("caron_below_ls", "a\u032C\u032C\u032C\u032C\u032Cb", "ls", None, 0.02),
("caron_below_ttb", "a" + ("\u032C" * 15) + "b", None, "ttb", 0.03),
("caron_below_ttb_lb", "a" + ("\u032C" * 15) + "b", "lb", "ttb", 0.03),
("caron_below", "a\u032c\u032c\u032c\u032c\u032cb", None, None, 0.02),
("caron_below_ld", "a\u032c\u032c\u032c\u032c\u032cb", "ld", None, 0.02),
("caron_below_lb", "a\u032c\u032c\u032c\u032c\u032cb", "lb", None, 0.02),
("caron_below_ls", "a\u032c\u032c\u032c\u032c\u032cb", "ls", None, 0.02),
("caron_below_ttb", "a" + ("\u032c" * 15) + "b", None, "ttb", 0.03),
("caron_below_ttb_lb", "a" + ("\u032c" * 15) + "b", "lb", "ttb", 0.03),
# extends to the right (e.g. issue #3745)
("double_breve_below", "a\u035Ci", None, None, 0.02),
("double_breve_below_ma", "a\u035Ci", "ma", None, 0.02),
("double_breve_below_ra", "a\u035Ci", "ra", None, 0.02),
("double_breve_below_ttb", "a\u035Cb", None, "ttb", 0.02),
("double_breve_below_ttb_rt", "a\u035Cb", "rt", "ttb", 0.02),
("double_breve_below_ttb_mt", "a\u035Cb", "mt", "ttb", 0.02),
("double_breve_below_ttb_st", "a\u035Cb", "st", "ttb", 0.02),
("double_breve_below", "a\u035ci", None, None, 0.02),
("double_breve_below_ma", "a\u035ci", "ma", None, 0.02),
("double_breve_below_ra", "a\u035ci", "ra", None, 0.02),
("double_breve_below_ttb", "a\u035cb", None, "ttb", 0.02),
("double_breve_below_ttb_rt", "a\u035cb", "rt", "ttb", 0.02),
("double_breve_below_ttb_mt", "a\u035cb", "mt", "ttb", 0.02),
("double_breve_below_ttb_st", "a\u035cb", "st", "ttb", 0.02),
# extends to the left (fail=0.064)
("overline", "i\u0305", None, None, 0.02),
("overline_la", "i\u0305", "la", None, 0.02),
Expand Down Expand Up @@ -346,7 +346,7 @@ def test_combine_multiline(anchor: str, align: str) -> None:

path = f"Tests/images/test_combine_multiline_{anchor}_{align}.png"
f = ImageFont.truetype("Tests/fonts/NotoSans-Regular.ttf", 48)
text = "i\u0305\u035C\ntext" # i with overline and double breve, and a word
text = "i\u0305\u035c\ntext" # i with overline and double breve, and a word

im = Image.new("RGB", (400, 400), "white")
d = ImageDraw.Draw(im)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagepalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_2bit_palette(tmp_path: Path) -> None:

rgb = b"\x00" * 2 + b"\x01" * 2 + b"\x02" * 2
img = Image.frombytes("P", (6, 1), rgb)
img.putpalette(b"\xFF\x00\x00\x00\xFF\x00\x00\x00\xFF") # RGB
img.putpalette(b"\xff\x00\x00\x00\xff\x00\x00\x00\xff") # RGB
img.save(outfile, format="PNG")

assert_image_equal_tofile(img, outfile)
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
18 changes: 9 additions & 9 deletions Tests/test_pdfparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@


def test_text_encode_decode() -> None:
assert encode_text("abc") == b"\xFE\xFF\x00a\x00b\x00c"
assert decode_text(b"\xFE\xFF\x00a\x00b\x00c") == "abc"
assert encode_text("abc") == b"\xfe\xff\x00a\x00b\x00c"
assert decode_text(b"\xfe\xff\x00a\x00b\x00c") == "abc"
assert decode_text(b"abc") == "abc"
assert decode_text(b"\x1B a \x1C") == "\u02D9 a \u02DD"
assert decode_text(b"\x1b a \x1c") == "\u02d9 a \u02dd"


def test_indirect_refs() -> None:
Expand All @@ -45,8 +45,8 @@ def test_parsing() -> None:
assert PdfParser.get_value(b"false%", 0) == (False, 5)
assert PdfParser.get_value(b"null<", 0) == (None, 4)
assert PdfParser.get_value(b"%cmt\n %cmt\n 123\n", 0) == (123, 15)
assert PdfParser.get_value(b"<901FA3>", 0) == (b"\x90\x1F\xA3", 8)
assert PdfParser.get_value(b"asd < 9 0 1 f A > qwe", 3) == (b"\x90\x1F\xA0", 17)
assert PdfParser.get_value(b"<901FA3>", 0) == (b"\x90\x1f\xa3", 8)
assert PdfParser.get_value(b"asd < 9 0 1 f A > qwe", 3) == (b"\x90\x1f\xa0", 17)
assert PdfParser.get_value(b"(asd)", 0) == (b"asd", 5)
assert PdfParser.get_value(b"(asd(qwe)zxc)zzz(aaa)", 0) == (b"asd(qwe)zxc", 13)
assert PdfParser.get_value(b"(Two \\\nwords.)", 0) == (b"Two words.", 14)
Expand All @@ -56,9 +56,9 @@ def test_parsing() -> None:
assert PdfParser.get_value(b"(One\\(paren).", 0) == (b"One(paren", 12)
assert PdfParser.get_value(b"(One\\)paren).", 0) == (b"One)paren", 12)
assert PdfParser.get_value(b"(\\0053)", 0) == (b"\x053", 7)
assert PdfParser.get_value(b"(\\053)", 0) == (b"\x2B", 6)
assert PdfParser.get_value(b"(\\53)", 0) == (b"\x2B", 5)
assert PdfParser.get_value(b"(\\53a)", 0) == (b"\x2Ba", 6)
assert PdfParser.get_value(b"(\\053)", 0) == (b"\x2b", 6)
assert PdfParser.get_value(b"(\\53)", 0) == (b"\x2b", 5)
assert PdfParser.get_value(b"(\\53a)", 0) == (b"\x2ba", 6)
assert PdfParser.get_value(b"(\\1111)", 0) == (b"\x491", 7)
assert PdfParser.get_value(b" 123 (", 0) == (123, 4)
assert round(abs(PdfParser.get_value(b" 123.4 %", 0)[0] - 123.4), 7) == 0
Expand Down Expand Up @@ -118,7 +118,7 @@ def test_pdf_repr() -> None:
assert pdf_repr(None) == b"null"
assert pdf_repr(b"a)/b\\(c") == rb"(a\)/b\\\(c)"
assert pdf_repr([123, True, {"a": PdfName(b"b")}]) == b"[ 123 true <<\n/a /b\n>> ]"
assert pdf_repr(PdfBinary(b"\x90\x1F\xA0")) == b"<901FA0>"
assert pdf_repr(PdfBinary(b"\x90\x1f\xa0")) == b"<901FA0>"


def test_duplicate_xref_entry() -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _open(self) -> None:
if s == b"\r":
continue

if not s or s == b"\0" or s == b"\x1A":
if not s or s == b"\0" or s == b"\x1a":
break

# FIXME: this may read whole file if not a text file
Expand Down Expand Up @@ -209,7 +209,7 @@ def _open(self) -> None:
self._mode = self.info[MODE]

# Skip forward to start of image data
while s and s[:1] != b"\x1A":
while s and s[:1] != b"\x1a":
s = self.fp.read(1)
if not s:
msg = "File truncated"
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ def __truediv__(self, other: ImagePointTransform | float) -> ImagePointTransform


def _getscaleoffset(
expr: Callable[[ImagePointTransform], ImagePointTransform | float]
expr: Callable[[ImagePointTransform], ImagePointTransform | float],
) -> tuple[float, float]:
a = expr(ImagePointTransform(1, 0))
return (a.scale, a.offset) if isinstance(a, ImagePointTransform) else (0, a)
Expand Down Expand Up @@ -3884,7 +3884,7 @@ def _get_ifd_dict(
return self._fixup_dict(dict(info))

def _get_head(self) -> bytes:
version = b"\x2B" if self.bigtiff else b"\x2A"
version = b"\x2b" if self.bigtiff else b"\x2a"
if self.endian == "<":
head = b"II" + version + b"\x00" + o32le(8)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImtImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _open(self) -> None:
if not s:
break

if s == b"\x0C":
if s == b"\x0c":
# image data begins
self.tile = [
ImageFile._Tile(
Expand Down
Loading

0 comments on commit 92eb11e

Please sign in to comment.