Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Commit

Permalink
unfilter __all__ (#708)
Browse files Browse the repository at this point in the history
Fixes #642.
Reopens #619.
Related #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 committed Mar 6, 2019
1 parent f43cc9f commit 1072de6
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 @@ internal PythonModule(ModuleCreationOptions creationOptions, IServiceContainer s
#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 1072de6

Please sign in to comment.