summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_io.py7
-rw-r--r--Modules/_fileio.c6
2 files changed, 11 insertions, 2 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index bcb37d7..ea965d7 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -1237,6 +1237,13 @@ class MiscIOTest(unittest.TestCase):
else:
self.assert_(issubclass(obj, io.IOBase))
+ def test_fileio_warnings(self):
+ with 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():
support.run_unittest(IOTest, BytesIOTest, StringIOTest,
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index 3b0f81b..4b35194 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -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++) {