private static bool BuiltinModuleContainsMember(IModuleContext context, string name, IPythonModule interpModule) { var mem = interpModule.GetMember(context, name); if (mem != null) { if (IsExcludedBuiltin(interpModule, mem)) { // if a module imports a builtin and exposes it don't report it for purposes of adding imports return(false); } IPythonMultipleMembers multiMem = mem as IPythonMultipleMembers; if (multiMem != null) { foreach (var innerMem in multiMem.Members) { if (IsExcludedBuiltin(interpModule, innerMem)) { // if something non-excludable aliased w/ something excluable we probably // only care about the excluable (for example a module and None - timeit.py // does this in the std lib) return(false); } } } return(true); } return(false); }
public MultipleMemberView(IModuleContext context, string name, IPythonMultipleMembers member) : base(context, name, member) { _members = member; }
internal AnalysisValue GetAnalysisValueFromObjects(object attr) { if (attr == null) { return(_noneInst); } var attrType = (attr != null) ? attr.GetType() : typeof(NoneType); if (attr is IPythonType) { return(GetBuiltinType((IPythonType)attr)); } else if (attr is IPythonFunction) { var bf = (IPythonFunction)attr; return(GetCached(attr, () => new BuiltinFunctionInfo(bf, this)) ?? _noneInst); } else if (attr is IPythonMethodDescriptor) { return(GetCached(attr, () => { var md = (IPythonMethodDescriptor)attr; if (md.IsBound) { return new BuiltinFunctionInfo(md.Function, this); } else { return new BuiltinMethodInfo(md, this); } }) ?? _noneInst); } else if (attr is IBuiltinProperty) { return(GetCached(attr, () => new BuiltinPropertyInfo((IBuiltinProperty)attr, this)) ?? _noneInst); } else if (attr is IPythonModule) { return(_modules.GetBuiltinModule((IPythonModule)attr)); } else if (attr is IPythonEvent) { return(GetCached(attr, () => new BuiltinEventInfo((IPythonEvent)attr, this)) ?? _noneInst); } else if (attr is IPythonConstant) { return(GetConstant((IPythonConstant)attr).First()); } else if (attrType == typeof(bool) || attrType == typeof(int) || attrType == typeof(Complex) || attrType == typeof(string) || attrType == typeof(long) || attrType == typeof(double) || attr == null) { return(GetConstant(attr).First()); } else if (attr is IMemberContainer) { return(GetCached(attr, () => new ReflectedNamespace((IMemberContainer)attr, this))); } else if (attr is IPythonMultipleMembers) { IPythonMultipleMembers multMembers = (IPythonMultipleMembers)attr; var members = multMembers.Members; return(GetCached(attr, () => MultipleMemberInfo.Create(members.Select(GetAnalysisValueFromObjects)).FirstOrDefault() ?? ClassInfos[BuiltinTypeId.NoneType].Instance )); } else { var pyAttrType = GetTypeFromObject(attr); Debug.Assert(pyAttrType != null); return(GetBuiltinType(pyAttrType).Instance); } }
internal Namespace GetNamespaceFromObjects(object attr) { var attrType = (attr != null) ? attr.GetType() : typeof(NoneType); if (attr is IPythonType) { return(GetBuiltinType((IPythonType)attr)); } else if (attr is IPythonFunction) { var bf = (IPythonFunction)attr; return(GetCached(attr, () => new BuiltinFunctionInfo(bf, this))); } else if (attr is IPythonMethodDescriptor) { return(GetCached(attr, () => new BuiltinMethodInfo((IPythonMethodDescriptor)attr, this))); } else if (attr is IBuiltinProperty) { return(GetCached(attr, () => new BuiltinPropertyInfo((IBuiltinProperty)attr, this))); } else if (attr is IPythonModule) { return(GetCached(attr, () => new BuiltinModule((IPythonModule)attr, this))); } else if (attr is IPythonEvent) { return(GetCached(attr, () => new BuiltinEventInfo((IPythonEvent)attr, this))); } else if (attr is IPythonConstant) { return(GetConstant((IPythonConstant)attr).First()); } else if (attrType == typeof(bool) || attrType == typeof(int) || attrType == typeof(Complex) || attrType == typeof(string) || attrType == typeof(long) || attrType == typeof(double) || attr == null) { return(GetConstant(attr).First()); } else if (attr is IMemberContainer) { return(GetCached(attr, () => new ReflectedNamespace((IMemberContainer)attr, this))); } else if (attr is IPythonMultipleMembers) { IPythonMultipleMembers multMembers = (IPythonMultipleMembers)attr; var members = multMembers.Members; return(GetCached(attr, () => { Namespace[] nses = new Namespace[members.Count]; for (int i = 0; i < members.Count; i++) { nses[i] = GetNamespaceFromObjects(members[i]); } return new MultipleMemberInfo(nses); } )); } else { var pyAattrType = GetTypeFromObject(attr); return(GetBuiltinType(pyAattrType).Instance); } }