Skip to content

Commit e79f041

Browse files
committed
method binding failure now supports non-Python exception causes
1 parent 2cd3f61 commit e79f041

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/runtime/methodbinder.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,13 @@ public MatchedMethod(int kwargsMatched, int defaultsNeeded, object[] margs, int
341341

342342
private readonly struct MismatchedMethod
343343
{
344-
public MismatchedMethod(PythonException exception, MethodBase mb)
344+
public MismatchedMethod(Exception exception, MethodBase mb)
345345
{
346346
Exception = exception;
347347
Method = mb;
348348
}
349349

350-
public PythonException Exception { get; }
350+
public Exception Exception { get; }
351351
public MethodBase Method { get; }
352352
}
353353

@@ -438,8 +438,8 @@ internal Binding Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, Meth
438438
outs: out outs);
439439
if (margs == null)
440440
{
441-
mismatchedMethods.Add(new MismatchedMethod(PythonException.FetchCurrentRaw(), mi));
442-
Exceptions.Clear();
441+
var mismatchCause = PythonException.FetchCurrent();
442+
mismatchedMethods.Add(new MismatchedMethod(mismatchCause, mi));
443443
continue;
444444
}
445445
if (isOperator)

src/runtime/pythonexception.cs

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ internal static PythonException FetchCurrentRaw()
9494
}
9595
}
9696

97+
internal static Exception FetchCurrent()
98+
=> FetchCurrentOrNull(out _)
99+
?? throw new InvalidOperationException("No exception is set");
100+
97101
private static ExceptionDispatchInfo? TryGetDispatchInfo(BorrowedReference exception)
98102
{
99103
if (exception.IsNull) return null;

0 commit comments

Comments
 (0)