private PyObject_IsSubclass ( IntPtr ob, IntPtr type ) : int | ||
ob | IntPtr | |
type | IntPtr | |
Résultat | int |
//==================================================================== // helper methods for raising warnings //==================================================================== /// <summary> /// Alias for Python's warnings.warn() function. /// </summary> public static void warn(string message, IntPtr exception, int stacklevel) { if (exception == IntPtr.Zero || (Runtime.PyObject_IsSubclass(exception, Exceptions.Warning) != 1)) { Exceptions.RaiseTypeError("Invalid exception"); } Runtime.XIncref(warnings_module); IntPtr warn = Runtime.PyObject_GetAttrString(warnings_module, "warn"); Runtime.XDecref(warnings_module); Exceptions.ErrorCheck(warn); IntPtr args = Runtime.PyTuple_New(3); IntPtr msg = Runtime.PyString_FromString(message); Runtime.XIncref(exception); // PyTuple_SetItem steals a reference IntPtr level = Runtime.PyInt_FromInt32(stacklevel); Runtime.PyTuple_SetItem(args, 0, msg); Runtime.PyTuple_SetItem(args, 1, exception); Runtime.PyTuple_SetItem(args, 2, level); IntPtr result = Runtime.PyObject_CallObject(warn, args); Exceptions.ErrorCheck(result); Runtime.XDecref(warn); Runtime.XDecref(result); Runtime.XDecref(args); }
/// <summary> /// IsSubclass Method /// </summary> /// <remarks> /// Return true if the object is identical to or derived from the /// given Python type or class. This method always succeeds. /// </remarks> public bool IsSubclass(PyObject typeOrClass) { int r = Runtime.PyObject_IsSubclass(obj, typeOrClass.obj); if (r < 0) { Runtime.PyErr_Clear(); return(false); } return(r != 0); }
/// <summary> /// IsSubclass Method /// </summary> /// <remarks> /// Return true if the object is identical to or derived from the /// given Python type or class. This method always succeeds. /// </remarks> public bool IsSubclass(PyObject typeOrClass) { if (typeOrClass == null) { throw new ArgumentNullException(nameof(typeOrClass)); } int r = Runtime.PyObject_IsSubclass(obj, typeOrClass.obj); if (r < 0) { Runtime.PyErr_Clear(); return(false); } return(r != 0); }
internal bool IsSubclass(BorrowedReference typeOrClass) { if (typeOrClass.IsNull) { throw new ArgumentNullException(nameof(typeOrClass)); } int r = Runtime.PyObject_IsSubclass(Reference, typeOrClass); if (r < 0) { Runtime.PyErr_Clear(); return(false); } return(r != 0); }
//==================================================================== // helper methods for raising warnings //==================================================================== /// <summary> /// Alias for Python's warnings.warn() function. /// </summary> public static void warn(string message, BorrowedReference exception, int stacklevel) { if (exception == null || (Runtime.PyObject_IsSubclass(exception, Exceptions.Warning) != 1)) { Exceptions.RaiseTypeError("Invalid exception"); } using var warn = Runtime.PyObject_GetAttrString(warnings_module.obj, "warn"); Exceptions.ErrorCheck(warn.Borrow()); using var argsTemp = Runtime.PyTuple_New(3); BorrowedReference args = argsTemp.BorrowOrThrow(); using var msg = Runtime.PyString_FromString(message); Runtime.PyTuple_SetItem(args, 0, msg.StealOrThrow()); Runtime.PyTuple_SetItem(args, 1, exception); using var level = Runtime.PyInt_FromInt32(stacklevel); Runtime.PyTuple_SetItem(args, 2, level.StealOrThrow()); using var result = Runtime.PyObject_CallObject(warn.Borrow(), args); Exceptions.ErrorCheck(result.Borrow()); }