public object Call(object[] args, string[] names) { object newMethod, newObject = null; if (TryGetAttr(DefaultContext.Default, SymbolTable.NewInst, out newMethod)) { IFancyCallable ifc = newMethod as IFancyCallable; if (ifc != null) { newObject = ifc.Call(PrependThis(args), names); } else { throw Ops.TypeError("{0} object is not callable", Ops.GetDynamicType(newMethod).__name__); } } else { Debug.Assert(names.Length != 0); throw Ops.TypeError("default __new__ takes no parameters"); } if (newObject == null) { return(null); } InvokeInit(newObject, args, names); return(newObject); }
public void InvokeInit(object inst, object[] args, string[] names) { if (Ops.GetDynamicType(inst).IsSubclassOf(this)) { object initFunc; if (TryGetAttr(DefaultContext.Default, inst, SymbolTable.Init, out initFunc)) { IFancyCallable ifc = initFunc as IFancyCallable; if (ifc != null) { ifc.Call(args, names); } else { throw Ops.TypeError("__init__ cannot be called with keyword arguments"); } } } }