From ecd4935f5abeb3e621a41006d94dce6213c30174 Mon Sep 17 00:00:00 2001 From: Shantanu Date: Sun, 15 Nov 2026 07:33:19 +0000 Subject: [PATCH] [mypyc] Clear conversion errors before formatting a TypeError A failed conversion can leave an exception set. Clear it before looking up attributes to describe the actual type, as required by the debug C API checks. --- mypyc/lib-rt/exc_ops.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mypyc/lib-rt/exc_ops.c b/mypyc/lib-rt/exc_ops.c index c5ec2b6386e8..842c966ed133 100644 --- a/mypyc/lib-rt/exc_ops.c +++ b/mypyc/lib-rt/exc_ops.c @@ -271,6 +271,7 @@ static PyObject *CPy_FormatTypeName(PyObject *value) { CPy_NOINLINE void CPy_TypeError(const char *expected, PyObject *value) { + PyErr_Clear(); PyObject *out = CPy_FormatTypeName(value); if (out) { PyErr_Format(PyExc_TypeError, "%s object expected; got %U", expected, out);