]> granicus.if.org Git - python/commitdiff
Merged revisions 67052 via svnmerge from
authorChristian Heimes <christian@cheimes.de>
Thu, 30 Oct 2008 21:52:43 +0000 (21:52 +0000)
committerChristian Heimes <christian@cheimes.de>
Thu, 30 Oct 2008 21:52:43 +0000 (21:52 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67052 | christian.heimes | 2008-10-30 22:26:15 +0100 (Thu, 30 Oct 2008) | 1 line

  Issue #4237: io.FileIO() was raising invalid warnings caused by insufficient initialization of PyFileIOObject struct members.
........

Lib/test/test_io.py
Modules/_fileio.c

index 9ef2a818b3d4aa11fea24548287f66c4ddf70c30..08a524fa99d22cd3c12dff54895f39c990696de1 100644 (file)
@@ -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,
index d7f78936715c9d5c7e3da06426024948a8fdfab3..0d770ceb34379a4181f01c082514e0b34e5fe39f 100644 (file)
@@ -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++) {