mirror of https://github.com/python/cpython
#2196 hasattr now allows SystemExit and KeyboardInterrupt to propagate
This commit is contained in:
parent
42bfa90f02
commit
b9030f4f0d
|
@ -590,6 +590,16 @@ class BuiltinTest(unittest.TestCase):
|
||||||
if have_unicode:
|
if have_unicode:
|
||||||
self.assertRaises(UnicodeError, hasattr, sys, unichr(sys.maxunicode))
|
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):
|
def test_hash(self):
|
||||||
hash(None)
|
hash(None)
|
||||||
self.assertEqual(hash(1), hash(1L))
|
self.assertEqual(hash(1), hash(1L))
|
||||||
|
|
|
@ -17,6 +17,9 @@ Core and Builtins
|
||||||
|
|
||||||
- Issue #2790: sys.flags was not properly exposing its bytes_warning attribute.
|
- Issue #2790: sys.flags was not properly exposing its bytes_warning attribute.
|
||||||
|
|
||||||
|
- Issue #2196: hasattr now lets exceptions which do not inherit Exception
|
||||||
|
(KeyboardInterrupt, and SystemExit) propagate instead of ignoring them
|
||||||
|
|
||||||
Extension Modules
|
Extension Modules
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
|
|
@ -877,9 +877,13 @@ builtin_hasattr(PyObject *self, PyObject *args)
|
||||||
}
|
}
|
||||||
v = PyObject_GetAttr(v, name);
|
v = PyObject_GetAttr(v, name);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PyErr_Clear();
|
if (!PyErr_ExceptionMatches(PyExc_Exception))
|
||||||
Py_INCREF(Py_False);
|
return NULL;
|
||||||
return Py_False;
|
else {
|
||||||
|
PyErr_Clear();
|
||||||
|
Py_INCREF(Py_False);
|
||||||
|
return Py_False;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
Py_INCREF(Py_True);
|
Py_INCREF(Py_True);
|
||||||
|
|
Loading…
Reference in New Issue