summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-10-15 03:06:55 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-10-15 03:06:55 (GMT)
commitc63457b18e986ae74a13e5b6601bdbd58e909c84 (patch)
tree906f6ead74945d99c97f1082b231908b2ecb8600
parentca2d2529cee492ea0ac2b88ba0fdeb75fff0781a (diff)
downloadcpython-c63457b18e986ae74a13e5b6601bdbd58e909c84.zip
cpython-c63457b18e986ae74a13e5b6601bdbd58e909c84.tar.gz
cpython-c63457b18e986ae74a13e5b6601bdbd58e909c84.tar.bz2
make inspect.isabstract() always return a boolean; add a test for it, too #7069
-rw-r--r--Lib/inspect.py2
-rw-r--r--Lib/test/test_inspect.py23
-rw-r--r--Misc/NEWS2
3 files changed, 26 insertions, 1 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index ac3434d..e5098d7 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -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.
diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py
index e4c4ee8..f20b26c 100644
--- a/Lib/test/test_inspect.py
+++ b/Lib/test/test_inspect.py
@@ -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):
diff --git a/Misc/NEWS b/Misc/NEWS
index cd6c930..276fc56 100644
--- 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