@@ -169,7 +169,7 @@ builtin_filter(self, args)
169
169
if ((item = (* sqf -> sq_item )(seq , i )) == NULL ) {
170
170
if (i < len )
171
171
goto Fail_1 ;
172
- if (PyErr_Occurred () == PyExc_IndexError ) {
172
+ if (PyErr_ExceptionMatches ( PyExc_IndexError ) ) {
173
173
PyErr_Clear ();
174
174
break ;
175
175
}
@@ -726,8 +726,9 @@ builtin_map(self, args)
726
726
if (item == NULL ) {
727
727
if (i < sqp -> len )
728
728
goto Fail_0 ;
729
- if (PyErr_Occurred () ==
730
- PyExc_IndexError ) {
729
+ if (PyErr_ExceptionMatches (
730
+ PyExc_IndexError ))
731
+ {
731
732
PyErr_Clear ();
732
733
Py_INCREF (Py_None );
733
734
item = Py_None ;
@@ -1067,7 +1068,7 @@ min_max(args, sign)
1067
1068
for (i = 0 ; ; i ++ ) {
1068
1069
x = (* sq -> sq_item )(v , i ); /* Implies INCREF */
1069
1070
if (x == NULL ) {
1070
- if (PyErr_Occurred () == PyExc_IndexError ) {
1071
+ if (PyErr_ExceptionMatches ( PyExc_IndexError ) ) {
1071
1072
PyErr_Clear ();
1072
1073
break ;
1073
1074
}
@@ -1415,7 +1416,7 @@ builtin_reduce(self, args)
1415
1416
}
1416
1417
1417
1418
if ((op2 = (* sqf -> sq_item )(seq , i )) == NULL ) {
1418
- if (PyErr_Occurred () == PyExc_IndexError ) {
1419
+ if (PyErr_ExceptionMatches ( PyExc_IndexError ) ) {
1419
1420
PyErr_Clear ();
1420
1421
break ;
1421
1422
}
@@ -1613,6 +1614,57 @@ builtin_vars(self, args)
1613
1614
return d ;
1614
1615
}
1615
1616
1617
+ static PyObject *
1618
+ builtin_isinstance (self , args )
1619
+ PyObject * self ;
1620
+ PyObject * args ;
1621
+ {
1622
+ PyObject * inst ;
1623
+ PyObject * cls ;
1624
+ int retval ;
1625
+
1626
+ if (!PyArg_ParseTuple (args , "OO" , & inst , & cls ))
1627
+ return NULL ;
1628
+ if (!PyClass_Check (cls )) {
1629
+ PyErr_SetString (PyExc_TypeError ,
1630
+ "second argument must be a class" );
1631
+ return NULL ;
1632
+ }
1633
+
1634
+ if (!PyInstance_Check (inst ))
1635
+ retval = 0 ;
1636
+ else {
1637
+ PyObject * inclass =
1638
+ (PyObject * )((PyInstanceObject * )inst )-> in_class ;
1639
+ retval = PyClass_IsSubclass (inclass , cls );
1640
+ }
1641
+ return PyInt_FromLong (retval );
1642
+ }
1643
+
1644
+
1645
+ static PyObject *
1646
+ builtin_issubclass (self , args )
1647
+ PyObject * self ;
1648
+ PyObject * args ;
1649
+ {
1650
+ PyObject * derived ;
1651
+ PyObject * cls ;
1652
+ int retval ;
1653
+
1654
+ if (!PyArg_ParseTuple (args , "OO" , & derived , & cls ))
1655
+ return NULL ;
1656
+ if (!PyClass_Check (derived ) || !PyClass_Check (cls )) {
1657
+ PyErr_SetString (PyExc_TypeError , "arguments must be classes" );
1658
+ return NULL ;
1659
+ }
1660
+ /* shortcut */
1661
+ if (!(retval = (derived == cls )))
1662
+ retval = PyClass_IsSubclass (derived , cls );
1663
+
1664
+ return PyInt_FromLong (retval );
1665
+ }
1666
+
1667
+
1616
1668
static PyMethodDef builtin_methods [] = {
1617
1669
{"__import__" , builtin___import__ , 1 },
1618
1670
{"abs" , builtin_abs , 1 },
@@ -1641,6 +1693,8 @@ static PyMethodDef builtin_methods[] = {
1641
1693
{"input" , builtin_input , 1 },
1642
1694
{"intern" , builtin_intern , 1 },
1643
1695
{"int" , builtin_int , 1 },
1696
+ {"isinstance" , builtin_isinstance , 1 },
1697
+ {"issubclass" , builtin_issubclass , 1 },
1644
1698
{"len" , builtin_len , 1 },
1645
1699
{"list" , builtin_list , 1 },
1646
1700
{"locals" , builtin_locals , 1 },
0 commit comments