Skip to content

Commit 4c76f15

Browse files
committed
fixed __cause__ on overload bind failure and array conversion
1 parent d068f36 commit 4c76f15

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/runtime/converter.cs

+5
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo
817817

818818
private static void SetConversionError(IntPtr value, Type target)
819819
{
820+
// PyObject_Repr might clear the error
821+
Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace);
822+
820823
IntPtr ob = Runtime.PyObject_Repr(value);
821824
string src = Runtime.GetManagedString(ob);
822825
Runtime.XDecref(ob);
826+
827+
Runtime.PyErr_Restore(causeType.Steal(), causeVal.Steal(), causeTrace.Steal());
823828
Exceptions.RaiseTypeError($"Cannot convert {src} to {target}");
824829
}
825830

src/runtime/methodbinder.cs

+2
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.StealNullable(), errVal.StealNullable(), errTrace.StealNullable());
930932
Exceptions.RaiseTypeError(value.ToString());
931933
return IntPtr.Zero;
932934
}

0 commit comments

Comments
 (0)