diff --git a/Lib/inspect.py b/Lib/inspect.py index 45515fca566..54365313b1f 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -63,7 +63,7 @@ def isclass(object): Class objects provide these attributes: __doc__ documentation string __module__ name of module in which this class was defined""" - return isinstance(object, type) or hasattr(object, '__bases__') + return isinstance(object, type) def ismethod(object): """Return true if the object is an instance method. diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index b3aa28cf7ca..e2fe641ec03 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -74,7 +74,6 @@ class TestPredicates(IsTestBase): def test_excluding_predicates(self): self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, '[].append') - self.istest(inspect.isclass, 'mod.StupidGit') self.istest(inspect.iscode, 'mod.spam.__code__') self.istest(inspect.isframe, 'tb.tb_frame') self.istest(inspect.isfunction, 'mod.spam') @@ -99,6 +98,15 @@ class TestPredicates(IsTestBase): self.assert_(inspect.isroutine(mod.spam)) self.assert_(inspect.isroutine([].count)) + def test_isclass(self): + self.istest(inspect.isclass, 'mod.StupidGit') + self.assertTrue(inspect.isclass(list)) + + class CustomGetattr(object): + def __getattr__(self, attr): + return None + self.assertFalse(inspect.isclass(CustomGetattr())) + def test_get_slot_members(self): class C(object): __slots__ = ("a", "b")