From 099048b874969bd3e6821b77aec5e4573c0c4d6c Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 20 Nov 2025 08:14:15 +1100 Subject: [PATCH] Raise warning if image file identification fails due to lack of support --- Tests/test_file_jxl.py | 5 +++-- src/PIL/JpegXlImagePlugin.py | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/test_file_jxl.py b/Tests/test_file_jxl.py index 027d6b1c9..8816702e8 100644 --- a/Tests/test_file_jxl.py +++ b/Tests/test_file_jxl.py @@ -23,8 +23,9 @@ class TestUnsupportedJpegXl: monkeypatch.setattr(JpegXlImagePlugin, "SUPPORTED", False) with pytest.raises(OSError): - with Image.open("Tests/images/hopper.jxl"): - pass + with pytest.warns(UserWarning, match="JXL support not installed"): + with Image.open("Tests/images/hopper.jxl"): + pass @skip_unless_feature("jpegxl") diff --git a/src/PIL/JpegXlImagePlugin.py b/src/PIL/JpegXlImagePlugin.py index 588752949..4f4807748 100644 --- a/src/PIL/JpegXlImagePlugin.py +++ b/src/PIL/JpegXlImagePlugin.py @@ -22,13 +22,12 @@ except ImportError: # OPEN_COUNTS_FRAMES = True -def _accept(prefix: bytes) -> bool: +def _accept(prefix: bytes) -> bool | str: is_jxl = prefix.startswith( (b"\xff\x0a", b"\x00\x00\x00\x0c\x4a\x58\x4c\x20\x0d\x0a\x87\x0a") ) if is_jxl and not SUPPORTED: - msg = "image file could not be identified because JXL support not installed" - raise SyntaxError(msg) + return "image file could not be identified because JXL support not installed" return is_jxl