diff --git a/Doc/library/select.rst b/Doc/library/select.rst --- a/Doc/library/select.rst +++ b/Doc/library/select.rst @@ -18,9 +18,17 @@ The module defines the following: .. exception:: error - The exception raised when an error occurs. The accompanying value is a pair - containing the numeric error code from :c:data:`errno` and the corresponding - string, as would be printed by the C function :c:func:`perror`. + The exception raised when an error occurs. This exception is derived from + :exc:`OSError`. The accompanying value is a pair containing the numeric error code + from :c:data:`errno` and the corresponding string, as would be printed by + the C function :c:func:`perror`. The :attr:`errno` attribute contains the + error code. + + See the module :mod:`errno`, which contains names for the error codes + defined by the underlying operating system. + + .. versionchanged:: 3.3 + The exception is now derived from :exc:`OSError`. .. function:: epoll(sizehint=-1) diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py --- a/Lib/test/test_select.py +++ b/Lib/test/test_select.py @@ -1,8 +1,9 @@ +import errno +import os +import select +import sys +import unittest from test import support -import unittest -import select -import os -import sys @unittest.skipIf(sys.platform[:3] in ('win', 'os2', 'riscos'), "can't easily test on this system") @@ -22,6 +23,18 @@ class SelectTestCase(unittest.TestCase): self.assertRaises(TypeError, select.select, [], [], [], "not a number") self.assertRaises(ValueError, select.select, [], [], [], -1) + def test_errno(self): + with open(__file__, 'rb') as fp: + fd = fp.fileno() + fp.close() + try: + select.select([fd], [], []) + except select.error as err: + self.assertEqual(err.errno, errno.EBADF) + self.assertTrue(isinstance(err, OSError)) + else: + self.fail("exception not raised") + def test_returned_list_identity(self): # See issue #8329 r, w, x = select.select([], [], [], 1) diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -1785,7 +1785,7 @@ PyInit_select(void) if (m == NULL) return NULL; - SelectError = PyErr_NewException("select.error", NULL, NULL); + SelectError = PyErr_NewException("select.error", PyExc_OSError, NULL); Py_INCREF(SelectError); PyModule_AddObject(m, "error", SelectError);