示例#1
0
        public static IPythonPropertyType Property(string name, IPythonModule declaringModule, IPythonType declaringType, IMember returnValue)
        {
            var prop = new PythonPropertyType(name, declaringModule, declaringType, false, LocationInfo.Empty);
            var o    = new PythonFunctionOverload(prop.Name, declaringModule, LocationInfo.Empty);

            o.AddReturnValue(returnValue);
            prop.AddOverload(o);
            return(prop);
        }
        public static IPythonFunctionType Function(string name, IPythonModule declaringModule, IPythonType declaringType, string documentation, IMember returnValue)
        {
            var prop = new PythonFunctionType(name, declaringModule, declaringType, documentation, LocationInfo.Empty);
            var o    = new PythonFunctionOverload(prop.Name, declaringModule, _ => LocationInfo.Empty);

            o.AddReturnValue(returnValue);
            prop.AddOverload(o);
            return(prop);
        }
        public static IMember __iter__(IPythonInterpreter interpreter, BuiltinTypeId contentTypeId)
        {
            var fn = new PythonFunctionType(@"__iter__", interpreter.ModuleResolution.BuiltinsModule, null, string.Empty, LocationInfo.Empty);
            var o  = new PythonFunctionOverload(fn.Name, interpreter.ModuleResolution.BuiltinsModule, _ => fn.Location);

            o.AddReturnValue(PythonTypeIterator.FromTypeId(interpreter, contentTypeId));
            fn.AddOverload(o);
            return(fn);
        }
示例#4
0
        public override bool Walk(ReturnStatement node)
        {
            var value = Eval.GetValueFromExpression(node.Expression);

            if (value != null)
            {
                _overload.AddReturnValue(value);
            }
            return(true); // We want to evaluate all code so all private variables in __new__ get defined
        }
示例#5
0
        public override async Task <bool> WalkAsync(ReturnStatement node, CancellationToken cancellationToken = default)
        {
            var value = await Eval.GetValueFromExpressionAsync(node.Expression, cancellationToken);

            if (value != null)
            {
                _overload.AddReturnValue(value);
            }
            return(true); // We want to evaluate all code so all private variables in __new__ get defined
        }
示例#6
0
        public static IPythonFunctionType Function(string name, IPythonModule declaringModule, string documentation, IMember returnValue)
        {
            var location = new Location(declaringModule);
            var prop     = PythonFunctionType.Specialize(name, declaringModule, documentation);
            var o        = new PythonFunctionOverload(prop.Name, location);

            o.AddReturnValue(returnValue);
            prop.AddOverload(o);
            return(prop);
        }
        public override bool Walk(ReturnStatement node)
        {
            var value = Eval.GetValueFromExpression(node.Expression);

            if (value != null)
            {
                // although technically legal, __init__ in a constructor should not have a not-none return value
                if (_function.IsDunderInit() && !value.IsOfType(BuiltinTypeId.None))
                {
                    Eval.ReportDiagnostics(Module.Uri, new DiagnosticsEntry(
                                               Resources.ReturnInInit,
                                               node.GetLocation(Eval).Span,
                                               ErrorCodes.ReturnInInit,
                                               Severity.Warning,
                                               DiagnosticSource.Analysis));
                }

                _overload.AddReturnValue(value);
            }
            return(true); // We want to evaluate all code so all private variables in __new__ get defined
        }