◐ Shell
clean mode source ↗

Message 75431 - Python tracker

I don't see a good 'n easy way to fix the issue. close() is called in
too many places and I don't wanna add more checks in Python code. 

This patch reduces the mass of warnings to one, but it also changes the
semantic of close() a bit. However it seems logical to set the fd
attribute of the file object to -1 (meaning closed).

Index: Modules/_fileio.c
===================================================================
--- Modules/_fileio.c   (Revision 67068)
+++ Modules/_fileio.c   (Arbeitskopie)
@@ -60,7 +60,8 @@
 static PyObject *
 fileio_close(PyFileIOObject *self)
 {
-       if (!self->closefd) {
+       if (!self->closefd && self->fd >= 0) {
+               self->fd = -1;
                if (PyErr_WarnEx(PyExc_RuntimeWarning,
                                 "Trying to close unclosable fd!", 3) < 0) {
                        return NULL;