Repository navigation
gh-159677: fix FileIO.seekable incorrectly returning false
#159678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix :meth:`io.FileIO.seekable` always returning ``False`` for a seekable file | ||
| when the first call to :meth:`~io.FileIO.seek` failed. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1013,7 +1013,7 @@ portable_lseek(fileio *self, PyObject *posobj, int whence, bool suppress_pipe_er | |
| _Py_END_SUPPRESS_IPH | ||
| Py_END_ALLOW_THREADS | ||
|
|
||
| if (self->seekable < 0) { | ||
| if (self->seekable < 0 && (res >= 0 || errno == ESPIPE || posobj == NULL)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| self->seekable = (res >= 0); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seekableandseekare only defined on IOBase in the docscpython/Doc/library/io.rst
Lines 422 to 425 in 7dbc797
I would probably do something like: