Example #1
0
            public virtual Delegate MakeBindingResult()
            {
                int version = _type.Version;

                PythonTypeSlot init, newInst;

                _type.TryResolveSlot(_context, "__new__", out newInst);
                _type.TryResolveSlot(_context, "__init__", out init);

                Delegate newDlg;

                if (newInst == InstanceOps.New)
                {
                    if (_genTypeArgs.Length > 0 && init == InstanceOps.Init)
                    {
                        // new needs to report an error, we don't optimize for the error case.
                        return(null);
                    }
                    newDlg = GetOrCreateFastNew();
                }
                else if (newInst.GetType() == typeof(staticmethod) && ((staticmethod)newInst)._func is PythonFunction)
                {
                    // need an extra argument to pass the class to __new__
                    newDlg = GetNewSiteDelegate(_binder.Context.Invoke(_binder.Signature.InsertArgument(Argument.Simple)), ((staticmethod)newInst)._func);
                }
                else
                {
                    // odd slot in __new__, we don't handle this.
                    newDlg = null;
                }

                if (newDlg == null)
                {
                    // can't optimize this method because we have no fast-new
                    return(null);
                }

                return(MakeDelegate(version, newDlg, _type.GetLateBoundInitBinder(_binder.Signature)));
            }