Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 168 commits
Commits
Show all changes
187 commits
Select commit Hold shift + click to select a range
b605b76
Remove old qualified name
May 17, 2019
5471ce4
Node storage
May 17, 2019
8a8d847
Class and scope to use AST map
May 17, 2019
89ce2ca
Library analysis
May 17, 2019
7a93bf7
Fix SO
May 18, 2019
2a2bdf8
Keep small AST with imports
May 18, 2019
3edaa73
AST reduction
May 18, 2019
73371e1
Final field
May 18, 2019
7d60edc
Initial
May 20, 2019
02475f4
Reload
May 22, 2019
835eeac
Merge master
May 25, 2019
6b6e928
Ignore post-final requests
May 25, 2019
9692397
Drop AST
May 25, 2019
080beab
Remove local variables
May 25, 2019
93a6915
Test fixes
May 26, 2019
cadd7ce
Fix overload match
May 26, 2019
f61b1a7
Tests
May 26, 2019
1b20326
Add locks
May 27, 2019
d7efdac
Remove local variables
May 25, 2019
98934d4
Drop file content to save memory
May 27, 2019
417ae03
Cache PEP hints
May 28, 2019
ec5605f
Recreate AST
May 28, 2019
713d87f
Fix specialization
May 28, 2019
50e63e6
Fix locations
May 28, 2019
fcd0c06
usings
May 28, 2019
f6a992b
Test fixes
May 28, 2019
acad202
Add options to keep data in memory
May 28, 2019
f176b2f
Merge branch 'master' of https://github.com/microsoft/python-language…
May 28, 2019
4225337
Merge master
May 28, 2019
86e36a6
Fix test
May 28, 2019
ba97e9f
Fix lambda parameters
May 28, 2019
ffed87e
Fix argument set
May 29, 2019
186a9c6
Fix overload doc
May 29, 2019
4196699
Fix stub merge errors
May 29, 2019
93249d4
Fix async issues
May 29, 2019
5e61392
Undo some changes
May 29, 2019
130b95d
Fix test
May 29, 2019
a6676f1
Fix race condition
May 30, 2019
18b61ad
Merge master
Jun 1, 2019
0850544
Merge master
Jun 3, 2019
7d0bf5b
Merge branch 'proxymod' into db
Jun 4, 2019
663dc8f
Partial
Jun 4, 2019
86544a6
Models and views
Jun 4, 2019
67b06c2
Merge branch 'master' of https://github.com/microsoft/python-language…
Jun 4, 2019
9daf4a9
Merge master
Jun 4, 2019
90318e9
Restore log null checks
Jun 4, 2019
b79d918
Merge master
Jun 4, 2019
a02c6f3
Fix merge conflict
Jun 4, 2019
8a6b055
Merge master
Jun 5, 2019
57358eb
Fix merge issue
Jun 5, 2019
41ef00f
Merge branch 'master' of https://github.com/microsoft/python-language…
Jun 5, 2019
814cd64
Merge master
Jun 6, 2019
6ceb9b8
Null check
Jun 6, 2019
74bb061
Merge branch 'noast5' into db
Jun 6, 2019
478ce37
Partial
Jun 6, 2019
cb46e68
Partial
Jun 6, 2019
ef2981c
Partial
Jun 6, 2019
2164ad5
Fix test
Jun 6, 2019
1a48790
Merge branch 'noast5' into db
Jun 6, 2019
319c416
Partial
Jun 6, 2019
86b0ee6
Partial
Jun 7, 2019
1670c9d
First test
Jun 7, 2019
ab69cfd
Baseline comparison
Jun 7, 2019
e00c197
Builtins
Jun 7, 2019
4e1657c
Partial
Jun 7, 2019
ade00f4
Type fixes
Jun 10, 2019
e2fc221
Fix type names, part I
Jun 11, 2019
aaf40bb
Qualified name
Jun 11, 2019
a5b3b20
Properly write variables
Jun 11, 2019
f23a487
Partial
Jun 11, 2019
e6373a7
Construct module from model
Jun 12, 2019
6f6737d
Test
Jun 12, 2019
081f475
Variable creations
Jun 12, 2019
42fa4dc
Factories
Jun 13, 2019
2f03cb9
Factories
Jun 13, 2019
1dc3339
Split construction
Jun 13, 2019
9535bad
Restore
Jun 13, 2019
bec2a82
Save builtins
Jun 13, 2019
80c9b1c
Test passes
Jun 13, 2019
5b372f7
Qualified name
Jun 13, 2019
3066554
Better export detection
Jun 14, 2019
91491d4
Test fixes
Jun 14, 2019
bc4f587
More consistent qualified names
Jun 14, 2019
af69880
Sys test
Jun 14, 2019
5c1a0c3
Demo
Jun 14, 2019
4146690
Complete sys write/read
Jun 17, 2019
48763aa
Partial
Jun 17, 2019
93bece3
Partial
Jun 18, 2019
55b6a3f
Test staility
Jun 18, 2019
5e9bf8e
Perf bug
Jun 18, 2019
c152e67
Merge master
Jun 18, 2019
eadd622
Baseline, remove debug code, deactivate db
Jun 18, 2019
ba87581
Test fixes
Jun 18, 2019
a797593
Test fix
Jun 18, 2019
db6c7fc
Simplify a bit
Jun 19, 2019
f73fed0
Baselines and use : separator
Jun 19, 2019
4054d5a
Baselines
Jun 19, 2019
4ef96d8
PR feedback
Jun 19, 2019
c7436ed
Merge branch 'master' of https://github.com/microsoft/python-language…
Jun 19, 2019
f3860e6
Merge master
Jun 19, 2019
cab0fce
Remove registry reference
Jun 19, 2019
b9c1e14
PR feedback
Jun 19, 2019
4fbdcb9
Merge master
Jul 11, 2019
c7b1a5d
Merge db
Jul 11, 2019
90d1429
PR feedback
Jul 11, 2019
10289c3
Merge branch 'master' of https://github.com/microsoft/python-language…
Jul 12, 2019
facb062
Restore persistence + update test
Jul 12, 2019
d80604a
Better handle persistent module in dependencies
Jul 14, 2019
0705812
Merge master
Jul 15, 2019
96a5b82
Merge master
Jul 15, 2019
360f922
Undo
Jul 15, 2019
1015c1b
Add location converter abstraction
Jul 15, 2019
2ab07d6
Store member location
Jul 15, 2019
57c24c5
Fix merge issue
Jul 15, 2019
4779813
Basic locations test
Jul 15, 2019
7e6fb63
Navigation
Jul 15, 2019
9ee9bfe
Add test
Jul 16, 2019
fc66756
Update baselines
Jul 16, 2019
3b0fb23
Type restore - initial
Jul 17, 2019
8192ff2
Remove debug code
Jul 17, 2019
e27218f
Partial
Jul 17, 2019
ae4e178
Fix stub merge
Jul 18, 2019
2209ec1
Various model fixes
Jul 19, 2019
73498eb
Improve module handling
Jul 19, 2019
fcfb2bb
Qualified name improvements
Jul 23, 2019
54fa335
Fix unbound case
Jul 23, 2019
bb0b415
Improve stub merge
Jul 23, 2019
3b213bc
Fix qualified names of typing
Jul 23, 2019
eaa9e37
Handle stub-only modules
Jul 23, 2019
05eb692
Merge branch 'db' of https://github.com/microsoft/python-language-ser…
Jul 23, 2019
5193858
Merge branch 'dbloc' into dbtype
Jul 23, 2019
b888b2a
Add tests for io, re and sys
Jul 24, 2019
40554b0
Better handle named tuple
Jul 24, 2019
fcd2bd5
Handle module circular references
Jul 24, 2019
28f5b6c
Handle else in platform and version clauses + handle it in symbol col…
Jul 24, 2019
8fdf769
Formatting
Jul 24, 2019
08b5971
Fix walk of multi-level if statement
Jul 24, 2019
67fed10
Unify package search in imports
Jul 24, 2019
247a8c3
Fix tests
Jul 25, 2019
2bd4749
Undo change
Jul 25, 2019
5ead9ec
Port changes from dbtype
Jul 25, 2019
4090ca0
Merge fixes from upstream
Jul 25, 2019
97f1716
Merge master
Jul 25, 2019
59f4b83
Partial
Jul 26, 2019
91a0bb5
Named tuple support
Jul 29, 2019
362800c
Baseline updates
Jul 29, 2019
32e8bfc
Debug code
Jul 29, 2019
0d65468
Support types
Jul 30, 2019
f42d453
Merge branch 'master' into dbtype
Jul 30, 2019
3a1fd40
Merge upstream
Jul 30, 2019
9e3011d
Properly compare class member declaring type
Jul 30, 2019
eba1f45
Nested classes and functions persistence
Jul 30, 2019
12b0269
Undo debug
Jul 30, 2019
234390d
Fix numpy restore
Jul 30, 2019
263eabf
Baselines
Jul 30, 2019
f065110
Fix tests
Jul 31, 2019
b2b0501
Update AnyStr test reflecting changes to AnyStr behavior
Jul 31, 2019
28fa723
Exclude baselines from git diff
Jul 31, 2019
b58e893
Fix gitattr
Jul 31, 2019
f110a53
Move git setting to root
Jul 31, 2019
21c1660
Try no path
Jul 31, 2019
754a668
Add RDT count to the analysis_complete event (#1396)
jakebailey Jul 31, 2019
96d38b2
Test fixes
Jul 31, 2019
7ee6322
Undo change
Jul 31, 2019
db4aab1
Additional stub merge fixes
Aug 2, 2019
f72818e
Baseline updates
Aug 2, 2019
ed1a728
Fix goto def
Aug 4, 2019
8ee1fd0
Protect specific type creation
Aug 5, 2019
0ce7bad
Track documentaton source
Aug 5, 2019
f9aff94
Merge
Aug 5, 2019
088ce1b
More reliable tests + simplification
Aug 5, 2019
b423ed8
Prevent crashes when the AST happens to be null (#1405)
jakebailey Aug 5, 2019
352fecc
Remove all references to dropped modules and force GC on reload (#1402)
jakebailey Aug 5, 2019
c1b93d8
Typo
Aug 5, 2019
62ac1c2
Cleanup
Aug 6, 2019
b719956
Basic classification
Aug 6, 2019
14671ae
Merge #1340
Aug 6, 2019
7983c75
Merge master
Aug 6, 2019
6b207ae
Merge master
Aug 6, 2019
a9b7ff0
Fix merge error
Aug 6, 2019
ac9d1cb
Module unique id fixes
Aug 6, 2019
23a9b81
Stricted check to save analysis
Aug 6, 2019
1d86086
Revert "Fix tests"
Aug 7, 2019
67350e3
Revert "Unify package search in imports"
Aug 7, 2019
01d7f2f
Merge branch '1376' into dbtype
Aug 7, 2019
f687dc8
Don't clear scope variables with inner classes
Aug 7, 2019
68b479b
Fix typo
Aug 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.json -diff
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace Microsoft.Python.Analysis.Analyzer.Evaluation {
internal sealed partial class ExpressionEval {
public IPythonInstance GetConstantFromLiteral(Expression expr, LookupOptions options) {
public IPythonInstance GetConstantFromLiteral(Expression expr) {
if (expr is ConstantExpression ce) {
switch (ce.Value) {
case string s:
Expand Down
31 changes: 17 additions & 14 deletions src/Analysis/Ast/Impl/Analyzer/Evaluation/ExpressionEval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public IMember GetValueFromExpression(Expression expr, LookupOptions options = L
m = null;
break;
default:
m = GetValueFromBinaryOp(expr) ?? GetConstantFromLiteral(expr, options);
m = GetValueFromBinaryOp(expr) ?? GetConstantFromLiteral(expr);
break;
}
if (m == null) {
Expand Down Expand Up @@ -237,29 +237,32 @@ private IMember GetValueFromMember(MemberExpression expr) {
return null;
}

IPythonInstance instance = null;
var m = GetValueFromExpression(expr.Target);
if (m is IPythonType typeInfo) {
var member = typeInfo.GetMember(expr.Name);
// If container is class/type info rather than the instance, then the method is an unbound function.
// Example: C.f where f is a method of C. Compare to C().f where f is bound to the instance of C.
if (member is PythonFunctionType f && !f.IsStatic && !f.IsClassMethod) {
f.AddReference(GetLocationOfName(expr));
return f.ToUnbound();
}
instance = new PythonInstance(typeInfo);
if (m == null) {
return UnknownType;
}

instance = instance ?? m as IPythonInstance;
var type = m?.GetPythonType(); // Try inner type

var type = m.GetPythonType();
var value = type?.GetMember(expr.Name);
type?.AddMemberReference(expr.Name, this, GetLocationOfName(expr));

if (type is IPythonModule) {
return value;
}

IPythonInstance instance = null;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to fix the issue when standalone function could become an unbound method with declaring type of null. Does not really affect completions, but present problems when restoring function from the database.

if (m == type) {
// If container is class/type info rather than the instance, then the method is an unbound function.
// Example: C.f where f is a method of C. Compare to C().f where f is bound to the instance of C.
if (value is PythonFunctionType f && f.DeclaringType != null && !f.IsStatic && !f.IsClassMethod) {
f.AddReference(GetLocationOfName(expr));
return f.ToUnbound();
}
instance = new PythonInstance(type);
}

instance = instance ?? m as IPythonInstance;

// Class type GetMember returns a type. However, class members are
// mostly instances (consider self.x = 1, x is an instance of int).
// However, it is indeed possible to have them as types, like in
Expand Down
109 changes: 2 additions & 107 deletions src/Analysis/Ast/Impl/Analyzer/Handlers/ConditionalHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,123 +13,18 @@
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System;
using System.Linq;
using Microsoft.Python.Core.OS;
using Microsoft.Python.Parsing;
using Microsoft.Python.Parsing.Ast;

namespace Microsoft.Python.Analysis.Analyzer.Handlers {
internal sealed class ConditionalHandler : StatementHandler {
private readonly IOSPlatform _platformService;

private enum ConditionTestResult {
Unrecognized,
DontWalkBody,
WalkBody
}

public ConditionalHandler(AnalysisWalker walker) : base(walker) {
_platformService = Eval.Services.GetService<IOSPlatform>();
}

public bool HandleIf(IfStatement node) {
// System version, platform and os.path specializations
var someRecognized = false;
foreach (var test in node.Tests) {
var result = TryHandleSysVersionInfo(test);
if (result != ConditionTestResult.Unrecognized) {
if (result == ConditionTestResult.WalkBody) {
test.Walk(Walker);
}
someRecognized = true;
continue;
}

result = TryHandleSysPlatform(test);
if (result != ConditionTestResult.Unrecognized) {
if (result == ConditionTestResult.WalkBody) {
test.Walk(Walker);
}
someRecognized = true;
continue;
}

result = TryHandleOsPath(test);
if (result != ConditionTestResult.Unrecognized) {
if (result == ConditionTestResult.WalkBody) {
test.Walk(Walker);
return false; // Execute only one condition.
}
someRecognized = true;
}
}
return !someRecognized;
}

private ConditionTestResult TryHandleSysVersionInfo(IfStatementTest test) {
if (test.Test is BinaryExpression cmp &&
cmp.Left is MemberExpression me && (me.Target as NameExpression)?.Name == "sys" && me.Name == "version_info" &&
cmp.Right is TupleExpression te && te.Items.All(i => (i as ConstantExpression)?.Value is int)) {
Version v;
try {
v = new Version(
(int)((te.Items.ElementAtOrDefault(0) as ConstantExpression)?.Value ?? 0),
(int)((te.Items.ElementAtOrDefault(1) as ConstantExpression)?.Value ?? 0)
);
} catch (ArgumentException) {
// Unsupported comparison, so walk all children
return ConditionTestResult.WalkBody;
}

var shouldWalk = false;
switch (cmp.Operator) {
case PythonOperator.LessThan:
shouldWalk = Ast.LanguageVersion.ToVersion() < v;
break;
case PythonOperator.LessThanOrEqual:
shouldWalk = Ast.LanguageVersion.ToVersion() <= v;
break;
case PythonOperator.GreaterThan:
shouldWalk = Ast.LanguageVersion.ToVersion() > v;
break;
case PythonOperator.GreaterThanOrEqual:
shouldWalk = Ast.LanguageVersion.ToVersion() >= v;
break;
}
return shouldWalk ? ConditionTestResult.WalkBody : ConditionTestResult.DontWalkBody;
}
return ConditionTestResult.Unrecognized;
}

private ConditionTestResult TryHandleSysPlatform(IfStatementTest test) {
if (test.Test is BinaryExpression cmp &&
cmp.Left is MemberExpression me && (me.Target as NameExpression)?.Name == "sys" && me.Name == "platform" &&
cmp.Right is ConstantExpression cex && cex.GetStringValue() is string s) {
switch (cmp.Operator) {
case PythonOperator.Equals:
return s == "win32" && _platformService.IsWindows ? ConditionTestResult.WalkBody : ConditionTestResult.DontWalkBody;
case PythonOperator.NotEquals:
return s == "win32" && _platformService.IsWindows ? ConditionTestResult.DontWalkBody : ConditionTestResult.WalkBody;
}
return ConditionTestResult.DontWalkBody;
}
return ConditionTestResult.Unrecognized;
}

private ConditionTestResult TryHandleOsPath(IfStatementTest test) {
if (test.Test is BinaryExpression cmp &&
cmp.Left is ConstantExpression cex && cex.GetStringValue() is string s &&
cmp.Right is NameExpression nex && nex.Name == "_names") {
switch (cmp.Operator) {
case PythonOperator.In when s == "nt":
return _platformService.IsWindows ? ConditionTestResult.WalkBody : ConditionTestResult.DontWalkBody;
case PythonOperator.In when s == "posix":
return _platformService.IsWindows ? ConditionTestResult.DontWalkBody : ConditionTestResult.WalkBody;
}
return ConditionTestResult.DontWalkBody;
}
return ConditionTestResult.Unrecognized;
}
public bool HandleIf(IfStatement node)
=> node.WalkIfWithSystemConditions(Walker, Ast.LanguageVersion, _platformService.IsWindows);
}
}
14 changes: 10 additions & 4 deletions src/Analysis/Ast/Impl/Analyzer/Handlers/FromImportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ public bool HandleFromImport(FromImportStatement node) {
}
}

var imports = ModuleResolution.CurrentPathResolver.FindImports(Module.FilePath, node);
if (HandleImportSearchResult(imports, null, null, node.Root, out var variableModule)) {
AssignVariables(node, imports, variableModule);
if(node.Root is RelativeModuleName) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var imports = ModuleResolution.CurrentPathResolver.FindImports(Module.FilePath, node);
if (HandleImportSearchResult(imports, null, null, node.Root, out var variableModule)) {
AssignVariables(node, imports, variableModule);
}
} else {
FindModuleByAbsoluteName(node.Root, null, node.ForceAbsolute, out _, out var module, out _, out var imports);
AssignVariables(node, imports, module);
}

return false;
}

Expand Down Expand Up @@ -82,7 +88,7 @@ private void HandleModuleImportStar(PythonVariableModule variableModule, bool is
}

// If __all__ is present, take it, otherwise declare all members from the module that do not begin with an underscore.
var memberNames = isImplicitPackage
var memberNames = isImplicitPackage
? variableModule.GetMemberNames()
: variableModule.Analysis.StarImportMemberNames ?? variableModule.GetMemberNames().Where(s => !s.StartsWithOrdinal("_"));

Expand Down
31 changes: 18 additions & 13 deletions src/Analysis/Ast/Impl/Analyzer/Handlers/ImportHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,30 @@ public bool HandleImport(ImportStatement node) {
}

private void HandleImport(ModuleName moduleImportExpression, NameExpression asNameExpression, bool forceAbsolute) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FindModuleByAbsoluteName(moduleImportExpression, asNameExpression, forceAbsolute, out var firstModule, out var lastModule, out var importNames, out _);
// "import fob.oar.baz as baz" is handled as baz = import_module('fob.oar.baz')
// "import fob.oar.baz" is handled as fob = import_module('fob')
if (!string.IsNullOrEmpty(asNameExpression?.Name) && lastModule != default) {
Eval.DeclareVariable(asNameExpression.Name, lastModule, VariableSource.Import, asNameExpression);
} else if (firstModule != default && !string.IsNullOrEmpty(importNames[0])) {
var firstName = moduleImportExpression.Names[0];
Eval.DeclareVariable(importNames[0], firstModule, VariableSource.Import, firstName);
}
}

private void FindModuleByAbsoluteName(ModuleName moduleImportExpression, NameExpression asNameExpression, bool forceAbsolute,
out PythonVariableModule firstModule, out PythonVariableModule lastModule, out ImmutableArray<string> importNames, out IImportSearchResult imports) {
// "import fob.oar.baz" means
// import_module('fob')
// import_module('fob.oar')
// import_module('fob.oar.baz')
var importNames = ImmutableArray<string>.Empty;
var lastModule = default(PythonVariableModule);
var firstModule = default(PythonVariableModule);
importNames = ImmutableArray<string>.Empty;
lastModule = default;
firstModule = default;
imports = null;
foreach (var nameExpression in moduleImportExpression.Names) {
importNames = importNames.Add(nameExpression.Name);
var imports = ModuleResolution.CurrentPathResolver.GetImportsFromAbsoluteName(Module.FilePath, importNames, forceAbsolute);
imports = ModuleResolution.CurrentPathResolver.GetImportsFromAbsoluteName(Module.FilePath, importNames, forceAbsolute);
if (!HandleImportSearchResult(imports, lastModule, asNameExpression, moduleImportExpression, out lastModule)) {
lastModule = default;
break;
Expand All @@ -69,15 +83,6 @@ private void HandleImport(ModuleName moduleImportExpression, NameExpression asNa
firstModule = lastModule;
}
}

// "import fob.oar.baz as baz" is handled as baz = import_module('fob.oar.baz')
// "import fob.oar.baz" is handled as fob = import_module('fob')
if (!string.IsNullOrEmpty(asNameExpression?.Name) && lastModule != default) {
Eval.DeclareVariable(asNameExpression.Name, lastModule, VariableSource.Import, asNameExpression);
} else if (firstModule != default && !string.IsNullOrEmpty(importNames[0])) {
var firstName = moduleImportExpression.Names[0];
Eval.DeclareVariable(importNames[0], firstModule, VariableSource.Import, firstName);
}
}

private bool HandleImportSearchResult(in IImportSearchResult imports, in PythonVariableModule parent, in NameExpression asNameExpression, in Node location, out PythonVariableModule variableModule) {
Expand Down
3 changes: 0 additions & 3 deletions src/Analysis/Ast/Impl/Analyzer/LibraryAnalysis.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

using System.Collections.Generic;
using System.Linq;
using Microsoft.Python.Analysis.Analyzer.Evaluation;
using Microsoft.Python.Analysis.Diagnostics;
using Microsoft.Python.Analysis.Documents;
using Microsoft.Python.Analysis.Modules;
using Microsoft.Python.Analysis.Values;
using Microsoft.Python.Core;
using Microsoft.Python.Core.Diagnostics;
using Microsoft.Python.Parsing.Ast;

Expand Down
Loading