Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
unfilter __all__ (microsoft#708)
Browse files Browse the repository at this point in the history
Fixes microsoft#642.
Reopens microsoft#619.
Related microsoft#620.

This unfilters exported variables except for things which are directly from typing or are imported modules, though even that may be too strong. The old LS didn't look at __all__ whatsoever, so maybe all of these should be allowed to come through; you tell me.
  • Loading branch information
jakebailey authored Mar 6, 2019
1 parent 0869eb3 commit 6c2246a
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions src/Analysis/Ast/Impl/Modules/PythonModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,11 @@ public virtual string Documentation {
#region IMemberContainer
public virtual IMember GetMember(string name) => Analysis.GlobalScope.Variables[name]?.Value;
public virtual IEnumerable<string> GetMemberNames() {
// Try __all__ since it contains exported members
var all = Analysis.GlobalScope.Variables["__all__"];
if (all?.Value is IPythonCollection collection) {
return collection.Contents
.OfType<IPythonConstant>()
.Select(c => c.GetString())
.Where(s => !string.IsNullOrEmpty(s));
}
// TODO: Filter __all__. See: https://github.com/Microsoft/python-language-server/issues/620

// __all__ is not declared. Try filtering by origin:
// drop imported modules and generics.
// drop imported modules and typing.
return Analysis.GlobalScope.Variables
.Where(v => v.Value?.MemberType != PythonMemberType.Generic
&& !(v.Value?.GetPythonType() is PythonModule)
.Where(v => !(v.Value?.GetPythonType() is PythonModule)
&& !(v.Value?.GetPythonType().DeclaringModule is TypingModule && !(this is TypingModule)))
.Select(v => v.Name);
}
Expand Down

0 comments on commit 6c2246a

Please sign in to comment.