From 2b48df58fba967c24a1b24aa5529d29fb8e8f7a4 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Fri, 20 Nov 2020 11:40:04 +0100 Subject: [PATCH] Workaround for #2682 and #2422 by simply clearing the TypeError --- include/pybind11/cast.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 11c61a441f..c428e3f13a 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1870,7 +1870,14 @@ struct arg_v : arg { #if !defined(NDEBUG) , type(type_id()) #endif - { } + { + // Workaround! See: + // https://github.com/pybind/pybind11/issues/2336 + // https://github.com/pybind/pybind11/pull/2685#issuecomment-731286700 + if (PyErr_Occurred()) { + PyErr_Clear(); + } + } public: /// Direct construction with name, default, and description