]> granicus.if.org Git - python/commitdiff
make inspect.isabstract() always return a boolean; add a test for it, too #7069
authorBenjamin Peterson <benjamin@python.org>
Thu, 15 Oct 2009 03:06:55 +0000 (03:06 +0000)
committerBenjamin Peterson <benjamin@python.org>
Thu, 15 Oct 2009 03:06:55 +0000 (03:06 +0000)
Lib/inspect.py
Lib/test/test_inspect.py
Misc/NEWS

index ac3434d43a600af05dbd45f207c427d9dd9bfb02..e5098d798e538d1c28a6b2e257ccbcda8668a4b1 100644 (file)
@@ -242,7 +242,7 @@ def isroutine(object):
 
 def isabstract(object):
     """Return true if the object is an abstract base class (ABC)."""
-    return isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT
+    return bool(isinstance(object, type) and object.__flags__ & TPFLAGS_IS_ABSTRACT)
 
 def getmembers(object, predicate=None):
     """Return all members of an object as (name, value) pairs sorted by name.
index e4c4ee8039bbd89de7e7c1ed43e3930a21d44c35..f20b26ceb04229f9d4332affc5252254c72909e9 100644 (file)
@@ -115,6 +115,29 @@ class TestPredicates(IsTestBase):
         self.assertTrue('a' in members)
         self.assertTrue('b' not in members)
 
+    def test_isabstract(self):
+        from abc import ABCMeta, abstractmethod
+
+        class AbstractClassExample(object):
+            __metaclass__ = ABCMeta
+
+            @abstractmethod
+            def foo(self):
+                pass
+
+        class ClassExample(AbstractClassExample):
+            def foo(self):
+                pass
+
+        a = ClassExample()
+
+        # Test general behaviour.
+        self.assertTrue(inspect.isabstract(AbstractClassExample))
+        self.assertFalse(inspect.isabstract(ClassExample))
+        self.assertFalse(inspect.isabstract(a))
+        self.assertFalse(inspect.isabstract(int))
+        self.assertFalse(inspect.isabstract(5))
+
 
 class TestInterpreterStack(IsTestBase):
     def __init__(self, *args, **kwargs):
index cd6c9308b5fa809c7ad931c47c06aa119655b4cd..276fc561f9ff547c3827ec60f06f1a19b4c5179a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -405,6 +405,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #7069: Make inspect.isabstract() return a boolean.
+
 - Add support to the `ihooks` module for relative imports.
 
 - Issue #6894: Fixed the issue urllib2 doesn't respect "no_proxy" environment