@@ -204,6 +204,8 @@ typedef struct {
204204
205205
206206#define Element_CheckExact (op ) (Py_TYPE(op) == &Element_Type)
207+ #define Element_Check (op ) PyObject_TypeCheck(op, &Element_Type)
208+
207209
208210/* -------------------------------------------------------------------- */
209211/* Element constructors and destructor */
@@ -1132,7 +1134,7 @@ _elementtree_Element_extend(ElementObject *self, PyObject *elements)
11321134 for (i = 0 ; i < PySequence_Fast_GET_SIZE (seq ); i ++ ) {
11331135 PyObject * element = PySequence_Fast_GET_ITEM (seq , i );
11341136 Py_INCREF (element );
1135- if (!PyObject_TypeCheck (element , ( PyTypeObject * ) & Element_Type )) {
1137+ if (!Element_Check (element )) {
11361138 PyErr_Format (
11371139 PyExc_TypeError ,
11381140 "expected an Element, not \"%.200s\"" ,
@@ -1184,7 +1186,7 @@ _elementtree_Element_find_impl(ElementObject *self, PyObject *path,
11841186 for (i = 0 ; i < self -> extra -> length ; i ++ ) {
11851187 PyObject * item = self -> extra -> children [i ];
11861188 int rc ;
1187- if (!Element_CheckExact (item ))
1189+ if (!Element_Check (item ))
11881190 continue ;
11891191 Py_INCREF (item );
11901192 rc = PyObject_RichCompareBool (((ElementObject * )item )-> tag , path , Py_EQ );
@@ -1229,14 +1231,14 @@ _elementtree_Element_findtext_impl(ElementObject *self, PyObject *path,
12291231 }
12301232
12311233 for (i = 0 ; i < self -> extra -> length ; i ++ ) {
1232- ElementObject * item = ( ElementObject * ) self -> extra -> children [i ];
1234+ PyObject * item = self -> extra -> children [i ];
12331235 int rc ;
1234- if (!Element_CheckExact (item ))
1236+ if (!Element_Check (item ))
12351237 continue ;
12361238 Py_INCREF (item );
1237- rc = PyObject_RichCompareBool (item -> tag , path , Py_EQ );
1239+ rc = PyObject_RichCompareBool ((( ElementObject * ) item ) -> tag , path , Py_EQ );
12381240 if (rc > 0 ) {
1239- PyObject * text = element_get_text (item );
1241+ PyObject * text = element_get_text (( ElementObject * ) item );
12401242 if (text == Py_None ) {
12411243 Py_DECREF (item );
12421244 return PyUnicode_New (0 , 0 );
@@ -1269,13 +1271,12 @@ _elementtree_Element_findall_impl(ElementObject *self, PyObject *path,
12691271{
12701272 Py_ssize_t i ;
12711273 PyObject * out ;
1272- PyObject * tag = path ;
12731274 elementtreestate * st = ET_STATE_GLOBAL ;
12741275
1275- if (checkpath (tag ) || namespaces != Py_None ) {
1276+ if (checkpath (path ) || namespaces != Py_None ) {
12761277 _Py_IDENTIFIER (findall );
12771278 return _PyObject_CallMethodIdObjArgs (
1278- st -> elementpath_obj , & PyId_findall , self , tag , namespaces , NULL
1279+ st -> elementpath_obj , & PyId_findall , self , path , namespaces , NULL
12791280 );
12801281 }
12811282
@@ -1289,10 +1290,10 @@ _elementtree_Element_findall_impl(ElementObject *self, PyObject *path,
12891290 for (i = 0 ; i < self -> extra -> length ; i ++ ) {
12901291 PyObject * item = self -> extra -> children [i ];
12911292 int rc ;
1292- if (!Element_CheckExact (item ))
1293+ if (!Element_Check (item ))
12931294 continue ;
12941295 Py_INCREF (item );
1295- rc = PyObject_RichCompareBool (((ElementObject * )item )-> tag , tag , Py_EQ );
1296+ rc = PyObject_RichCompareBool (((ElementObject * )item )-> tag , path , Py_EQ );
12961297 if (rc != 0 && (rc < 0 || PyList_Append (out , item ) < 0 )) {
12971298 Py_DECREF (item );
12981299 Py_DECREF (out );
@@ -2173,7 +2174,7 @@ elementiter_next(ElementIterObject *it)
21732174 continue ;
21742175 }
21752176
2176- if (!PyObject_TypeCheck (extra -> children [child_index ], & Element_Type )) {
2177+ if (!Element_Check (extra -> children [child_index ])) {
21772178 PyErr_Format (PyExc_AttributeError ,
21782179 "'%.100s' object has no attribute 'iter'" ,
21792180 Py_TYPE (extra -> children [child_index ])-> tp_name );
0 commit comments