/// <summary> /// Looks up __init__ avoiding calls to __getattribute__ and handling both /// new-style and old-style classes in the MRO. /// </summary> private static object GetInitMethod(CodeContext /*!*/ context, PythonType dt, object newObject) { // __init__ is never searched for w/ __getattribute__ for (int i = 0; i < dt.ResolutionOrder.Count; i++) { PythonType cdt = dt.ResolutionOrder[i]; PythonTypeSlot dts; object value; if (cdt.IsOldClass) { if (PythonOps.ToPythonType(cdt) is OldClass oc && oc.TryGetBoundCustomMember(context, "__init__", out value)) { return(oc.GetOldStyleDescriptor(context, value, newObject, oc)); } // fall through to new-style only case. We might accidently // detect old-style if the user imports a IronPython.NewTypes // type. } if (cdt.TryLookupSlot(context, "__init__", out dts) && dts.TryGetValue(context, newObject, dt, out value)) { return(value); } } return(null); }
private static bool LookupValue(PythonType dt, object instance, string name, out object value) { if (dt.TryLookupSlot(DefaultContext.Default, name, out PythonTypeSlot dts) && dts.TryGetValue(DefaultContext.Default, instance, dt, out value)) { return(true); } value = null; return(false); }
/// <summary> /// Looks up __init__ avoiding calls to __getattribute__ and handling both /// new-style and old-style classes in the MRO. /// </summary> private static object GetInitMethod(CodeContext /*!*/ context, PythonType dt, object newObject) { // __init__ is never searched for w/ __getattribute__ for (int i = 0; i < dt.ResolutionOrder.Count; i++) { PythonType cdt = dt.ResolutionOrder[i]; PythonTypeSlot dts; object value; if (cdt.TryLookupSlot(context, "__init__", out dts) && dts.TryGetValue(context, newObject, dt, out value)) { return(value); } } return(null); }