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

Commit 47ceb5e

Browse files
author
Mikhail Arkhipov
authored
Fix __all__ handling (microsoft#908)
* Fix microsoft#668 (partial) * Tests * Revert "Tests" This reverts commit 7ffc9db. * Partial * Part 2 * Part 3 * Part 4 * Part 4 * Part 5 * Analysis tests * Tests * Tests * Basic test * Tests * Tests * Tests * Tests * Tests * Linked variables * Tests * Tests * Tests * Merge issues * Fix merge issue * Basic single file * Handle closed files * Closed files * Tests * Tests * Fix 454 * Remove references on analysis change * Rename * Rename non-user code * Linter * Ref fix * Member expressions * Linter improvements * Tests * Definitions only for LHS * Add test * Add null checks and tests * Null checks * Fix variable leak in expressions with comprehensions * Temp * Fix scope lookup + test * Handle virtual space * Better handle nested sequence expression assignments * More extensive handling of RHS sequences * PR feedback * Enable test * Test stability * Don't collect references to library modules * Handle virtual envs * PR feedback * null check * Remove references in all modules * Add test * Perf improvement * Null check in tests * Store span rather than node * Fix AST associations with locations * Handle null nodes * Temp * Add AST to nodes * Variable refs * Null ref * Merge issues * Handle import * * Undo debug * Merge issues * Better handle variable * Null check * Better handle nested variables without location * Fix rename test * Usings * Fix merge conflict * Fix __all__ processing * Undo temp change
1 parent ea30994 commit 47ceb5e

File tree

5 files changed

+8
-9
lines changed

5 files changed

+8
-9
lines changed

src/Analysis/Ast/Impl/Analyzer/AnalysisWalker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ public override bool Walk(ExpressionStatement node) {
6666
return false;
6767
case CallExpression callex when callex.Target is NameExpression nex && !string.IsNullOrEmpty(nex.Name):
6868
Eval.LookupNameInScopes(nex.Name)?.AddReference(Eval.GetLocationOfName(nex));
69-
return false;
69+
return true;
7070
case CallExpression callex when callex.Target is MemberExpression mex && !string.IsNullOrEmpty(mex.Name):
7171
var t = Eval.GetValueFromExpression(mex.Target)?.GetPythonType();
7272
t?.GetMember(mex.Name).AddReference(Eval.GetLocationOfName(mex));
73-
return false;
73+
return true;
7474
default:
7575
return base.Walk(node);
7676
}

src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.Collections.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IMember GetValueFromList(ListExpression expression) {
6060
var value = GetValueFromExpression(item) ?? UnknownType;
6161
contents.Add(value);
6262
}
63-
return PythonCollectionType.CreateList(Module.Interpreter, contents);
63+
return PythonCollectionType.CreateList(Module.Interpreter, contents, exact: true);
6464
}
6565

6666
public IMember GetValueFromDictionary(DictionaryExpression expression) {
@@ -70,7 +70,7 @@ public IMember GetValueFromDictionary(DictionaryExpression expression) {
7070
var value = GetValueFromExpression(item.SliceStop) ?? UnknownType;
7171
contents[key] = value;
7272
}
73-
return new PythonDictionary(Interpreter, contents);
73+
return new PythonDictionary(Interpreter, contents, exact: true);
7474
}
7575

7676
private IMember GetValueFromTuple(TupleExpression expression) {
@@ -79,7 +79,7 @@ private IMember GetValueFromTuple(TupleExpression expression) {
7979
var value = GetValueFromExpression(item) ?? UnknownType;
8080
contents.Add(value);
8181
}
82-
return PythonCollectionType.CreateTuple(Module.Interpreter, contents);
82+
return PythonCollectionType.CreateTuple(Module.Interpreter, contents, exact: true);
8383
}
8484

8585
public IMember GetValueFromSet(SetExpression expression) {
@@ -88,7 +88,7 @@ public IMember GetValueFromSet(SetExpression expression) {
8888
var value = GetValueFromExpression(item) ?? UnknownType;
8989
contents.Add(value);
9090
}
91-
return PythonCollectionType.CreateSet(Interpreter, contents);
91+
return PythonCollectionType.CreateSet(Interpreter, contents, exact: true);
9292
}
9393

9494
public IMember GetValueFromGenerator(GeneratorExpression expression) {

src/Analysis/Ast/Impl/Analyzer/ModuleWalker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ private void HandleAllAppendExtend(CallExpression node) {
106106
}
107107

108108
IPythonCollection values = null;
109-
110109
switch (me.Name) {
111110
case "append":
112111
values = PythonCollectionType.CreateList(Module.Interpreter, new List<IMember> { v }, exact: true);

src/Analysis/Ast/Impl/Types/Collections/PythonCollectionType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static IPythonCollection CreateList(IPythonInterpreter interpreter, IArgu
9595
} else {
9696
contents = args.ListArgument?.Values;
9797
}
98-
return CreateList(interpreter, contents ?? Array.Empty<IMember>());
98+
return CreateList(interpreter, contents ?? Array.Empty<IMember>(), exact: exact);
9999
}
100100

101101
public static IPythonCollection CreateList(IPythonInterpreter interpreter, IReadOnlyList<IMember> contents, bool flatten = true, bool exact = false) {

src/LanguageServer/Test/ImportsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def baz(self):
536536
pass
537537
" + allCode;
538538

539-
var appCode = @"
539+
const string appCode = @"
540540
from module1 import *
541541
542542
A().

0 commit comments

Comments
 (0)