mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed bug that causes a false positive reportPrivateUsage
error when a global or nonlocal binding is used within a class to access an outer-scoped variable. This addresses #7884.
This commit is contained in:
parent
e654729d96
commit
e045e1c0a2
@ -1428,6 +1428,7 @@ export class Binder extends ParseTreeWalker {
|
||||
range: convertTextRangeToRange(node.name, this._fileInfo.lines),
|
||||
moduleName: this._fileInfo.moduleName,
|
||||
isInExceptSuite: this._isInExceptSuite,
|
||||
isExplicitBinding: this._currentScope.getBindingType(node.name.value) !== undefined,
|
||||
};
|
||||
symbol.addDeclaration(declaration);
|
||||
}
|
||||
@ -2322,6 +2323,7 @@ export class Binder extends ParseTreeWalker {
|
||||
range: convertTextRangeToRange(node.target, this._fileInfo.lines),
|
||||
moduleName: this._fileInfo.moduleName,
|
||||
isInExceptSuite: this._isInExceptSuite,
|
||||
isExplicitBinding: this._currentScope.getBindingType(node.target.value) !== undefined,
|
||||
};
|
||||
symbol.addDeclaration(declaration);
|
||||
}
|
||||
@ -2392,6 +2394,7 @@ export class Binder extends ParseTreeWalker {
|
||||
range: convertTextRangeToRange(slotNameNode, this._fileInfo.lines),
|
||||
moduleName: this._fileInfo.moduleName,
|
||||
isInExceptSuite: this._isInExceptSuite,
|
||||
isExplicitBinding: this._currentScope.getBindingType(slotName) !== undefined,
|
||||
};
|
||||
symbol.addDeclaration(declaration);
|
||||
}
|
||||
@ -2441,6 +2444,7 @@ export class Binder extends ParseTreeWalker {
|
||||
range: convertTextRangeToRange(target, this._fileInfo.lines),
|
||||
moduleName: this._fileInfo.moduleName,
|
||||
isInExceptSuite: this._isInExceptSuite,
|
||||
isExplicitBinding: this._currentScope.getBindingType(target.value) !== undefined,
|
||||
};
|
||||
symbol.addDeclaration(declaration);
|
||||
}
|
||||
@ -3607,6 +3611,7 @@ export class Binder extends ParseTreeWalker {
|
||||
moduleName: this._fileInfo.moduleName,
|
||||
isInExceptSuite: this._isInExceptSuite,
|
||||
docString: this._getVariableDocString(target),
|
||||
isExplicitBinding: this._currentScope.getBindingType(name.value) !== undefined,
|
||||
};
|
||||
symbolWithScope.symbol.addDeclaration(declaration);
|
||||
}
|
||||
@ -3748,6 +3753,7 @@ export class Binder extends ParseTreeWalker {
|
||||
moduleName: this._fileInfo.moduleName,
|
||||
isInExceptSuite: this._isInExceptSuite,
|
||||
docString: this._getVariableDocString(target),
|
||||
isExplicitBinding: this._currentScope.getBindingType(name.value) !== undefined,
|
||||
};
|
||||
symbolWithScope.symbol.addDeclaration(declaration);
|
||||
|
||||
|
@ -4528,7 +4528,12 @@ export class Checker extends ParseTreeWalker {
|
||||
return;
|
||||
}
|
||||
|
||||
const declarations = this._evaluator.getDeclarationsForNameNode(node);
|
||||
// Get the declarations for this name node, but filter out
|
||||
// any variable declarations that are bound using nonlocal
|
||||
// or global explicit bindings.
|
||||
const declarations = this._evaluator
|
||||
.getDeclarationsForNameNode(node)
|
||||
?.filter((decl) => decl.type !== DeclarationType.Variable || !decl.isExplicitBinding);
|
||||
|
||||
let primaryDeclaration =
|
||||
declarations && declarations.length > 0 ? declarations[declarations.length - 1] : undefined;
|
||||
|
@ -175,6 +175,9 @@ export interface VariableDeclaration extends DeclarationBase {
|
||||
|
||||
// If set, indicates an alternative node to use to determine the type of the variable.
|
||||
alternativeTypeNode?: ExpressionNode;
|
||||
|
||||
// Is the declaration an assignment through an explicit nonlocal or global binding?
|
||||
isExplicitBinding?: boolean;
|
||||
}
|
||||
|
||||
// Alias declarations are used for imports. They are resolved
|
||||
|
Loading…
Reference in New Issue
Block a user