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
io.FileIO('foo', 'rt') prints a RuntimeWarning #48487
Comments
>>> import io
>>> io.FileIO('foo', 'rt')
__main__:1: RuntimeWarning: Trying to close unclosable fd!
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid mode: rt The ValueError is expected, but the warning is not. |
Verified. The issue should be easy to fix. I wonder why 'rt' is an invalid mode. Python 2.x supports 'rt'. |
I propose to move self->closefd closer to the top of the function: Index: Modules/_fileio.c self->readable = self->writable = 0;
self->seekable = -1;
+ self->closefd = closefd;
s = mode;
while (*s) {
switch (*s++) {
@@ -243,7 +244,6 @@ if (fd >= 0) {
self->fd = fd;
- self->closefd = closefd;
}
else {
self->closefd = 1; |
>>> print(io.read.__doc__)
...
The default mode is 'rt' (open for reading text).
... |
'rt' is a valid mode for open() or io.open(). Python 2.6 has exactly the same problem and displays the same Christian, the change you propose does not fix another case:
>>> io.FileIO([]) |
The new patch fixes the problem and adds a unit test, too. The bug was caused by a design flaw -- which was partly my fault. Some We should add a rule that all struct members must be properly I'm raising the severity of the bug to release blocker because I can't |
The patch looks fine to me |
Fixed in r67051 (py3k), r67052 (trunk) |
Merged into the release26 branch, too. |
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: