[Python-checkins] r72907 - in python/trunk: Lib/test/test_descr.py Objects/abstract.c Objects/enumobject.c Objects/object.c Python/sysmodule.c
benjamin.peterson
python-checkins at python.org
Mon May 25 04:40:21 CEST 2009
Author: benjamin.peterson
Date: Mon May 25 04:40:21 2009
New Revision: 72907
Log:
handle errors from _PyObject_LookupSpecial when __get__ fails
Modified:
python/trunk/Lib/test/test_descr.py
python/trunk/Objects/abstract.c
python/trunk/Objects/enumobject.c
python/trunk/Objects/object.c
python/trunk/Python/sysmodule.c
Modified: python/trunk/Lib/test/test_descr.py
==============================================================================
--- python/trunk/Lib/test/test_descr.py (original)
+++ python/trunk/Lib/test/test_descr.py Mon May 25 04:40:21 2009
@@ -1722,7 +1722,11 @@
def __get__(self, obj, owner):
record.append(1)
return self.impl.__get__(obj, owner)
-
+ class MyException(Exception):
+ pass
+ class ErrDescr(object):
+ def __get__(self, obj, owner):
+ raise MyException
for name, runner, meth_impl, ok, env in specials:
class X(Checker):
@@ -1741,6 +1745,18 @@
runner(X())
self.assertEqual(record, [1], name)
+ class X(Checker):
+ pass
+ for attr, obj in env.iteritems():
+ setattr(X, attr, obj)
+ setattr(X, name, ErrDescr())
+ try:
+ runner(X())
+ except MyException:
+ pass
+ else:
+ self.fail("{0!r} didn't raise".format(name))
+
def test_specials(self):
# Testing special operators...
# Test operators like __hash__ for which a built-in default exists
Modified: python/trunk/Objects/abstract.c
==============================================================================
--- python/trunk/Objects/abstract.c (original)
+++ python/trunk/Objects/abstract.c Mon May 25 04:40:21 2009
@@ -111,8 +111,12 @@
return defaultvalue;
/* try o.__length_hint__() */
hintmeth = _PyObject_LookupSpecial(o, "__length_hint__", &hintstrobj);
- if (hintmeth == NULL)
- return defaultvalue;
+ if (hintmeth == NULL) {
+ if (PyErr_Occurred())
+ return -1;
+ else
+ return defaultvalue;
+ }
ro = PyObject_CallFunctionObjArgs(hintmeth, NULL);
Py_DECREF(hintmeth);
if (ro == NULL) {
@@ -2945,6 +2949,8 @@
}
return ok;
}
+ else if (PyErr_Occurred())
+ return -1;
}
return recursive_isinstance(inst, cls);
}
@@ -3021,6 +3027,9 @@
}
return ok;
}
+ else if (PyErr_Occurred()) {
+ return -1;
+ }
}
return recursive_issubclass(derived, cls);
}
Modified: python/trunk/Objects/enumobject.c
==============================================================================
--- python/trunk/Objects/enumobject.c (original)
+++ python/trunk/Objects/enumobject.c Mon May 25 04:40:21 2009
@@ -241,9 +241,12 @@
return NULL;
}
}
- else
+ else {
reversed_meth = _PyObject_LookupSpecial(seq, "__reversed__",
&reversed_cache);
+ if (reversed_meth == NULL && PyErr_Occurred())
+ return NULL;
+ }
if (reversed_meth != NULL) {
PyObject *res = PyObject_CallFunctionObjArgs(reversed_meth, NULL);
Py_DECREF(reversed_meth);
Modified: python/trunk/Objects/object.c
==============================================================================
--- python/trunk/Objects/object.c (original)
+++ python/trunk/Objects/object.c Mon May 25 04:40:21 2009
@@ -509,6 +509,8 @@
res = PyObject_CallFunctionObjArgs(func, NULL);
Py_DECREF(func);
}
+ else if (PyErr_Occurred())
+ return NULL;
}
/* Didn't find __unicode__ */
Modified: python/trunk/Python/sysmodule.c
==============================================================================
--- python/trunk/Python/sysmodule.c (original)
+++ python/trunk/Python/sysmodule.c Mon May 25 04:40:21 2009
@@ -669,10 +669,12 @@
else {
PyObject *method = _PyObject_LookupSpecial(o, "__sizeof__",
&str__sizeof__);
- if (method == NULL)
- PyErr_Format(PyExc_TypeError,
- "Type %.100s doesn't define __sizeof__",
- Py_TYPE(o)->tp_name);
+ if (method == NULL) {
+ if (!PyErr_Occurred())
+ PyErr_Format(PyExc_TypeError,
+ "Type %.100s doesn't define __sizeof__",
+ Py_TYPE(o)->tp_name);
+ }
else {
res = PyObject_CallFunctionObjArgs(method, NULL);
Py_DECREF(method);
More information about the Python-checkins
mailing list