Skip to content

Commit 7f293c5

Browse files
authored
Merge branch 'main' into feat/riscv64-wheels
2 parents 816fe45 + b62ff96 commit 7f293c5

19 files changed

+103
-69
lines changed

Tests/test_bmp_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_questionable() -> None:
5656
im.load()
5757
if os.path.basename(f) not in supported:
5858
print(f"Please add {f} to the partially supported bmp specs.")
59-
except Exception: # as msg:
59+
except Exception: # noqa: PERF203
6060
if os.path.basename(f) in supported:
6161
raise
6262

@@ -106,7 +106,7 @@ def get_compare(f: str) -> str:
106106

107107
assert_image_similar(im_converted, compare_converted, 5)
108108

109-
except Exception as msg:
109+
except Exception as msg: # noqa: PERF203
110110
# there are three here that are unsupported:
111111
unsupported = (
112112
os.path.join(base, "g", "rgb32bf.bmp"),

Tests/test_file_container.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,7 @@ def test_iter(bytesmode: bool) -> None:
179179
container = ContainerIO.ContainerIO(fh, 0, 120)
180180

181181
# Act
182-
data = []
183-
for line in container:
184-
data.append(line)
182+
data = list(container)
185183

186184
# Assert
187185
if bytesmode:

Tests/test_file_libtiff.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@ def test_additional_metadata(
224224
with Image.open("Tests/images/hopper_g4.tif") as im:
225225
assert isinstance(im, TiffImagePlugin.TiffImageFile)
226226
for tag in im.tag_v2:
227-
try:
228-
del core_items[tag]
229-
except KeyError:
230-
pass
227+
core_items.pop(tag, None)
231228
del core_items[320] # colormap is special, tested below
232229

233230
# Type codes:

docs/releasenotes/12.2.0.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
12.2.0
2+
------
3+
4+
Security
5+
========
6+
7+
TODO
8+
^^^^
9+
10+
TODO
11+
12+
:cve:`YYYY-XXXXX`: TODO
13+
^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
TODO
16+
17+
API changes
18+
===========
19+
20+
Error when encoding an empty image
21+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
Attempting to encode an image with zero width or height would previously raise
24+
a :py:exc:`SystemError`. That has now been changed to a :py:exc:`ValueError`.
25+
26+
This does not add any new errors. SGI, ICNS and ICO formats are still able to
27+
save (0, 0) images.
28+
29+
API additions
30+
=============
31+
32+
FontFile.to_imagefont()
33+
^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
:py:class:`~PIL.FontFile.FontFile` instances can now be directly converted to
36+
:py:class:`~PIL.ImageFont.ImageFont` instances::
37+
38+
>>> from PIL import PcfFontFile
39+
>>> with open("Tests/fonts/10x20-ISO8859-1.pcf", "rb") as fp:
40+
... pcffont = PcfFontFile.PcfFontFile(fp)
41+
... pcffont.to_imagefont()
42+
...
43+
<PIL.ImageFont.ImageFont object at 0x10457bb80>
44+
45+
Other changes
46+
=============
47+
48+
Support reading JPEG2000 images with CMYK palettes
49+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50+
51+
JPEG2000 images with CMYK palettes can now be read. This is the first integration of
52+
CMYK palettes into Pillow.

docs/releasenotes/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ expected to be backported to earlier versions.
1515
:maxdepth: 2
1616

1717
versioning
18+
12.2.0
1819
12.1.1
1920
12.1.0
2021
12.0.0

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ lint.select = [
146146
"I", # isort
147147
"ISC", # flake8-implicit-str-concat
148148
"LOG", # flake8-logging
149+
"PERF", # perflint
149150
"PGH", # pygrep-hooks
150151
"PIE", # flake8-pie
151152
"PT", # flake8-pytest-style

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def _pkg_config(name: str) -> tuple[list[str], list[str]] | None:
302302
subprocess.check_output(command_cflags).decode("utf8").strip(),
303303
)[::2][1:]
304304
return libs, cflags
305-
except Exception:
305+
except Exception: # noqa: PERF203
306306
pass
307307
return None
308308

@@ -1078,10 +1078,10 @@ def debug_build() -> bool:
10781078
]
10791079

10801080
files: list[str | os.PathLike[str]] = ["src/_imaging.c"]
1081-
for src_file in _IMAGING:
1082-
files.append("src/" + src_file + ".c")
1083-
for src_file in _LIB_IMAGING:
1084-
files.append(os.path.join("src/libImaging", src_file + ".c"))
1081+
files.extend("src/" + src_file + ".c" for src_file in _IMAGING)
1082+
files.extend(
1083+
os.path.join("src/libImaging", src_file + ".c") for src_file in _LIB_IMAGING
1084+
)
10851085
ext_modules = [
10861086
Extension("PIL._imaging", files),
10871087
Extension("PIL._imagingft", ["src/_imagingft.c"]),

src/PIL/GifImagePlugin.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ def seek(self, frame: int) -> None:
164164
self._seek(0)
165165

166166
last_frame = self.__frame
167-
for f in range(self.__frame + 1, frame + 1):
168-
try:
167+
try:
168+
for f in range(self.__frame + 1, frame + 1):
169169
self._seek(f)
170-
except EOFError as e:
171-
self.seek(last_frame)
172-
msg = "no more images in GIF file"
173-
raise EOFError(msg) from e
170+
except EOFError as e:
171+
self.seek(last_frame)
172+
msg = "no more images in GIF file"
173+
raise EOFError(msg) from e
174174

175175
def _seek(self, frame: int, update_image: bool = True) -> None:
176176
if isinstance(self._fp, DeferredError):

src/PIL/IcnsImagePlugin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ def read_32(
8080
if byte_int & 0x80:
8181
blocksize = byte_int - 125
8282
byte = fobj.read(1)
83-
for i in range(blocksize):
84-
data.append(byte)
83+
data.extend([byte] * blocksize)
8584
else:
8685
blocksize = byte_int + 1
8786
data.append(fobj.read(blocksize))

src/PIL/Image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def init() -> bool:
488488
try:
489489
logger.debug("Importing %s", plugin)
490490
__import__(f"{__spec__.parent}.{plugin}", globals(), locals(), [])
491-
except ImportError as e:
491+
except ImportError as e: # noqa: PERF203
492492
logger.debug("Image: failed to import %s: %s", plugin, e)
493493

494494
if OPEN or SAVE:

0 commit comments

Comments
 (0)