diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -194,6 +194,18 @@ self.fdopen_helper('r') self.fdopen_helper('r', 100) + @unittest.skipUnless(hasattr(posix, 'fdopen'), + 'test needs posix.fdopen()') + def test_fdopen_directory(self): + try: + fd = os.open('.', os.O_RDONLY) + except OSError as e: + self.assertEqual(e.errno, errno.EACCES) + self.skipTest("system cannot open directories") + with self.assertRaises(IOError) as cm: + os.fdopen(fd, 'r') + self.assertEqual(cm.exception.errno, errno.EISDIR) + @unittest.skipUnless(hasattr(posix, 'fdopen') and not sys.platform.startswith("sunos"), 'test needs posix.fdopen()') diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6861,7 +6861,7 @@ if (fstat(fd, &buf) == 0 && S_ISDIR(buf.st_mode)) { PyMem_FREE(mode); msg = strerror(EISDIR); - exc = PyObject_CallFunction(PyExc_IOError, "(isO)", + exc = PyObject_CallFunction(PyExc_IOError, "(iss)", EISDIR, msg, ""); if (exc) { PyErr_SetObject(PyExc_IOError, exc);