Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 61087) +++ Python/bltinmodule.c (working copy) @@ -857,9 +857,15 @@ } v = PyObject_GetAttr(v, name); if (v == NULL) { - PyErr_Clear(); - Py_INCREF(Py_False); - return Py_False; + if (PyErr_ExceptionMatches(PyExc_KeyboardInterrupt) + || PyErr_ExceptionMatches(PyExc_SystemExit)) { + return NULL; + } + else { + PyErr_Clear(); + Py_INCREF(Py_False); + return Py_False; + } } Py_DECREF(v); Py_INCREF(Py_True); Index: Lib/test/test_builtin.py =================================================================== --- Lib/test/test_builtin.py (revision 61087) +++ Lib/test/test_builtin.py (working copy) @@ -737,6 +737,16 @@ self.assertRaises(TypeError, hasattr) if have_unicode: self.assertRaises(UnicodeError, hasattr, sys, unichr(sys.maxunicode)) + + # Check that hasattr allows SystemExit and KeyboardInterrupts by + class A: + def __getattr__(self, what): + raise KeyboardInterrupt + self.assertRaises(KeyboardInterrupt, hasattr, A(), "b") + class B: + def __getattr__(self, what): + raise SystemExit + self.assertRaises(SystemExit, hasattr, B(), "b") def test_hash(self): hash(None)