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 242 commits
Commits
Show all changes
247 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
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
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
eac2d40
Many new tests
Aug 7, 2019
f3261a3
Fix collections test
Aug 7, 2019
9825e3f
Fix CTypes
Aug 8, 2019
570a925
Initial
Aug 10, 2019
318b3cd
Update test
Aug 10, 2019
06112c6
Merge master
Aug 10, 2019
e0a37a9
Merge master
Aug 10, 2019
517a004
Merge master
Aug 11, 2019
f7717ac
Merge issues
Aug 11, 2019
4e4215c
Fix CTypes again
Aug 11, 2019
d6fa183
Merge branch '1231a' into dbsystest
Aug 11, 2019
2cbb89f
Fix null bases
Aug 11, 2019
58ae484
Tell between class members with/without self better
Aug 12, 2019
53f3af4
TypeVar support
Aug 12, 2019
11cb4b5
Add bound/covariant
Aug 12, 2019
9a92494
Fix Enum reassignments
Aug 12, 2019
e72285c
Fix Random
Aug 12, 2019
a26822a
Fix import * over local declarations (Socket)
Aug 13, 2019
c924622
Move interface
Aug 13, 2019
a473a98
Fix reference search
Aug 13, 2019
3c9a912
Enable asyncio test
Aug 13, 2019
8406a62
Merge db
Aug 13, 2019
4853e98
Merge hover fixes
Aug 13, 2019
3eb2f41
More tests
Aug 13, 2019
3d10d45
Merge branch 'db' of https://github.com/microsoft/python-language-ser…
Aug 13, 2019
4dcdb25
Enable dataclasses
Aug 13, 2019
a5c3af6
Add inspect and gzip
Aug 13, 2019
6fff95d
More tests
Aug 13, 2019
7847eb0
Add setting
Aug 13, 2019
e36ede9
Add handling of import position relative to the variable
Aug 13, 2019
2270c3b
Caching level changes
Aug 13, 2019
ffd2c37
Partial
Aug 14, 2019
8c0b1ee
Rework
Aug 14, 2019
f40966d
Fix null
Aug 14, 2019
359329f
Update baselines
Aug 14, 2019
6794e7c
Merge branch 'dbsystest' into functools
Aug 14, 2019
a0b9782
Functools pass
Aug 15, 2019
e99598b
Reverse stub merge
Aug 15, 2019
a5e41d0
Partial
Aug 15, 2019
2c1cbab
Partial ctypes
Aug 16, 2019
f511e64
Update variables post merge
Aug 16, 2019
18e882b
Fix ctypes
Aug 16, 2019
ab35ba6
Merge db/master
Aug 16, 2019
a037a64
Merge branch 'db' of https://github.com/microsoft/python-language-ser…
Aug 16, 2019
2f299cd
Merge issues
Aug 16, 2019
c614ec8
Fix typevar
Aug 17, 2019
97ba31d
Merge db
Aug 17, 2019
1c2968e
Add caching on construction
Aug 17, 2019
3509a55
Assorted fixes
Aug 19, 2019
ef9df9d
Named tuples
Aug 19, 2019
4b06021
Work around os stub oddness
Aug 19, 2019
02c506d
Fix generic qualified names
Aug 19, 2019
17aedd2
Ignore lambdas
Aug 19, 2019
7c5afc0
Support named tuples as bases
Aug 19, 2019
4ae9f42
Baselines
Aug 19, 2019
c3eb060
Test updates
Aug 19, 2019
d5b85ee
Named tuple tests
Aug 19, 2019
b00e157
Merge master
Aug 20, 2019
83c9d10
PR feedback
Aug 20, 2019
4bd56ff
Using
Aug 21, 2019
63c3fe7
Move diagnostics to GenericBase
Aug 21, 2019
e3cca84
PR feedback
Aug 21, 2019
aaae896
Merge db
Aug 21, 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
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,10 @@ private IMember CreateSpecificTypeFromIndex(IGenericType gt, IReadOnlyList<IMemb
if (!GenericClassParameterValid(genericTypeArgs, args, expr)) {
return UnknownType;
}

// Generic[T1, T2, ...] expression. Create generic base for the class.
return new GenericClassParameter(genericTypeArgs, Module);
}

// For other types just use supplied arguments
if (args.Count > 0) {
return gt.CreateSpecificType(new ArgumentSet(args, expr, this));
}

return UnknownType;
return args.Count > 0 ? gt.CreateSpecificType(new ArgumentSet(args, expr, this)) : UnknownType;
}

