-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Documentation/implementation out of sync for IO #67043
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
Comments
The docstring on for fileno() method says: "An IOError is raised if the IO object does not use a file descriptor." In reality, UnsupportedOperation is raised instead:
|
Just in case: yes, UnsupportedOperation is an IOError - but shouldn't docstring here be more specific? |
Similarly for the readable(), seekable() and writable() documentation |
Some of the docstrings already mention UnsupportedOperation. This patch updates the rest of the documentation. Also adds some tests to verify this on all the concrete classes I could think of. Some discoveries in the process:
|
Nice patch. But it isn't applied cleanly on current tip (perhaps due to Argument Clinic). Added comments and questions on Rietveld. |
Thanks for looking at this Serhiy. Here is patch v2, merged with 3.6 branch; some doc string changes were redundant with upstream Arg Clinic changes. However looking at this again, I think we should be cautious changing the documented exceptions for the base classes, since that is changing the API. E.g. perhaps it would be safer to leave the exception for fileno() as OSError (aka IOError). It it actually causing a problem? Or the API changes should be reserved for 3.6 only. |
I have doubts about changing OSError to UnsupportedOperation in the documentation of readable() and writable(). Some implementations can try to do an IO operation without checking readable() and writable() flags. I have lesser doubt about using half-closed pipes in tests. May be it is safe, I don't know. |
Okay let’s document fileno(), read, write and seek operations in the base classes as raising OSError then. This effectively rejects the OP (Stanislaw’s) view that the exception should be more specific. In patch v3, I changed everything over to say OSError is raised. I also added a background thread to drain the pipe writer. And I removed a test_no_fileno() method which was having an “existential crisis”. :) |
LGTM. |
New changeset dc9e5f09ac0c by Martin Panter in branch '3.5': New changeset c27e9dcad1a3 by Martin Panter in branch 'default': |
New changeset 3d9d9ca75a31 by Martin Panter in branch '2.7': |
New changeset fb10d1f5016e by Martin Panter in branch 'default': |
New changeset 66765a49465f by Martin Panter in branch '3.5': New changeset 3b7811b58a1f by Martin Panter in branch 'default': |
I gave up on porting the fix to 2.7. Python 3 raises UnsupportedOperation (which inherits ValueError) in many cases due to bpo-9293, but Python 2 raises IOError (which does not inherit ValueError). Changing how BufferedWriter.read() etc work in Python 2 would break test_io_after_close(). Also, none of the doc strings in Python 2 need fixing. Also according to the buildbots, Windows can seek in pipes. Or at least tell() doesn’t raise an exception. So I skipped the seek testing on Windows. |
New changeset b3c79e0ba477 by Martin Panter in branch '3.5': New changeset de8412dc477e by Martin Panter in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: