[Python-checkins] cpython: alias resource.error to OSError

benjamin.peterson python-checkins at python.org
Sat Dec 10 23:55:36 CET 2011


http://hg.python.org/cpython/rev/8d670cb0d64a
changeset:   73930:8d670cb0d64a
parent:      73926:aab45b904141
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat Dec 10 17:50:22 2011 -0500
summary:
  alias resource.error to OSError

files:
  Doc/library/resource.rst |   8 +++++---
  Misc/NEWS                |   2 ++
  Modules/resource.c       |  16 +++++-----------
  3 files changed, 12 insertions(+), 14 deletions(-)


diff --git a/Doc/library/resource.rst b/Doc/library/resource.rst
--- a/Doc/library/resource.rst
+++ b/Doc/library/resource.rst
@@ -14,13 +14,15 @@
 Symbolic constants are used to specify particular system resources and to
 request usage information about either the current process or its children.
 
-A single exception is defined for errors:
+An :exc:`OSError` is raised on syscall failure.
 
 
 .. exception:: error
 
-   The functions described below may raise this error if the underlying system call
-   failures unexpectedly.
+   A deprecated alias of :exc:`OSError`.
+
+   .. versionchanged:: 3.3
+      Following :pep:`3151`, this class was made an alias of :exc:`OSError`.
 
 
 Resource Limits
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -406,6 +406,8 @@
 Library
 -------
 
+- Alias resource.error to OSError ala PEP 3151.
+
 - Issue #13248: Turn 3.2's PendingDeprecationWarning into 3.3's
   DeprecationWarning.  It covers 'cgi.escape', 'importlib.abc.PyLoader',
   'importlib.abc.PyPycLoader', 'nntplib.NNTP.xgtitle', 'nntplib.NNTP.xpath',
diff --git a/Modules/resource.c b/Modules/resource.c
--- a/Modules/resource.c
+++ b/Modules/resource.c
@@ -18,8 +18,6 @@
 
 #define doubletime(TV) ((double)(TV).tv_sec + (TV).tv_usec * 0.000001)
 
-static PyObject *ResourceError;
-
 PyDoc_STRVAR(struct_rusage__doc__,
 "struct_rusage: Result from getrusage.\n\n"
 "This object may be accessed either as a tuple of\n"
@@ -73,7 +71,7 @@
                             "invalid who parameter");
             return NULL;
         }
-        PyErr_SetFromErrno(ResourceError);
+        PyErr_SetFromErrno(PyExc_OSError);
         return NULL;
     }
 
@@ -125,7 +123,7 @@
     }
 
     if (getrlimit(resource, &rl) == -1) {
-        PyErr_SetFromErrno(ResourceError);
+        PyErr_SetFromErrno(PyExc_OSError);
         return NULL;
     }
 
@@ -183,7 +181,7 @@
             PyErr_SetString(PyExc_ValueError,
                             "not allowed to raise maximum limit");
         else
-            PyErr_SetFromErrno(ResourceError);
+            PyErr_SetFromErrno(PyExc_OSError);
         return NULL;
     }
     Py_INCREF(Py_None);
@@ -246,12 +244,8 @@
         return NULL;
 
     /* Add some symbolic constants to the module */
-    if (ResourceError == NULL) {
-        ResourceError = PyErr_NewException("resource.error",
-                                           NULL, NULL);
-    }
-    Py_INCREF(ResourceError);
-    PyModule_AddObject(m, "error", ResourceError);
+    Py_INCREF(PyExc_OSError);
+    PyModule_AddObject(m, "error", PyExc_OSError);
     if (!initialized)
         PyStructSequence_InitType(&StructRUsageType,
                                   &struct_rusage_desc);

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list