[Jython-checkins] jython: Don't swallow SystemExit or KeyboardInterrupt from hasattr.

frank.wierzbicki jython-checkins at python.org
Thu May 3 21:03:58 CEST 2012


http://hg.python.org/jython/rev/003b5ba52cfa
changeset:   6643:003b5ba52cfa
parent:      6637:23d0189442da
user:        Frank Wierzbicki <fwierzbicki at gmail.com>
date:        Thu May 03 11:59:51 2012 -0700
summary:
  Don't swallow SystemExit or KeyboardInterrupt from hasattr.

files:
  Lib/test/test_builtin.py             |  6 ++----
  src/org/python/core/__builtin__.java |  5 ++++-
  2 files changed, 6 insertions(+), 5 deletions(-)


diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py
--- a/Lib/test/test_builtin.py
+++ b/Lib/test/test_builtin.py
@@ -602,13 +602,11 @@
         class A:
             def __getattr__(self, what):
                 raise KeyboardInterrupt
-        if not is_jython: #FIXME #1861: not working in Jython
-            self.assertRaises(KeyboardInterrupt, hasattr, A(), "b")
+        self.assertRaises(KeyboardInterrupt, hasattr, A(), "b")
         class B:
             def __getattr__(self, what):
                 raise SystemExit
-        if not is_jython: #FIXME #1861: not working in Jython
-            self.assertRaises(SystemExit, hasattr, B(), "b")
+        self.assertRaises(SystemExit, hasattr, B(), "b")
 
     def test_hash(self):
         hash(None)
diff --git a/src/org/python/core/__builtin__.java b/src/org/python/core/__builtin__.java
--- a/src/org/python/core/__builtin__.java
+++ b/src/org/python/core/__builtin__.java
@@ -647,7 +647,10 @@
         try {
             return obj.__findattr__(name) != null;
         } catch (PyException pye) {
-            // swallow
+            if (pye.match(Py.KeyboardInterrupt) || pye.match(Py.SystemExit)) {
+                throw pye;
+            }
+            //Otherwise swallow exception.
         }
         return false;
     }

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list