Skip to content

Commit d7e9f60

Browse files
committed
Revert accidental checkins from last commit.
1 parent fdca6d8 commit d7e9f60

3 files changed

Lines changed: 7 additions & 58 deletions

File tree

Lib/test/test_exceptions.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
catch_warning)
1010
from test.test_pep352 import ignore_message_warning
1111

12-
class NaiveException(Exception):
13-
def __init__(self, x):
14-
self.x = x
15-
16-
class SomewhatNaiveException(Exception):
17-
def __init__(self, x):
18-
self.x = x
19-
Exception.__init__(self)
20-
21-
2212
# XXX This is not really enough, each *operation* should be tested!
2313

2414
class ExceptionTests(unittest.TestCase):
@@ -273,10 +263,6 @@ def testAttributes(self):
273263
{'message' : '', 'args' : (u'\u3042', 0, 1, 'ouch'),
274264
'object' : u'\u3042', 'reason' : 'ouch',
275265
'start' : 0, 'end' : 1}),
276-
(NaiveException, ('foo',),
277-
{'message': '', 'args': ('foo',), 'x': 'foo'}),
278-
(SomewhatNaiveException, ('foo',),
279-
{'message': '', 'args': (), 'x': 'foo'}),
280266
]
281267
try:
282268
exceptionList.append(
@@ -297,8 +283,7 @@ def testAttributes(self):
297283
if type(e) is not exc:
298284
raise
299285
# Verify module name
300-
if not type(e).__name__.endswith('NaiveException'):
301-
self.assertEquals(type(e).__module__, 'exceptions')
286+
self.assertEquals(type(e).__module__, 'exceptions')
302287
# Verify no ref leaks in Exc_str()
303288
s = str(e)
304289
for checkArgName in expected:

Objects/exceptions.c

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,31 +38,18 @@ BaseException_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
3838
/* the dict is created on the fly in PyObject_GenericSetAttr */
3939
self->message = self->dict = NULL;
4040

41-
if (!args) {
42-
/* MemoryError instantiation */
43-
args = PyTuple_New(0);
44-
if (!args) {
45-
Py_DECREF(self);
46-
return NULL;
47-
}
48-
} else {
49-
Py_INCREF(args);
50-
}
51-
52-
self->args = args;
53-
54-
/* Since the args can be overwritten in __init__, we have to store
55-
the original args somewhere for pickling. */
56-
if (PyObject_SetAttrString((PyObject *)self, "__newargs__", args) < 0) {
41+
self->args = PyTuple_New(0);
42+
if (!self->args) {
5743
Py_DECREF(self);
5844
return NULL;
5945
}
60-
46+
6147
self->message = PyString_FromString("");
6248
if (!self->message) {
6349
Py_DECREF(self);
6450
return NULL;
6551
}
52+
6653
return (PyObject *)self;
6754
}
6855

@@ -160,23 +147,10 @@ BaseException_repr(PyBaseExceptionObject *self)
160147
static PyObject *
161148
BaseException_reduce(PyBaseExceptionObject *self)
162149
{
163-
PyObject *result;
164-
PyObject *newargs = PyObject_GetAttrString((PyObject *)self, "__newargs__");
165-
if (!newargs) {
166-
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
167-
PyErr_SetString(PyExc_AttributeError,
168-
"To pickle exceptions via BaseException.__reduce__, "
169-
"you need to set the __newargs__ attribute in your "
170-
"custom __new__ method.");
171-
}
172-
return NULL;
173-
}
174150
if (self->args && self->dict)
175-
result = PyTuple_Pack(3, Py_Type(self), newargs, self->dict);
151+
return PyTuple_Pack(3, Py_Type(self), self->args, self->dict);
176152
else
177-
result = PyTuple_Pack(2, Py_Type(self), newargs);
178-
Py_DECREF(newargs);
179-
return result;
153+
return PyTuple_Pack(2, Py_Type(self), self->args);
180154
}
181155

182156
/*

Python/import.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,6 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
13951395
filemode = fdp->mode;
13961396
if (filemode[0] == 'U')
13971397
filemode = "r" PY_STDIOTEXTMODE;
1398-
errno = 0;
13991398
fp = fopen(buf, filemode);
14001399
if (fp != NULL) {
14011400
if (case_ok(buf, len, namelen, name))
@@ -1405,15 +1404,6 @@ find_module(char *fullname, char *subname, PyObject *path, char *buf,
14051404
fp = NULL;
14061405
}
14071406
}
1408-
/* issue a warning if the file is there */
1409-
/*if (errno != ENOENT) {
1410-
char warnstr[MAXPATHLEN+80];
1411-
sprintf(warnstr, "Not importing '%.*s': ");
1412-
1413-
if (PyErr_Warn(PyExc_ImportWarning,
1414-
warnstr)) {
1415-
1416-
}*/
14171407
#if defined(PYOS_OS2)
14181408
/* restore the saved snapshot */
14191409
strcpy(buf, saved_buf);

0 commit comments

Comments
 (0)