with self.assertRaises(Exception):
_testinternalcapi.verify_stateless_code(func)
+ def test_code_richcompare_raise_exception(self):
+ class BadStr(str):
+ def __eq__(self, _):
+ raise RuntimeError("Poison!")
+
+ __hash__ = str.__hash__
+
+ c1 = compile("pass", "test", "exec")
+ c2 = c1.replace(co_name=BadStr("poison"))
+ c3 = compile("pass", "poison", "exec")
+ with self.assertRaises(RuntimeError):
+ c2 == c3
def isinterned(s):
return s is sys.intern(('_' + s + '_')[1:-1])
cp = (PyCodeObject *)other;
eq = PyObject_RichCompareBool(co->co_name, cp->co_name, Py_EQ);
- if (!eq) goto unequal;
+ if (eq <= 0) goto unequal;
eq = co->co_argcount == cp->co_argcount;
if (!eq) goto unequal;
eq = co->co_posonlyargcount == cp->co_posonlyargcount;