Skip to content

Commit e311a46

Browse files
authored
Merge branch 'main' into image_mode_size_delegation
2 parents 88cad58 + c1c474a commit e311a46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+252
-183
lines changed

.github/workflows/test-cygwin.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,23 @@ jobs:
7676
with:
7777
dirs: 'C:\cygwin\bin;C:\cygwin\lib\lapack'
7878

79+
- name: Select Python version
80+
run: |
81+
ln -sf c:/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/cygwin/bin/python3
82+
83+
- name: Get latest NumPy version
84+
id: latest-numpy
85+
shell: bash.exe -eo pipefail -o igncr "{0}"
86+
run: |
87+
python3 -m pip list --outdated | grep numpy | sed -r 's/ +/ /g' | cut -d ' ' -f 3 | sed 's/^/version=/' >> $GITHUB_OUTPUT
88+
7989
- name: pip cache
8090
uses: actions/cache@v3
8191
with:
8292
path: 'C:\cygwin\home\runneradmin\.cache\pip'
83-
key: ${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-${{ hashFiles('.ci/install.sh') }}
93+
key: ${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-numpy${{ steps.latest-numpy.outputs.version }}-${{ hashFiles('.ci/install.sh') }}
8494
restore-keys: |
85-
${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-
86-
87-
- name: Select Python version
88-
run: |
89-
ln -sf c:/cygwin/bin/python3.${{ matrix.python-minor-version }} c:/cygwin/bin/python3
95+
${{ runner.os }}-cygwin-pip3.${{ matrix.python-minor-version }}-numpy${{ steps.latest-numpy.outputs.version }}-
9096
9197
- name: Build system information
9298
run: |
@@ -96,7 +102,7 @@ jobs:
96102
run: |
97103
bash.exe .ci/install.sh
98104
99-
- name: Install a different NumPy
105+
- name: Install latest NumPy
100106
shell: dash.exe -l "{0}"
101107
run: |
102108
python3 -m pip install -U numpy

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Changelog (Pillow)
55
10.1.0 (unreleased)
66
-------------------
77

8+
- Silence exceptions in _repr_jpeg_ and _repr_png_ #7266
9+
[mtreinish, radarhere]
10+
11+
- Do not use transparency when saving GIF if it has been removed when normalizing mode #7284
12+
[radarhere]
13+
814
- Fix missing symbols when libtiff depends on libjpeg #7270
915
[heitbaum]
1016

Tests/test_file_gif.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,21 @@ def test_transparent_optimize(tmp_path):
10861086
assert reloaded.info["transparency"] == reloaded.getpixel((252, 0))
10871087

10881088

1089+
def test_removed_transparency(tmp_path):
1090+
out = str(tmp_path / "temp.gif")
1091+
im = Image.new("RGB", (256, 1))
1092+
1093+
for x in range(256):
1094+
im.putpixel((x, 0), (x, 0, 0))
1095+
1096+
im.info["transparency"] = (255, 255, 255)
1097+
with pytest.warns(UserWarning):
1098+
im.save(out)
1099+
1100+
with Image.open(out) as reloaded:
1101+
assert "transparency" not in reloaded.info
1102+
1103+
10891104
def test_rgb_transparency(tmp_path):
10901105
out = str(tmp_path / "temp.gif")
10911106

Tests/test_file_jpeg.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,11 +929,10 @@ def test_repr_jpeg(self):
929929
assert repr_jpeg.format == "JPEG"
930930
assert_image_similar(im, repr_jpeg, 17)
931931

932-
def test_repr_jpeg_error(self):
932+
def test_repr_jpeg_error_returns_none(self):
933933
im = hopper("F")
934934

935-
with pytest.raises(ValueError):
936-
im._repr_jpeg_()
935+
assert im._repr_jpeg_() is None
937936

938937

939938
@pytest.mark.skipif(not is_win32(), reason="Windows only")

Tests/test_file_jpeg2k.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,15 @@ def test_sgnd(tmp_path):
274274
assert reloaded_signed.getpixel((0, 0)) == 128
275275

276276

277-
def test_rgba():
277+
@pytest.mark.parametrize("ext", (".j2k", ".jp2"))
278+
def test_rgba(ext):
278279
# Arrange
279-
with Image.open("Tests/images/rgb_trns_ycbc.j2k") as j2k:
280-
with Image.open("Tests/images/rgb_trns_ycbc.jp2") as jp2:
281-
# Act
282-
j2k.load()
283-
jp2.load()
284-
285-
# Assert
286-
assert j2k.mode == "RGBA"
287-
assert jp2.mode == "RGBA"
280+
with Image.open("Tests/images/rgb_trns_ycbc" + ext) as im:
281+
# Act
282+
im.load()
283+
284+
# Assert
285+
assert im.mode == "RGBA"
288286

289287

290288
@pytest.mark.parametrize("ext", (".j2k", ".jp2"))

Tests/test_file_png.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,10 @@ def test_repr_png(self):
532532
assert repr_png.format == "PNG"
533533
assert_image_equal(im, repr_png)
534534

535-
def test_repr_png_error(self):
535+
def test_repr_png_error_returns_none(self):
536536
im = hopper("F")
537537

538-
with pytest.raises(ValueError):
539-
im._repr_png_()
538+
assert im._repr_png_() is None
540539

541540
def test_chunk_order(self, tmp_path):
542541
with Image.open("Tests/images/icc_profile.png") as im:

Tests/test_image.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ def test_width_height(self):
135135
with pytest.raises(AttributeError):
136136
im.size = (3, 4)
137137

138+
def test_set_mode(self):
139+
im = Image.new("RGB", (1, 1))
140+
141+
with pytest.raises(AttributeError):
142+
im.mode = "P"
143+
138144
def test_invalid_image(self):
139145
im = io.BytesIO(b"")
140146
with pytest.raises(UnidentifiedImageError):

Tests/test_imagefile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_no_format(self):
136136

137137
class DummyImageFile(ImageFile.ImageFile):
138138
def _open(self):
139-
self.mode = "RGB"
139+
self._mode = "RGB"
140140
self._size = (1, 1)
141141

142142
im = DummyImageFile(buf)
@@ -217,7 +217,7 @@ def cleanup(self):
217217
class MockImageFile(ImageFile.ImageFile):
218218
def _open(self):
219219
self.rawmode = "RGBA"
220-
self.mode = "RGBA"
220+
self._mode = "RGBA"
221221
self._size = (200, 200)
222222
self.tile = [("MOCK", (xoff, yoff, xoff + xsize, yoff + ysize), 32, None)]
223223

Tests/test_pickle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ def test_pickle_la_mode_with_palette(tmp_path):
7575

7676
# Act / Assert
7777
for protocol in range(0, pickle.HIGHEST_PROTOCOL + 1):
78-
im.mode = "LA"
78+
im._mode = "LA"
7979
with open(filename, "wb") as f:
8080
pickle.dump(im, f, protocol)
8181
with open(filename, "rb") as f:
8282
loaded_im = pickle.load(f)
8383

84-
im.mode = "PA"
84+
im._mode = "PA"
8585
assert im == loaded_im
8686

8787

docs/example/DdsImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _open(self):
225225

226226
flags, height, width = struct.unpack("<3I", header.read(12))
227227
self._size = (width, height)
228-
self.mode = "RGBA"
228+
self._mode = "RGBA"
229229

230230
pitch, depth, mipmaps = struct.unpack("<3I", header.read(12))
231231
struct.unpack("<11I", header.read(44)) # reserved

0 commit comments

Comments
 (0)