Skip to content

Inconsistent Image.open(str) #9047

@senyai

Description

@senyai

Image.open("") must raise an exception matching open("")

In [1]: from PIL import Image

In [2]: Image.open("non_existent_file")
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 1
----> 1 Image.open("non_existent_file")

File ~/.local/lib/python3.13/site-packages/PIL/Image.py:3505, in open(fp, mode, formats)
   3502     filename = os.fspath(fp)
   3504 if filename:
-> 3505     fp = builtins.open(filename, "rb")
   3506     exclusive_fp = True
   3507 else:

FileNotFoundError: [Errno 2] No such file or directory: 'non_existent_file'

In [3]: Image.open("")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.local/lib/python3.13/site-packages/PIL/Image.py:3511, in open(fp, mode, formats)
   3510 try:
-> 3511     fp.seek(0)
   3512 except (AttributeError, io.UnsupportedOperation):

AttributeError: 'str' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
Cell In[3], line 1
----> 1 Image.open("")

File ~/.local/lib/python3.13/site-packages/PIL/Image.py:3513, in open(fp, mode, formats)
   3511     fp.seek(0)
   3512 except (AttributeError, io.UnsupportedOperation):
-> 3513     fp = io.BytesIO(fp.read())
   3514     exclusive_fp = True
   3516 prefix = fp.read(16)

AttributeError: 'str' object has no attribute 'read'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions