Skip to content

Commit b480a0c

Browse files
committed
added Runtime.PyType_IsSameAsOrSubtype
1 parent d14105d commit b480a0c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/runtime/interop.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ public static int Size(IntPtr pyType)
184184
private static bool IsException(IntPtr pyObject)
185185
{
186186
var type = Runtime.PyObject_TYPE(pyObject);
187-
return Runtime.PyObjectType_TypeCheck(type, Exceptions.BaseException)
188-
|| Runtime.PyObjectType_TypeCheck(type, Runtime.PyTypeType)
187+
return Runtime.PyType_IsSameAsOrSubtype(type, ofType: Exceptions.BaseException)
188+
|| Runtime.PyType_IsSameAsOrSubtype(type, ofType: Runtime.PyTypeType)
189189
&& Runtime.PyType_IsSubtype(pyObject, Exceptions.BaseException);
190190
}
191191
}

src/runtime/runtime.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,11 @@ internal static bool PyObject_TypeCheck(IntPtr ob, IntPtr tp)
17711771
return (t == tp) || PyType_IsSubtype(t, tp);
17721772
}
17731773

1774+
internal static bool PyType_IsSameAsOrSubtype(IntPtr type, IntPtr ofType)
1775+
{
1776+
return (type == ofType) || PyType_IsSubtype(type, ofType);
1777+
}
1778+
17741779
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
17751780
internal static extern IntPtr PyType_GenericNew(IntPtr type, IntPtr args, IntPtr kw);
17761781

0 commit comments

Comments
 (0)