[Python-checkins] r75433 - in python/trunk: Lib/inspect.py Lib/test/test_inspect.py Misc/NEWS
benjamin.peterson
python-checkins at python.org
Thu Oct 15 05:06:55 CEST 2009
Author: benjamin.peterson
Date: Thu Oct 15 05:06:55 2009
New Revision: 75433
Log:
make inspect.isabstract() always return a boolean; add a test for it, too #7069
Modified:
python/trunk/Lib/inspect.py
python/trunk/Lib/test/test_inspect.py
python/trunk/Misc/NEWS
Modified: python/trunk/Lib/inspect.py
==============================================================================
--- python/trunk/Lib/inspect.py (original)
+++ python/trunk/Lib/inspect.py Thu Oct 15 05:06:55 2009
@@ -242,7 +242,7 @@
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.
Modified: python/trunk/Lib/test/test_inspect.py
==============================================================================
--- python/trunk/Lib/test/test_inspect.py (original)
+++ python/trunk/Lib/test/test_inspect.py Thu Oct 15 05:06:55 2009
@@ -115,6 +115,29 @@
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):
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Oct 15 05:06:55 2009
@@ -405,6 +405,8 @@
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
More information about the Python-checkins
mailing list