Skip to content

Commit

Permalink
fixed __cause__ on overload bind failure and array conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
lostmsu committed Apr 11, 2021
1 parent d068f36 commit 4c76f15
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/runtime/converter.cs
Expand Up @@ -817,9 +817,14 @@ private static bool ToPrimitive(IntPtr value, Type obType, out object result, bo

private static void SetConversionError(IntPtr value, Type target)
{
// PyObject_Repr might clear the error
Runtime.PyErr_Fetch(out var causeType, out var causeVal, out var causeTrace);

IntPtr ob = Runtime.PyObject_Repr(value);
string src = Runtime.GetManagedString(ob);
Runtime.XDecref(ob);

Runtime.PyErr_Restore(causeType.Steal(), causeVal.Steal(), causeTrace.Steal());
Exceptions.RaiseTypeError($"Cannot convert {src} to {target}");
}

Expand Down
2 changes: 2 additions & 0 deletions src/runtime/methodbinder.cs
Expand Up @@ -926,7 +926,9 @@ internal virtual IntPtr Invoke(IntPtr inst, IntPtr args, IntPtr kw, MethodBase i
}

value.Append(": ");
Runtime.PyErr_Fetch(out var errType, out var errVal, out var errTrace);
AppendArgumentTypes(to: value, args);
Runtime.PyErr_Restore(errType.StealNullable(), errVal.StealNullable(), errTrace.StealNullable());
Exceptions.RaiseTypeError(value.ToString());
return IntPtr.Zero;
}
Expand Down

0 comments on commit 4c76f15

Please sign in to comment.