Skip to content

gh-159677: fix FileIO.seekable incorrectly returning false - #159678

Draft
KowalskiThomas wants to merge 2 commits into
python:mainfrom
KowalskiThomas:kowalski/fix-fileio-seekable-incorrectly-returning-false
Draft

KowalskiThomas wants to merge 2 commits into
python:mainfrom
KowalskiThomas:kowalski/fix-fileio-seekable-incorrectly-returning-false

Conversation

@KowalskiThomas

Copy link
Copy Markdown
Contributor

Fixes gh-159677.

@KowalskiThomas

Copy link
Copy Markdown
Contributor Author

Seems like the Docs check has flaked :|

@@ -0,0 +1,2 @@
Fix :meth:`io.FileIO.seekable` always returning ``False`` for a seekable file

@cmaloney cmaloney Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seekable and seek are only defined on IOBase in the docs

cpython/Doc/library/io.rst

Lines 422 to 425 in 7dbc797

.. method:: seekable()
Return ``True`` if the stream supports random access. If ``False``,
:meth:`seek`, :meth:`tell` and :meth:`truncate` will raise :exc:`OSError`.

I would probably do something like:

Fix :class:`io.FileIO` ``seekable`` being cached as false because of an invalid argument to :meth:`!io.FileIO.seek`

Comment thread Modules/_io/fileio.c
Py_END_ALLOW_THREADS

if (self->seekable < 0) {
if (self->seekable < 0 && (res >= 0 || errno == ESPIPE || posobj == NULL)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure across the set of OS + kernel + version which Python runs on this is correct... Can work on evaluating that thoroughly but my leaning would be just making it so specific returns we know about that indicate "bad argument" pass through.

For instance EBADF should probably still mark seekable as False / I could see code relying on that. Something like: EINVAL, ENXIO, EOVERFLOW for Linux; EBADF and EINVAL for OpenBSD.

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.

FileIO.seekable() is incorrect if determined by an invalid seek call

2 participants