[Python-checkins] r86577 - in python/branches/py3k: Lib/test/test_isinstance.py Misc/ACKS Misc/NEWS Objects/abstract.c
r.david.murray
python-checkins at python.org
Sat Nov 20 17:33:30 CET 2010
Author: r.david.murray
Date: Sat Nov 20 17:33:30 2010
New Revision: 86577
Log:
#1574217: only swallow AttributeErrors in isinstance, not everything.
Patch and tests by Brian Harring, with improvements by Ralf Schmitt.
Modified:
python/branches/py3k/Lib/test/test_isinstance.py
python/branches/py3k/Misc/ACKS
python/branches/py3k/Misc/NEWS
python/branches/py3k/Objects/abstract.c
Modified: python/branches/py3k/Lib/test/test_isinstance.py
==============================================================================
--- python/branches/py3k/Lib/test/test_isinstance.py (original)
+++ python/branches/py3k/Lib/test/test_isinstance.py Sat Nov 20 17:33:30 2010
@@ -81,6 +81,20 @@
self.assertRaises(TypeError, isinstance, I(), C())
+ # check that we don't mask non AttributeErrors
+ # see: http://bugs.python.org/issue1574217
+ def test_isinstance_dont_mask_non_attribute_error(self):
+ class C(object):
+ def getclass(self):
+ raise RuntimeError()
+ __class__=property(getclass)
+
+ c=C()
+ self.assertRaises(RuntimeError, isinstance, c, bool)
+
+ # test another code path
+ class D: pass
+ self.assertRaises(RuntimeError, isinstance, c, D)
# These tests are similar to above, but tickle certain code paths in
Modified: python/branches/py3k/Misc/ACKS
==============================================================================
--- python/branches/py3k/Misc/ACKS (original)
+++ python/branches/py3k/Misc/ACKS Sat Nov 20 17:33:30 2010
@@ -337,6 +337,7 @@
Lynda Hardman
Derek Harland
Jason Harper
+Brian Harring
Larry Hastings
Shane Hathaway
Rycharde Hawkes
Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS (original)
+++ python/branches/py3k/Misc/NEWS Sat Nov 20 17:33:30 2010
@@ -10,6 +10,9 @@
Core and Builtins
-----------------
+- Issue #1574217: isinstance now catches only AttributeError, rather than
+ masking all errors.
+
- Issue #10391: Don't dereference invalid memory in error messages in the ast
module.
Modified: python/branches/py3k/Objects/abstract.c
==============================================================================
--- python/branches/py3k/Objects/abstract.c (original)
+++ python/branches/py3k/Objects/abstract.c Sat Nov 20 17:33:30 2010
@@ -2500,7 +2500,12 @@
if (retval == 0) {
PyObject *c = PyObject_GetAttr(inst, __class__);
if (c == NULL) {
- PyErr_Clear();
+ if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
+ }
+ else {
+ retval = -1;
+ }
}
else {
if (c != (PyObject *)(inst->ob_type) &&
@@ -2518,8 +2523,12 @@
return -1;
icls = PyObject_GetAttr(inst, __class__);
if (icls == NULL) {
- PyErr_Clear();
- retval = 0;
+ if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
+ PyErr_Clear();
+ }
+ else {
+ retval = -1;
+ }
}
else {
retval = abstract_issubclass(icls, cls);
More information about the Python-checkins
mailing list