From ef4660897466907a3f8de5962e46e31ee3fec4fb Mon Sep 17 00:00:00 2001 From: Yay295 Date: Mon, 23 Oct 2023 19:26:08 -0500 Subject: [PATCH 1/3] add mode to error message --- src/PIL/ImageOps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 6d70f02483d..bd6e01c9fe1 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -56,7 +56,7 @@ def _lut(image, lut): lut = lut + lut + lut return image.point(lut) else: - msg = "not supported for this image mode" + msg = "not supported for image mode " + image.mode raise OSError(msg) From f54dd8458600ac4373078f2b43a86918627e2e0f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 24 Oct 2023 12:44:00 +1100 Subject: [PATCH 2/3] Test unsupported autocontrast mode --- Tests/test_imageops.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Tests/test_imageops.py b/Tests/test_imageops.py index 6d153cceaf9..a3bb536cec2 100644 --- a/Tests/test_imageops.py +++ b/Tests/test_imageops.py @@ -433,6 +433,12 @@ def test_exif_transpose_in_place(): assert_image_equal(im, expected) +def test_autocontrast_unsupported_mode(): + im = Image.new("RGBA", (1, 1)) + with pytest.raises(OSError): + ImageOps.autocontrast(im) + + def test_autocontrast_cutoff(): # Test the cutoff argument of autocontrast with Image.open("Tests/images/bw_gradient.png") as img: From 6ddf10c7470e5f15ed1aafdd3f2e839af1e1e17b Mon Sep 17 00:00:00 2001 From: Yay295 Date: Mon, 23 Oct 2023 21:46:54 -0500 Subject: [PATCH 3/3] use format string instead of concatenation Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- src/PIL/ImageOps.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index bd6e01c9fe1..4f83a4edb69 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -56,7 +56,7 @@ def _lut(image, lut): lut = lut + lut + lut return image.point(lut) else: - msg = "not supported for image mode " + image.mode + msg = f"not supported for mode {image.mode}" raise OSError(msg)