[pypy-svn] r9909 - in pypy/dist: lib-python-2.3.4/test pypy/module/builtin

arigo at codespeak.net arigo at codespeak.net
Sun Mar 20 00:48:31 CET 2005


Author: arigo
Date: Sun Mar 20 00:48:31 2005
New Revision: 9909

Modified:
   pypy/dist/lib-python-2.3.4/test/conftest.py
   pypy/dist/pypy/module/builtin/app_inspect.py
Log:
Dark cases for isinstance().


Modified: pypy/dist/lib-python-2.3.4/test/conftest.py
==============================================================================
--- pypy/dist/lib-python-2.3.4/test/conftest.py	(original)
+++ pypy/dist/lib-python-2.3.4/test/conftest.py	Sun Mar 20 00:48:31 2005
@@ -40,6 +40,7 @@
 'test_heapq.py',
 'test_htmllib.py',
 'test_htmlparser.py',
+'test_isinstance.py',
 'test_operator.py',
 'test_pprint.py',
 'test_sgmllib.py',

Modified: pypy/dist/pypy/module/builtin/app_inspect.py
==============================================================================
--- pypy/dist/pypy/module/builtin/app_inspect.py	(original)
+++ pypy/dist/pypy/module/builtin/app_inspect.py	Sun Mar 20 00:48:31 2005
@@ -17,12 +17,12 @@
 def _recursive_issubclass(cls, klass_or_tuple):
     if cls is klass_or_tuple:
         return True
-    for base in cls.__bases__:
+    for base in getattr(cls, '__bases__', ()):
         if _recursive_issubclass(base, klass_or_tuple):
             return True
     return False
 
-def issubclass(cls, klass_or_tuple):
+def _issubclass(cls, klass_or_tuple, check_cls):
     if _issubtype(type(klass_or_tuple), tuple):
         for klass in klass_or_tuple:
             if issubclass(cls, klass):
@@ -31,12 +31,14 @@
     try:
         return _issubtype(cls, klass_or_tuple)
     except TypeError:
-        if not hasattr(cls, '__bases__'):
+        if check_cls and not hasattr(cls, '__bases__'):
             raise TypeError, "arg 1 must be a class or type"
         if not hasattr(klass_or_tuple, '__bases__'):
             raise TypeError, "arg 2 must be a class or type or a tuple thereof"
         return _recursive_issubclass(cls, klass_or_tuple)
 
+def issubclass(cls, klass_or_tuple):
+    return _issubclass(cls, klass_or_tuple, True)
 
 def isinstance(obj, klass_or_tuple):
     if issubclass(type(obj), klass_or_tuple):
@@ -46,7 +48,8 @@
     except AttributeError:
         return False
     else:
-        return objcls is not type(obj) and issubclass(objcls, klass_or_tuple)
+        return (objcls is not type(obj) and
+                _issubclass(objcls, klass_or_tuple, False))
 
 
 def vars(*obj):



More information about the Pypy-commit mailing list