/// <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); }