Commit ab5f8790 authored by Christian Heimes's avatar Christian Heimes

Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient...

Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members.
parent 69a9c5b5
......@@ -1236,6 +1236,13 @@ class MiscIOTest(unittest.TestCase):
else:
self.assert_(issubclass(obj, io.IOBase))
def test_fileio_warnings(self):
with test_support.check_warnings() as w:
self.assertEqual(w.warnings, [])
self.assertRaises(TypeError, io.FileIO, [])
self.assertEqual(w.warnings, [])
self.assertRaises(ValueError, io.FileIO, "/some/invalid/name", "rt")
self.assertEqual(w.warnings, [])
def test_main():
test_support.run_unittest(IOTest, BytesIOTest, StringIOTest,
......
......@@ -86,6 +86,10 @@ fileio_new(PyTypeObject *type, PyObject *args, PyObject *kews)
self = (PyFileIOObject *) type->tp_alloc(type, 0);
if (self != NULL) {
self->fd = -1;
self->readable = 0;
self->writable = 0;
self->seekable = -1;
self->closefd = 1;
self->weakreflist = NULL;
}
......@@ -179,8 +183,6 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
}
}
self->readable = self->writable = 0;
self->seekable = -1;
s = mode;
while (*s) {
switch (*s++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment