Skip to content

Conversation

@cmaloney
Copy link
Contributor

@cmaloney cmaloney commented Nov 7, 2025

io.UnsupportedOperation is a subclass of OSError and recommended by io.IOBase for this case; matches other read methods on io.FileIO.

While the issue was filed as a bug given how long this has raised OSError directly I'd like to treat it like a feature and have it 3.15/main only.

io.UnsupportedOperation is a subclass of OSError and recommended by
io.IOBase for this case; matches other read methods on io.FileIO.
@cmaloney
Copy link
Contributor Author

cc: @vstinner

@vstinner
Copy link
Member

Currently, OSError(EBADF) is raised:

>>> fp=open("out", "wb", buffering=0)
>>> fp
<_io.FileIO name='out' mode='wb' closefd=True>
>>> fp.readall()
Traceback (most recent call last):
   ...
OSError: [Errno 9] Bad file descriptor

@vstinner
Copy link
Member

Ah, _pyio already raises UnsupportedOperation:

>>> import _pyio
>>> fp=_pyio.open("out", "wb", buffering=0)
>>> fp.readall()
Traceback (most recent call last):
  ...
io.UnsupportedOperation: File not open for reading

@vstinner vstinner merged commit 6f988b0 into python:main Nov 12, 2025
46 checks passed
@vstinner
Copy link
Member

Merged, thanks. The change makes sense.

While the issue was filed as a bug given how long this has raised OSError directly I'd like to treat it like a feature and have it 3.15/main only.

I agree, there is no need to backport this change to stable branches.

@cmaloney cmaloney deleted the fileio_readall_readable branch November 14, 2025 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants