Skip to content

Commit 650ac77

Browse files
committed
fixed __cause__ on overload bind failure and array conversion
1 parent 0775458 commit 650ac77

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/runtime/converter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
814814

815815
private static void SetConversionError(IntPtr value, Type target)
816816
{
817+
// PyObject_Repr might clear the error
818+
Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace);
819+
817820
IntPtr ob = Runtime.PyObject_Repr(value);
818821
string src = Runtime.GetManagedString(ob);
819822
Runtime.XDecref(ob);
823+
824+
Runtime.PyErr_Restore(causeType, causeVal, causeTrace);
820825
Exceptions.RaiseTypeError($"Cannot convert {src} to {target}");
821826
}
822827

src/runtime/methodbinder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
926926
}
927927

928928
value.Append(": ");
929+
Runtime.PyErr_Fetch(out var errType, out var errVal, out var errTrace);
929930
AppendArgumentTypes(to: value, args);
931+
Runtime.PyErr_Restore(errType, errVal, errTrace);
930932
Exceptions.RaiseTypeError(value.ToString());
931933
return IntPtr.Zero;
932934
}

0 commit comments

Comments
 (0)