@@ -204,6 +204,8 @@ typedef struct {
204
204
205
205
206
206
#define Element_CheckExact (op ) (Py_TYPE(op) == &Element_Type)
207
+ #define Element_Check (op ) PyObject_TypeCheck(op, &Element_Type)
208
+
207
209
208
210
/* -------------------------------------------------------------------- */
209
211
/* Element constructors and destructor */
@@ -1131,7 +1133,7 @@ _elementtree_Element_extend(ElementObject *self, PyObject *elements)
1131
1133
for (i = 0 ; i < PySequence_Fast_GET_SIZE (seq ); i ++ ) {
1132
1134
PyObject * element = PySequence_Fast_GET_ITEM (seq , i );
1133
1135
Py_INCREF (element );
1134
- if (!PyObject_TypeCheck (element , ( PyTypeObject * ) & Element_Type )) {
1136
+ if (!Element_Check (element )) {
1135
1137
PyErr_Format (
1136
1138
PyExc_TypeError ,
1137
1139
"expected an Element, not \"%.200s\"" ,
@@ -1183,7 +1185,7 @@ _elementtree_Element_find_impl(ElementObject *self, PyObject *path,
1183
1185
for (i = 0 ; i < self -> extra -> length ; i ++ ) {
1184
1186
PyObject * item = self -> extra -> children [i ];
1185
1187
int rc ;
1186
- if (!Element_CheckExact (item ))
1188
+ if (!Element_Check (item ))
1187
1189
continue ;
1188
1190
Py_INCREF (item );
1189
1191
rc = PyObject_RichCompareBool (((ElementObject * )item )-> tag , path , Py_EQ );
@@ -1227,14 +1229,14 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyObject *path,
1227
1229
}
1228
1230
1229
1231
for (i = 0 ; i < self -> extra -> length ; i ++ ) {
1230
- ElementObject * item = ( ElementObject * ) self -> extra -> children [i ];
1232
+ PyObject * item = self -> extra -> children [i ];
1231
1233
int rc ;
1232
- if (!Element_CheckExact (item ))
1234
+ if (!Element_Check (item ))
1233
1235
continue ;
1234
1236
Py_INCREF (item );
1235
- rc = PyObject_RichCompareBool (item -> tag , path , Py_EQ );
1237
+ rc = PyObject_RichCompareBool ((( ElementObject * ) item ) -> tag , path , Py_EQ );
1236
1238
if (rc > 0 ) {
1237
- PyObject * text = element_get_text (item );
1239
+ PyObject * text = element_get_text (( ElementObject * ) item );
1238
1240
if (text == Py_None ) {
1239
1241
Py_DECREF (item );
1240
1242
return PyUnicode_New (0 , 0 );
@@ -1267,13 +1269,12 @@ _elementtree_Element_findall_impl(ElementObject *self, PyObject *path,
1267
1269
{
1268
1270
Py_ssize_t i ;
1269
1271
PyObject * out ;
1270
- PyObject * tag = path ;
1271
1272
elementtreestate * st = ET_STATE_GLOBAL ;
1272
1273
1273
- if (checkpath (tag ) || namespaces != Py_None ) {
1274
+ if (checkpath (path ) || namespaces != Py_None ) {
1274
1275
_Py_IDENTIFIER (findall );
1275
1276
return _PyObject_CallMethodId (
1276
- st -> elementpath_obj , & PyId_findall , "OOO" , self , tag , namespaces
1277
+ st -> elementpath_obj , & PyId_findall , "OOO" , self , path , namespaces
1277
1278
);
1278
1279
}
1279
1280
@@ -1287,10 +1288,10 @@ _elementtree_Element_findall_impl(ElementObject *self, PyObject *path,
1287
1288
for (i = 0 ; i < self -> extra -> length ; i ++ ) {
1288
1289
PyObject * item = self -> extra -> children [i ];
1289
1290
int rc ;
1290
- if (!Element_CheckExact (item ))
1291
+ if (!Element_Check (item ))
1291
1292
continue ;
1292
1293
Py_INCREF (item );
1293
- rc = PyObject_RichCompareBool (((ElementObject * )item )-> tag , tag , Py_EQ );
1294
+ rc = PyObject_RichCompareBool (((ElementObject * )item )-> tag , path , Py_EQ );
1294
1295
if (rc != 0 && (rc < 0 || PyList_Append (out , item ) < 0 )) {
1295
1296
Py_DECREF (item );
1296
1297
Py_DECREF (out );
@@ -2145,7 +2146,7 @@ elementiter_next(ElementIterObject *it)
2145
2146
continue ;
2146
2147
}
2147
2148
2148
- if (!PyObject_TypeCheck (extra -> children [child_index ], & Element_Type )) {
2149
+ if (!Element_Check (extra -> children [child_index ])) {
2149
2150
PyErr_Format (PyExc_AttributeError ,
2150
2151
"'%.100s' object has no attribute 'iter'" ,
2151
2152
Py_TYPE (extra -> children [child_index ])-> tp_name );
0 commit comments