private void GetMethodType(FunctionDefinition node, out bool classmethod, out bool staticmethod)
        {
            classmethod  = false;
            staticmethod = false;

            if (node.IsLambda)
            {
                staticmethod = true;
                return;
            }

            var classmethodObj  = _scope.Interpreter.GetBuiltinType(BuiltinTypeId.ClassMethod);
            var staticmethodObj = _scope.Interpreter.GetBuiltinType(BuiltinTypeId.StaticMethod);

            foreach (var d in (Target.Decorators?.Decorators).MaybeEnumerate().ExcludeDefault())
            {
                var m = _scope.GetValueFromExpression(d);
                if (m == classmethodObj)
                {
                    classmethod = true;
                }
                else if (m == staticmethodObj)
                {
                    staticmethod = true;
                }
            }
        }
Esempio n. 2
0
        public override bool Walk(AssignmentStatement node)
        {
            var value = _scope.GetValueFromExpression(node.Right);

            if ((value == null || value.MemberType == PythonMemberType.Unknown) && WarnAboutUndefinedValues)
            {
                _log?.Log(TraceLevel.Warning, "UndefinedValue", node.Right.ToCodeString(_ast).Trim());
            }

            foreach (var ne in node.Left.OfType <NameExpression>())
            {
                _scope.SetInScope(ne.Name, Clone(value));
            }

            return(base.Walk(node));
        }
Esempio n. 3
0
        public override bool Walk(AssignmentStatement node)
        {
            var value = _scope.GetValueFromExpression(node.Right);

            foreach (var ne in node.Left.OfType <NameExpression>())
            {
                _scope.SetInScope(ne.Name, Clone(value));
            }

            return(base.Walk(node));
        }
Esempio n. 4
0
        public override bool Walk(AssignmentStatement node)
        {
            var value = _scope.GetValueFromExpression(node.Right);

            if ((value == null || value.MemberType == PythonMemberType.Unknown) && WarnAboutUndefinedValues)
            {
                _log?.Log(TraceLevel.Warning, "UndefinedValue", node.Right.ToCodeString(_ast).Trim());
            }
            if ((value as IPythonConstant)?.Type?.TypeId == BuiltinTypeId.Ellipsis)
            {
                value = _unknownType;
            }

            foreach (var expr in node.Left.OfType <ExpressionWithAnnotation>())
            {
                if (expr.Expression is NameExpression ne)
                {
                    var annType = _scope.GetValueFromExpression(expr.Annotation) as IPythonType;
                    if (annType != null)
                    {
                        _scope.SetInScope(ne.Name, new AstPythonConstant(annType, GetLoc(expr.Expression)));
                    }
                    else
                    {
                        _scope.SetInScope(ne.Name, _unknownType);
                    }
                }
            }

            foreach (var ne in node.Left.OfType <NameExpression>())
            {
                _scope.SetInScope(ne.Name, Clone(value));
            }

            return(base.Walk(node));
        }