private IReadOnlyList<IMember> EvaluateIndex(IndexExpression expr) {
Expand Down
199 changes: 107 additions & 92 deletions src/Analysis/Ast/Impl/Analyzer/ModuleWalker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml.Serialization;
using Microsoft.Python.Analysis.Analyzer.Evaluation;
using Microsoft.Python.Analysis.Documents;
using Microsoft.Python.Analysis.Modules;
Expand Down Expand Up @@ -246,118 +245,134 @@ private void MergeStub() {
var sourceType = sourceVar?.Value.GetPythonType();

// If stub says 'Any' but we have better type, keep the current type.
if (!IsStubBetterType(sourceType, stubType)) {
if (stubType.IsUnknown() || (stubType.DeclaringModule is TypingModule && stubType.Name == "Any")) {
continue;
}

// If type does not exist in module, but exists in stub, declare it unless it is an import.
// If types are the classes, merge members. Otherwise, replace type from one from the stub.
switch (sourceType) {
case null:
// Nothing in sources, but there is type in the stub. Declare it.
if (v.Source == VariableSource.Declaration || v.Source == VariableSource.Generic) {
Eval.DeclareVariable(v.Name, v.Value, v.Source);
TryReplaceMember(v, sourceType, stubType);
}

UpdateVariables();
}

private void TryReplaceMember(IVariable v, IPythonType sourceType, IPythonType stubType) {
// If type does not exist in module, but exists in stub, declare it unless it is an import.
// If types are the classes, take class from the stub, then add missing members.
// Otherwise, replace type from one from the stub.
switch (sourceType) {
case null:
// Nothing in sources, but there is type in the stub. Declare it.
if (v.Source == VariableSource.Declaration || v.Source == VariableSource.Generic) {
Eval.DeclareVariable(v.Name, v.Value, v.Source);
}
break;

case PythonClassType sourceClass when Module.Equals(sourceClass.DeclaringModule):
// Transfer documentation first so we get class documentation
// that came from class definition win over one that may
// come from __init__ during the member merge below.
TransferDocumentationAndLocation(sourceClass, stubType);

// Replace the class entirely since stub members may use generic types
// and the class definition is important. We transfer missing members
// from the original class to the stub.
Eval.DeclareVariable(v.Name, v.Value, v.Source);

// Go through source class members and pick those that are
// not present in the stub class.
foreach (var name in sourceClass.GetMemberNames()) {

var sourceMember = sourceClass.GetMember(name);
if (sourceMember.IsUnknown()) {
continue; // Anything is better than unknowns.
}
break;
var sourceMemberType = sourceMember?.GetPythonType();

case PythonClassType cls when Module.Equals(cls.DeclaringModule):
// Transfer documentation first so we get class documentation
// that came from class definition win over one that may
// come from __init__ during the member merge below.
TransferDocumentationAndLocation(sourceType, stubType);
var stubMember = stubType.GetMember(name);
var stubMemberType = stubMember.GetPythonType();

// If class exists and belongs to this module, add or replace
// its members with ones from the stub, preserving documentation.
// Don't augment types that do not come from this module.
// Do not replace __class__ since it has to match class type and we are not
// replacing class type, we are only merging members.
foreach (var name in stubType.GetMemberNames().Except(new[] { "__class__", "__base__", "__bases__", "__mro__", "mro" })) {
var stubMember = stubType.GetMember(name);
var member = cls.GetMember(name);

var memberType = member?.GetPythonType();
var stubMemberType = stubMember.GetPythonType();

if (sourceType.IsBuiltin || stubType.IsBuiltin) {
// If stub type does not have an immediate member such as __init__() and
// rather have it inherited from object, we do not want to use the inherited
// since current class may either have its own of inherits it from the object.
continue;
}

if (stubMemberType?.MemberType == PythonMemberType.Method && stubMemberType?.DeclaringModule.ModuleType == ModuleType.Builtins) {
// Leave methods coming from object at the object and don't copy them into the derived class.
}

if (!IsStubBetterType(memberType, stubMemberType)) {
continue;
}

// Get documentation from the current type, if any, since stubs
// typically do not contain documentation while scraped code does.
TransferDocumentationAndLocation(memberType, stubMemberType);
cls.AddMember(name, stubMember, overwrite: true);
if (sourceType.IsBuiltin || stubType.IsBuiltin) {
// If source type does not have an immediate member such as __init__() and
// rather have it inherited from object, we do not want to use the inherited
// since stub class may either have its own of inherits it from the object.
continue;
}
break;

case IPythonModule _:
// We do not re-declare modules.
break;

default:
var stubModule = stubType.DeclaringModule;
if (stubType is IPythonModule || stubModule.ModuleType == ModuleType.Builtins) {
// Modules members that are modules should remain as they are, i.e. os.path
// should remain library with its own stub attached.
break;
if (stubMemberType?.MemberType == PythonMemberType.Method && stubMemberType?.DeclaringModule.ModuleType == ModuleType.Builtins) {
// Leave methods coming from object at the object and don't copy them into the derived class.
}
// We do not re-declaring variables that are imported.
if (v.Source == VariableSource.Declaration) {
// Re-declare variable with the data from the stub.
TransferDocumentationAndLocation(sourceType, stubType);
// TODO: choose best type between the scrape and the stub. Stub probably should always win.
var source = Eval.CurrentScope.Variables[v.Name]?.Source ?? v.Source;
Eval.DeclareVariable(v.Name, v.Value, source);

// Get documentation from the current type, if any, since stubs
// typically do not contain documentation while scraped code does.
TransferDocumentationAndLocation(sourceMemberType, stubMemberType);

// If stub says 'Any' but we have better type, use member from the original class.
if (stubMember != null && !(stubType.DeclaringModule is TypingModule && stubType.Name == "Any")) {
continue; // Stub already have the member, don't replace.
}

(stubType as PythonType)?.AddMember(name, stubMember, overwrite: true);
}
break;

case IPythonModule _:
// We do not re-declare modules.
break;

default:
var stubModule = stubType.DeclaringModule;
if (stubType is IPythonModule || stubModule.ModuleType == ModuleType.Builtins) {
// Modules members that are modules should remain as they are, i.e. os.path
// should remain library with its own stub attached.
break;
}
}
// We do not re-declaring variables that are imported.
if (v.Source == VariableSource.Declaration) {
// Re-declare variable with the data from the stub.
TransferDocumentationAndLocation(sourceType, stubType);
// TODO: choose best type between the scrape and the stub. Stub probably should always win.
var source = Eval.CurrentScope.Variables[v.Name]?.Source ?? v.Source;
Eval.DeclareVariable(v.Name, v.Value, source);
}

break;
}
}

private static bool IsStubBetterType(IPythonType sourceType, IPythonType stubType) {
if (stubType.IsUnknown()) {
// Do not use worse types than what is in the module.
return false;
}
if (sourceType.IsUnknown()) {
return true; // Anything is better than unknowns.
}
if (sourceType.DeclaringModule.ModuleType == ModuleType.Specialized) {
// Types in specialized modules should never be touched.
return false;
}
if (stubType.DeclaringModule is TypingModule && stubType.Name == "Any") {
// If stub says 'Any' but we have better type, keep the current type.
return false;
}
// Types should be compatible except it is allowed to replace function by a class.
// Consider stub of threading that replaces def RLock(): by class RLock().
// Similarly, in _json, make_scanner function is replaced by a class.
if (sourceType.MemberType == PythonMemberType.Function && stubType.MemberType == PythonMemberType.Class) {
return true;
}
// Random replaces method (variable) by a function.
if (sourceType.MemberType == PythonMemberType.Method && stubType.MemberType == PythonMemberType.Function) {
return true;
private void UpdateVariables() {
// Second pass: if we replaced any classes by new from the stub, we need to update
// variables that may still be holding old content. For example, ctypes
// declares 'c_voidp = c_void_p' so when we replace 'class c_void_p'
// by class from the stub, we need to go and update 'c_voidp' variable.
foreach (var v in GlobalScope.Variables) {
var variableType = v.Value.GetPythonType();
if (!variableType.DeclaringModule.Equals(Module) && !variableType.DeclaringModule.Equals(Module.Stub)) {
continue;
}
// Check if type that the variable references actually declared here.
var typeInScope = GlobalScope.Variables[variableType.Name].GetPythonType();
if (typeInScope == null || variableType == typeInScope) {
continue;
}

if (v.Value == variableType) {
Eval.DeclareVariable(v.Name, typeInScope, v.Source);
} else if (v.Value is IPythonInstance) {
Eval.DeclareVariable(v.Name, new PythonInstance(typeInScope), v.Source);
}
}
return sourceType.MemberType == stubType.MemberType;
}

private static void TransferDocumentationAndLocation(IPythonType s, IPythonType d) {
if (s.IsUnknown() || d.IsBuiltin || s.IsBuiltin) {
if (s.IsUnknown() || s.IsBuiltin || d == null || d.IsBuiltin) {
return; // Do not transfer location of unknowns or builtins
}

if (d.DeclaringModule != s.DeclaringModule.Stub) {
return; // Do not change unrelated types.
}

// Documentation and location are always get transferred from module type
// to the stub type and never the other way around. This makes sure that
// we show documentation from the original module and goto definition
Expand All @@ -368,7 +383,7 @@ private static void TransferDocumentationAndLocation(IPythonType s, IPythonType
var transferDoc = true;
if (src is PythonClassType srcClass && dst is PythonClassType dstClass) {
// Higher lever source wins
if(srcClass.DocumentationSource == PythonClassType.ClassDocumentationSource.Class ||
if (srcClass.DocumentationSource == PythonClassType.ClassDocumentationSource.Class ||
(srcClass.DocumentationSource == PythonClassType.ClassDocumentationSource.Init && dstClass.DocumentationSource == PythonClassType.ClassDocumentationSource.Base)) {
dstClass.SetDocumentation(srcClass.Documentation);
transferDoc = false;
Expand Down
1 change: 0 additions & 1 deletion src/Analysis/Ast/Impl/Analyzer/Symbols/ClassEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public void EvaluateClass() {

var bases = ProcessBases();
_class.SetBases(bases);
_class.DecideGeneric();
Copy link
Contributor

Choose a reason for hiding this comment

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

I debated about putting it inside SetBases but opted not to because I felt like the method should only set bases and perhaps some basic validation. If you're going to do this I believe there's another usage of DecideGeneric that becomes redundant here.

Copy link
Author

Choose a reason for hiding this comment

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

SetBases always requires calling DecideGeneric so that's why it makes sense to call it there so someone calling SetBases elsewhere won't forget. There other case is SetGenericParameters which is somewhat different case.

Copy link
Contributor

Choose a reason for hiding this comment

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

classType.SetBases(specificBases.Concat(newBases));
classType._parameters = classType._genericParameters.Values.Distinct().OfType<IGenericTypeParameter>().ToList();
classType.DecideGeneric();

can become:

classType._parameters = classType._genericParameters.Values.Distinct().OfType<IGenericTypeParameter>().ToList();
classType.SetBases(specificBases.Concat(newBases));

Copy link
Author

Choose a reason for hiding this comment

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

classType._parameters is now SetGenericParameters. It is generally bad idea to access private members although it is technically possible in the context of the class itself.

// Declare __class__ variable in the scope.
Eval.DeclareVariable("__class__", _class, VariableSource.Declaration);
ProcessClassBody();
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/Ast/Impl/Analyzer/Symbols/FunctionEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override void Evaluate() {
v => v.GetPythonType<IPythonClassType>() == null &&
v.GetPythonType<IPythonFunctionType>() == null)
) {
((VariableCollection)Eval.CurrentScope.Variables).Clear();
((VariableCollection)Eval.CurrentScope.Variables).Clear();
}
}
}
Expand Down Expand Up @@ -129,7 +129,7 @@ public override bool Walk(ReturnStatement node) {
if (FunctionDefinition.Name.EqualsOrdinal("__init__") && _function.DeclaringType.MemberType == PythonMemberType.Class
&& !value.IsOfType(BuiltinTypeId.NoneType)) {

Eval.ReportDiagnostics(Module.Uri, new Diagnostics.DiagnosticsEntry(
Eval.ReportDiagnostics(Module.Uri, new DiagnosticsEntry(
Resources.ReturnInInit,
node.GetLocation(Eval).Span,
ErrorCodes.ReturnInInit,
Expand Down
2 changes: 0 additions & 2 deletions src/Analysis/Ast/Impl/Extensions/ArgumentSetExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.


using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Python.Analysis.Analyzer.Evaluation;
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/Ast/Impl/Extensions/PythonFunctionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public static IScope GetScope(this IPythonFunctionType f) {
return gs?.TraverseBreadthFirst(s => s.Children).FirstOrDefault(s => s.Node == f.FunctionDefinition);
}

public static string GetQualifiedName(this IPythonClassMember cm) {
public static string GetQualifiedName(this IPythonClassMember cm, string baseName = null) {
var s = new Stack<string>();
s.Push(cm.Name);
s.Push(baseName ?? cm.Name);
for (var p = cm.DeclaringType as IPythonClassMember; p != null; p = p.DeclaringType as IPythonClassMember) {
s.Push(p.Name);
}
Expand Down
Loading