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):
runner(X())
self.assertEqual(record, [1], name)
+ class X(Checker):
+ pass
+ for attr, obj in env.items():
+ 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
/* 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) {
}
return ok;
}
+ else if (PyErr_Occurred())
+ return -1;
return recursive_isinstance(inst, cls);
}
}
return ok;
}
+ else if (PyErr_Occurred())
+ return -1;
return recursive_issubclass(derived, cls);
}
Py_DECREF(reversed_meth);
return res;
}
+ else if (PyErr_Occurred())
+ return NULL;
if (!PySequence_Check(seq)) {
PyErr_SetString(PyExc_TypeError,
}
return result;
}
+ else if (PyErr_Occurred())
+ return NULL;
return PyBytes_FromObject(v);
}
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);