class Child(Super):
pass
+# new-style classes
+class NewSuper(object):
+ pass
+
+class NewChild(NewSuper):
+ pass
+
\f
class TestIsInstanceIsSubclass(unittest.TestCase):
self.assertEqual(False, issubclass(Super, (Child,)))
self.assertEqual(True, issubclass(Super, (Child, Super)))
self.assertEqual(False, issubclass(Child, ()))
- self.assertRaises(TypeError, issubclass, Child, ((Child,),))
+ self.assertEqual(True, issubclass(Super, (Child, (Super,))))
+
+ self.assertEqual(True, issubclass(NewChild, (NewChild,)))
+ self.assertEqual(True, issubclass(NewChild, (NewSuper,)))
+ self.assertEqual(False, issubclass(NewSuper, (NewChild,)))
+ self.assertEqual(True, issubclass(NewSuper, (NewChild, NewSuper)))
+ self.assertEqual(False, issubclass(NewChild, ()))
+ self.assertEqual(True, issubclass(NewSuper, (NewChild, (NewSuper,))))
+
+ self.assertEqual(True, issubclass(int, (long, (float, int))))
+ self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring))))
int i;
int n = PyTuple_GET_SIZE(cls);
for (i = 0; i < n; ++i) {
- if (!check_class(PyTuple_GET_ITEM(cls, i),
- "issubclass() arg 2 must be a class"
- " or tuple of classes"))
- return -1;
+ retval = PyObject_IsSubclass(derived, PyTuple_GET_ITEM(cls, i));
+ if (retval != 0) /* either found it, or got an error */
+ return retval;
}
+ return 0;
}
else {
if (!check_class(cls,
if (PyTuple_Check(base)) {
n = PyTuple_GET_SIZE(base);
for (i = 0; i < n; i++) {
- if (class == PyTuple_GET_ITEM(base, i))
+ if (PyClass_IsSubclass(class, PyTuple_GET_ITEM(base, i)))
return 1;
}
+ return 0;
}
if (class == NULL || !PyClass_Check(class))
return 0;