예제 #1
0
        public override IAnalysisSet LookupName(string name)
        {
            var res = _eval.LookupAnalysisSetByName(_node, name);

            TypingModuleInfo typing;

            if (!_unit.ProjectState.Modules.TryGetImportedModule("typing", out var typingMod) ||
                (typing = typingMod.AnalysisModule as TypingModuleInfo) == null)
            {
                // User has not imported our special typing module, so return the original value
                return(res);
            }

            if (!res.Any(v => v.PythonType?.DeclaringModule?.Name == "typing"))
            {
                // Value was not imported from typing, so return it
                return(res);
            }

            var realRes = typing.GetTypingMember(_node, _unit, name);

            if (!realRes.Any())
            {
                return(res);
            }
            return(realRes);
        }
        private static IAnalysisSet EvaluateName(ExpressionEvaluator ee, Node node)
        {
            var n   = (NameExpression)node;
            var res = ee.LookupAnalysisSetByName(node, n.Name);

            foreach (var value in res)
            {
                value.AddReference(node, ee._unit);
            }
            return(res);
        }
예제 #3
0
        public override IAnalysisSet LookupName(string name)
        {
            var res = _eval.LookupAnalysisSetByName(_node, name);

            if (res.Any())
            {
                return(res);
            }

            return(null);
        }
        private IAnalysisSet FinalizeNames(IAnalysisSet types)
        {
            var res = types;

            if (res.Split(out IReadOnlyList <ConstantInfo> constants, out res))
            {
                res = res.UnionAll(
                    constants.Select(c => {
                    if (c.Value == null)
                    {
                        return(_unit.State.ClassInfos[BuiltinTypeId.NoneType]);
                    }
                    var n = c.GetConstantValueAsString();
                    if (!string.IsNullOrEmpty(n))
                    {
                        return(_eval.LookupAnalysisSetByName(_node, n, addDependency: true).GetInstanceType());
                    }
                    return(c);
                })
                    );
            }

            return(res);
        }