Skip to content

Commit

Permalink
Fixed #135: __init__ arguments for base class are handled incorrectly.
Browse files Browse the repository at this point in the history
  • Loading branch information
msfterictraut committed May 24, 2019
1 parent 39d5cfa commit 8c190d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
15 changes: 3 additions & 12 deletions server/src/analyzer/expressionEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,21 +841,12 @@ export class ExpressionEvaluator {
if (flags & MemberAccessFlags.SkipBaseClasses) {
classLookupFlags |= ClassMemberLookupFlags.SkipBaseClasses;
}
if (flags & MemberAccessFlags.SkipObjectBaseClass) {
classLookupFlags |= ClassMemberLookupFlags.SkipObjectBaseClass;
}
let memberInfo = TypeUtils.lookUpClassMember(classType, memberName,
classLookupFlags);

if (memberInfo) {
// Should we ignore members on the 'object' base class?
if (flags & MemberAccessFlags.SkipObjectBaseClass) {
if (memberInfo.classType instanceof ClassType) {
const classType = memberInfo.classType;
if (classType.isBuiltIn() && classType.getClassName() === 'object') {
memberInfo = undefined;
}
}
}
}

if (memberInfo) {
let type = memberInfo.symbolType;

Expand Down
14 changes: 12 additions & 2 deletions server/src/analyzer/typeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ export enum ClassMemberLookupFlags {
// is performed.
SkipBaseClasses = 0x01,

// Skip the 'object' base class in particular.
SkipObjectBaseClass = 0x02,

// By default, both class and instance variables are searched.
// If this flag is set, the instance variables are skipped.
SkipInstanceVariables = 0x02,
SkipInstanceVariables = 0x04,

// By default, the first symbol is returned even if it has only
// an inferred type associated with it. If this flag is set,
// the search looks only for symbols with declared types.
DeclaredTypesOnly = 0x04
DeclaredTypesOnly = 0x08
}

export interface SymbolWithClass {
Expand Down Expand Up @@ -763,6 +766,13 @@ export class TypeUtils {
if (classType instanceof ClassType) {
// TODO - Switch to true MRO. For now, use naive depth-first search.

// Should we ignore members on the 'object' base class?
if (flags & ClassMemberLookupFlags.SkipObjectBaseClass) {
if (classType.isBuiltIn() && classType.getClassName() === 'object') {
return undefined;
}
}

// Look in the instance fields first if requested.
if ((flags & ClassMemberLookupFlags.SkipInstanceVariables) === 0) {
const instanceFields = classType.getInstanceFields();
Expand Down

0 comments on commit 8c190d2

Please sign in to comment.