diff --git a/src/runtime/Types/ClassBase.cs b/src/runtime/Types/ClassBase.cs index 19d8abf32..525be8a35 100644 --- a/src/runtime/Types/ClassBase.cs +++ b/src/runtime/Types/ClassBase.cs @@ -348,7 +348,8 @@ public static NewReference tp_str(BorrowedReference ob) } catch (Exception e) { - if (e.InnerException != null) + // a PythonException's InnerException is the Python error's __cause__, not a wrapper + if (e is not PythonException && e.InnerException != null) { e = e.InnerException; } diff --git a/tests/test_repr.py b/tests/test_repr.py index 1fce44228..26694a034 100644 --- a/tests/test_repr.py +++ b/tests/test_repr.py @@ -77,6 +77,48 @@ def test_tostring_throws(): ob = ReprTest.ThrowingToString() assert "