]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 68677 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Sat, 17 Jan 2009 23:01:43 +0000 (23:01 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 17 Jan 2009 23:01:43 +0000 (23:01 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r68677 | benjamin.peterson | 2009-01-17 16:41:18 -0600 (Sat, 17 Jan 2009) | 9 lines

  Merged revisions 68676 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r68676 | benjamin.peterson | 2009-01-17 16:27:54 -0600 (Sat, 17 Jan 2009) | 1 line

    fix inspect.isclass() on instances with a custom __getattr__ #1225107
  ........
................

Lib/inspect.py
Lib/test/test_inspect.py

index b84aec0f6aaff7dc21012b520c405f233c94042c..549076376c9f7a59e029a6ba499b7f5a3a6c1e0b 100644 (file)
@@ -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.
index ac9fcd7999ce42963ba57cf8bb5db09334af515b..465bb7bff4be9758b14d62f700e4bee4d503e4fa 100644 (file)
@@ -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")