diff --git a/src/calibre/gui2/tweak_book/editor/syntax/html.c b/src/calibre/gui2/tweak_book/editor/syntax/html.c index 00402aa14e..9367763b7b 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/html.c +++ b/src/calibre/gui2/tweak_book/editor/syntax/html.c @@ -68,6 +68,7 @@ html_Tag_copy(html_Tag *self, PyObject *args, PyObject *kwargs) { static PyObject * html_Tag_compare(html_Tag *a, html_Tag *b, int op) { + if (!PyObject_TypeCheck(a, &html_TagType) || !PyObject_TypeCheck(b, &html_TagType)) Py_RETURN_FALSE; switch (op) { case Py_EQ: if (COMPARE(name, Py_EQ) && COMPARE(lang, Py_EQ)) Py_RETURN_TRUE; @@ -277,6 +278,7 @@ end: static PyObject * html_State_compare(html_State *a, html_State *b, int op) { + if (!PyObject_TypeCheck(a, &html_StateType) || !PyObject_TypeCheck(b, &html_StateType)) Py_RETURN_FALSE; switch (op) { case Py_EQ: if (COMPARE(parse, Py_EQ) && COMPARE(sub_parser_state, Py_EQ) && COMPARE(tag_being_defined, Py_EQ) && COMPARE(attribute_name, Py_EQ) && COMPARE(tags, Py_EQ)) Py_RETURN_TRUE; diff --git a/src/calibre/gui2/tweak_book/editor/syntax/html.py b/src/calibre/gui2/tweak_book/editor/syntax/html.py index 72682ce770..a1a03d23f8 100644 --- a/src/calibre/gui2/tweak_book/editor/syntax/html.py +++ b/src/calibre/gui2/tweak_book/editor/syntax/html.py @@ -86,7 +86,10 @@ else: self.lang = lang def __eq__(self, other): - return self.name == other.name and self.lang == other.lang + try: + return self.name == other.name and self.lang == other.lang + except AttributeError: + return False def copy(self): ans = Tag(self.name, self.bold, self.italic, self.lang) @@ -117,13 +120,16 @@ else: return ans def __eq__(self, other): - return ( - self.parse == other.parse and - self.sub_parser_state == other.sub_parser_state and - self.tag_being_defined == other.tag_being_defined and - self.attribute_name == other.attribute_name and - self.tags == other.tags - ) + try: + return ( + self.parse == other.parse and + self.sub_parser_state == other.sub_parser_state and + self.tag_being_defined == other.tag_being_defined and + self.attribute_name == other.attribute_name and + self.tags == other.tags + ) + except AttributeError: + return False def __ne__(self, other): return not self.__eq__(other)