[Python-checkins] r57254 - in python/trunk: Lib/test/test_exceptions.py Objects/exceptions.c Python/import.c

georg.brandl python-checkins at python.org
Tue Aug 21 08:03:43 CEST 2007


Author: georg.brandl
Date: Tue Aug 21 08:03:43 2007
New Revision: 57254

Modified:
   python/trunk/Lib/test/test_exceptions.py
   python/trunk/Objects/exceptions.c
   python/trunk/Python/import.c
Log:
Revert accidental checkins from last commit.


Modified: python/trunk/Lib/test/test_exceptions.py
==============================================================================
--- python/trunk/Lib/test/test_exceptions.py	(original)
+++ python/trunk/Lib/test/test_exceptions.py	Tue Aug 21 08:03:43 2007
@@ -9,16 +9,6 @@
                                 catch_warning)
 from test.test_pep352 import ignore_message_warning
 
-class NaiveException(Exception):
-    def __init__(self, x):
-        self.x = x
-
-class SomewhatNaiveException(Exception):
-    def __init__(self, x):
-        self.x = x
-        Exception.__init__(self)
-
-
 # XXX This is not really enough, each *operation* should be tested!
 
 class ExceptionTests(unittest.TestCase):
@@ -273,10 +263,6 @@
                 {'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
                  'object' : u'\u3042', 'reason' : 'ouch',
                  'start' : 0, 'end' : 1}),
-            (NaiveException, ('foo',),
-                {'message': '', 'args': ('foo',), 'x': 'foo'}),
-            (SomewhatNaiveException, ('foo',),
-                {'message': '', 'args': (), 'x': 'foo'}),
         ]
         try:
             exceptionList.append(
@@ -297,8 +283,7 @@
                     if type(e) is not exc:
                         raise
                     # Verify module name
-                    if not type(e).__name__.endswith('NaiveException'):
-                        self.assertEquals(type(e).__module__, 'exceptions')
+                    self.assertEquals(type(e).__module__, 'exceptions')
                     # Verify no ref leaks in Exc_str()
                     s = str(e)
                     for checkArgName in expected:

Modified: python/trunk/Objects/exceptions.c
==============================================================================
--- python/trunk/Objects/exceptions.c	(original)
+++ python/trunk/Objects/exceptions.c	Tue Aug 21 08:03:43 2007
@@ -38,31 +38,18 @@
     /* the dict is created on the fly in PyObject_GenericSetAttr */
     self->message = self->dict = NULL;
 
-    if (!args) {
-        /* MemoryError instantiation */
-        args = PyTuple_New(0);
-        if (!args) {
-            Py_DECREF(self);
-            return NULL;
-        }
-    } else {
-        Py_INCREF(args);
-    }
-    
-    self->args = args;
-
-    /* Since the args can be overwritten in __init__, we have to store
-       the original args somewhere for pickling. */
-    if (PyObject_SetAttrString((PyObject *)self, "__newargs__", args) < 0) {
+    self->args = PyTuple_New(0);
+    if (!self->args) {
         Py_DECREF(self);
         return NULL;
     }
-   
+
     self->message = PyString_FromString("");
     if (!self->message) {
         Py_DECREF(self);
         return NULL;
     }
+
     return (PyObject *)self;
 }
 
@@ -160,23 +147,10 @@
 static PyObject *
 BaseException_reduce(PyBaseExceptionObject *self)
 {
-    PyObject *result;
-    PyObject *newargs = PyObject_GetAttrString((PyObject *)self, "__newargs__");
-    if (!newargs) {
-        if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
-            PyErr_SetString(PyExc_AttributeError,
-                            "To pickle exceptions via BaseException.__reduce__, "
-                            "you need to set the __newargs__ attribute in your "
-                            "custom __new__ method.");
-        }
-        return NULL;
-    }
     if (self->args && self->dict)
-        result = PyTuple_Pack(3, Py_Type(self), newargs, self->dict);
+        return PyTuple_Pack(3, Py_Type(self), self->args, self->dict);
     else
-        result = PyTuple_Pack(2, Py_Type(self), newargs);
-    Py_DECREF(newargs);
-    return result;
+        return PyTuple_Pack(2, Py_Type(self), self->args);
 }
 
 /*

Modified: python/trunk/Python/import.c
==============================================================================
--- python/trunk/Python/import.c	(original)
+++ python/trunk/Python/import.c	Tue Aug 21 08:03:43 2007
@@ -1395,7 +1395,6 @@
 			filemode = fdp->mode;
 			if (filemode[0] == 'U')
 				filemode = "r" PY_STDIOTEXTMODE;
-			errno = 0;
 			fp = fopen(buf, filemode);
 			if (fp != NULL) {
 				if (case_ok(buf, len, namelen, name))
@@ -1405,15 +1404,6 @@
 					fp = NULL;
 				}
 			}
-			/* issue a warning if the file is there */
-			/*if (errno != ENOENT) {
-				char warnstr[MAXPATHLEN+80];
-				sprintf(warnstr, "Not importing '%.*s': ");
-				
-				if (PyErr_Warn(PyExc_ImportWarning,
-					       warnstr)) {
-
-			}*/
 #if defined(PYOS_OS2)
 			/* restore the saved snapshot */
 			strcpy(buf, saved_buf);


More information about the Python-checkins mailing list