Raise FileNotFoundError when opening an empty path (#9048)

This commit is contained in:
Hugo van Kemenade 2025-06-30 17:48:44 +03:00 committed by GitHub
commit 84855d11c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View File

@ -160,6 +160,10 @@ class TestImage:
with pytest.raises(AttributeError): with pytest.raises(AttributeError):
im.mode = "P" # type: ignore[misc] im.mode = "P" # type: ignore[misc]
def test_empty_path(self) -> None:
with pytest.raises(FileNotFoundError):
Image.open("")
def test_invalid_image(self) -> None: def test_invalid_image(self) -> None:
im = io.BytesIO(b"") im = io.BytesIO(b"")
with pytest.raises(UnidentifiedImageError): with pytest.raises(UnidentifiedImageError):

View File

@ -3510,8 +3510,6 @@ def open(
filename: str | bytes = "" filename: str | bytes = ""
if is_path(fp): if is_path(fp):
filename = os.fspath(fp) filename = os.fspath(fp)
if filename:
fp = builtins.open(filename, "rb") fp = builtins.open(filename, "rb")
exclusive_fp = True exclusive_fp = True
else: else: