From 8adef2c7f6b314e4fd0a4047b2e19828643ce105 Mon Sep 17 00:00:00 2001 From: Boris Staletic Date: Mon, 23 Nov 2020 19:02:25 +0000 Subject: [PATCH] fix: workaround for #2682 and #2422 by simply clearing the TypeError (#2685) --- 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 11c61a441..c428e3f13 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1870,7 +1870,14 @@ private: #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