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 all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
61d60c4
Persistent analysis, part I (#1224)
Jun 20, 2019
b2c9afb
Merge master into database branch (#1312)
Jul 11, 2019
ab8ecaf
Merge master
Jul 15, 2019
4a2fd79
Treat persistent module as regular specialized (#1334)
Jul 23, 2019
da3eb70
Store location of module members in the database (#1339)
Jul 26, 2019
a502cb5
Merge master
Jul 30, 2019
2143719
Multiple fixes and additional tests for persistence (#1372)
Aug 8, 2019
ff46089
Merge master
Aug 10, 2019
78b1bcf
Merge master
Aug 13, 2019
f267b80
Add persistence tests for 60+ system modules (#1429)
Aug 15, 2019
3c53083
Merge master
Aug 16, 2019
69806e0
Test update (we no longer reassign classes)
Aug 16, 2019
356ae4b
Fix typing tests
Aug 16, 2019
36a1d72
Update baseline
Aug 16, 2019
41c94e7
Fix missing keys issue (#1451)
AlexanderSher Aug 16, 2019
6284174
Typevar fix
Aug 17, 2019
28ec49b
Merge master
Aug 20, 2019
8b4c00a
Merge mast
Aug 21, 2019
86c8426
Persistence of generics and named tuples (#1459)
Aug 21, 2019
a82c356
- Fix #1455: AF: Library module of type Stub has been analyzed alread…
AlexanderSher Aug 22, 2019
ab93845
Merge master
Aug 23, 2019
79685eb
Update baselines since __spec__ member was added
Aug 26, 2019
809dc5c
Merge master (partial)
Aug 26, 2019
0f7f7ca
Undo some of changes to match master.
Aug 26, 2019
252d303
Fix null ref
Aug 26, 2019
a013b3a
Merge branch 'master' of https://github.com/Microsoft/python-language…
Aug 27, 2019
4de0812
Merge master
Aug 28, 2019
0913ea3
Merge master
Aug 30, 2019
8adb6cc
Merge master
Aug 30, 2019
c1883b5
Merge master
Sep 3, 2019
b923349
Resolve conflicts
Sep 3, 2019
28ce8e3
Fix null ref on bases due to new AnyStr behavior
Sep 3, 2019
e7f29d7
Handling dependencies in module persistence (#1471)
Sep 5, 2019
8cf831f
Upgrade to 3.0
Sep 5, 2019
958617b
Merge branch 'net3' of https://github.com/MikhailArkhipov/python-lang…
Sep 5, 2019
54d67cb
Undo change + .NET 3
Sep 5, 2019
26ea552
Get back to 2.0
Sep 5, 2019
fff4e0c
Merge branch 'net3' of https://github.com/MikhailArkhipov/python-lang…
Sep 5, 2019
227726c
Update components
Sep 5, 2019
2dd8fcf
Display caching level
Sep 5, 2019
c0f16e6
Fix null ref due to conflicting changes
Sep 5, 2019
987a837
Null ref fix
Sep 5, 2019
6d79b49
Simplify
Sep 5, 2019
28a4ce5
Pass AST whish is required during analysis when module does not have …
Sep 5, 2019
e24a4fd
tensorflow test
Sep 6, 2019
c4404cf
Fix from import model
Sep 6, 2019
c20485b
Undo debug
Sep 6, 2019
119e1b2
Improve goto def in import and fix class base processing (#1529)
Sep 9, 2019
2313d44
Usings
Sep 10, 2019
af2d7c7
Test fix
Sep 10, 2019
8e3289c
Remove CompletionItemKind.None
Sep 10, 2019
af70958
Add info to asserts
Sep 10, 2019
83ddd00
Merge master
Sep 10, 2019
967e741
PR feedback
Sep 10, 2019
653fd80
Undo test change, enable class reassignment
Sep 10, 2019
655818e
Prevent merge of unrelated types
Sep 11, 2019
48561b8
more tests
Sep 11, 2019
61014c1
Fix variable update
Sep 11, 2019
ab29574
Null check
Sep 11, 2019
81e36ce
Baselines
Sep 11, 2019
8323cd2
Move analysis complete event
Sep 11, 2019
f44c051
More stable enumeration
Sep 11, 2019
87093f3
Improve restoring imports in tests
Sep 11, 2019
a81874e
Make extension for tests
Sep 11, 2019
6a6fbb2
Add URI null check
Sep 12, 2019
8547a9b
Fix completion typo
Sep 12, 2019
8aa373c
Add assert on unresolved modules
Sep 12, 2019
820fdd4
Add more details to assert
Sep 12, 2019
db002c4
Using
Sep 12, 2019
56b8d88
To 3.7
Sep 12, 2019
68d38e7
Implement check for big/little endian
Sep 12, 2019
8dcd2bd
Merge master
Sep 12, 2019
93be7b1
Sync
Sep 12, 2019
2bdc314
Synchronization
Sep 13, 2019
3ee351c
Add hard assert
Sep 13, 2019
55b85e4
Fix exception
Sep 14, 2019
97f280c
Merge branch 'master' of https://github.com/Microsoft/python-language…
Sep 16, 2019
4108948
Fix typo
Sep 16, 2019
d6260fe
Add lock
Sep 16, 2019
c08dc38
Adding support for egg and zip files (#1477)
CTrando Sep 16, 2019
fbfafb8
Merge branch 'master' of https://github.com/Microsoft/python-language…
Sep 16, 2019
80fcca7
Merge branch 'db' of https://github.com/Microsoft/python-language-ser…
Sep 16, 2019
52e4beb
Unpacking typing Tuples and Lists correctly (#1498)
CTrando Sep 16, 2019
b164dbe
Merge branch 'master' of https://github.com/Microsoft/python-language…
Sep 16, 2019
e9ca834
Fix merge issue
Sep 16, 2019
881be72
Comment typo
Sep 16, 2019
13cde86
Handling some more cases for TypeVar bound (#1509)
CTrando Sep 16, 2019
9d6075e
Merge branch 'master' of https://github.com/Microsoft/python-language…
Sep 16, 2019
e151f66
Merge branch 'db' of https://github.com/Microsoft/python-language-ser…
Sep 16, 2019
0cf105f
Fix test
Sep 16, 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
5 changes: 4 additions & 1 deletion src/Analysis/Ast/Impl/Extensions/ArgumentSetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ public static IReadOnlyList<KeyValuePair<string, T>> Arguments<T>(this IArgument
public static T Argument<T>(this IArgumentSet args, int index) where T : class
=> args.Arguments[index].Value as T;

public static IArgument Argument(this IArgumentSet args, string name, bool excludeDefault = true)
=> args.Arguments.FirstOrDefault(a => name.Equals(a.Name) && !(excludeDefault &&a.ValueIsDefault));

public static T GetArgumentValue<T>(this IArgumentSet args, string name, bool excludeDefault = true) where T : class {
var value = args.Arguments.FirstOrDefault(a => name.Equals(a.Name) && !(excludeDefault && a.ValueIsDefault))?.Value;
var value = Argument(args, name, excludeDefault)?.Value;
if (value == null && args.DictionaryArgument?.Arguments != null && args.DictionaryArgument.Arguments.TryGetValue(name, out var m)) {
return m as T;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Microsoft.Python.Analysis.Types;
using Microsoft.Python.Analysis.Utilities;
using Microsoft.Python.Analysis.Values;
using Microsoft.Python.Core.Diagnostics;
using Microsoft.Python.Core.Text;
using Microsoft.Python.Parsing;

Expand Down Expand Up @@ -103,8 +104,13 @@ private static bool TypeVarArgumentsValid(IArgumentSet argSet) {
/// </summary>
private static IPythonType GetBoundType(IArgumentSet argSet) {
var eval = argSet.Eval;
var rawBound = argSet.GetArgumentValue<IMember>("bound");
var boundArg = argSet.Argument("bound");
var rawBound = boundArg?.Value as IMember;
switch (rawBound) {
// User did not pass in upper bound, bail
case null:
case IMember m when m.IsUnknown():
return null;
case IPythonType t:
return t;
case IPythonConstant c:
Expand All @@ -119,6 +125,7 @@ private static IPythonType GetBoundType(IArgumentSet argSet) {
}

public static IPythonType FromTypeVar(IArgumentSet argSet, IPythonModule declaringModule, IndexSpan indexSpan = default) {
Check.ArgumentNotNull(nameof(argSet.Eval), argSet.Eval);
if (!TypeVarArgumentsValid(argSet)) {
return declaringModule.Interpreter.UnknownType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void SpecializeMembers() {
o.SetParameters(new List<ParameterInfo> {
new ParameterInfo("name", Interpreter.GetBuiltinType(BuiltinTypeId.Str), ParameterKind.Normal, null),
new ParameterInfo("constraints", Interpreter.GetBuiltinType(BuiltinTypeId.Str), ParameterKind.List, null),
new ParameterInfo("bound", Interpreter.GetBuiltinType(BuiltinTypeId.Str), ParameterKind.KeywordOnly, new PythonConstant(null, Interpreter.GetBuiltinType(BuiltinTypeId.NoneType))),
new ParameterInfo("bound", Interpreter.GetBuiltinType(BuiltinTypeId.Type), ParameterKind.KeywordOnly, new PythonConstant(null, Interpreter.GetBuiltinType(BuiltinTypeId.NoneType))),
new ParameterInfo("covariant", Interpreter.GetBuiltinType(BuiltinTypeId.Bool), ParameterKind.KeywordOnly, new PythonConstant(false, Interpreter.GetBuiltinType(BuiltinTypeId.Bool))),
new ParameterInfo("contravariant", Interpreter.GetBuiltinType(BuiltinTypeId.Bool), ParameterKind.KeywordOnly, new PythonConstant(false, Interpreter.GetBuiltinType(BuiltinTypeId.Bool)))
});
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Ast/Impl/Types/PythonFunctionOverload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private IMember CreateSpecificReturnFromTypeVar(IPythonClassType selfClassType,
}

// Try getting the type from the type parameter bound
if (returnType.Bound != null) {
if (!returnType.Bound.IsUnknown()) {
return returnType.Bound.CreateInstance(args);
}

Expand Down
38 changes: 38 additions & 0 deletions src/Analysis/Ast/Test/GenericsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,44 @@ def get(self) -> T: ...
analysis.Should().HaveVariable("x").OfType("A");
}

[TestMethod, Priority(0)]
public async Task GenericDefaultBound() {
const string code = @"
from typing import TypeVar, Generic
from logging import Logger, getLogger

T = TypeVar('T')

class A: ...

class Test(Generic[T]):
def get(self) -> T: ...

x = Test().get()
";
var analysis = await GetAnalysisAsync(code);
analysis.Should().HaveVariable("x").OfType("T");
}

[TestMethod, Priority(0)]
public async Task GenericUnknownBound() {
const string code = @"
from typing import TypeVar, Generic
from logging import Logger, getLogger

T = TypeVar('T', bound='unknown_thing')

class A: ...

class Test(Generic[T]):
def get(self) -> T: ...

x = Test().get()
";
var analysis = await GetAnalysisAsync(code);
analysis.Should().HaveVariable("x").OfType(BuiltinTypeId.Unknown);
}

[TestMethod, Priority(0)]
public async Task GenericPath() {
const string code = @"
Expand Down