mirror of
https://github.com/microsoft/pyright.git
synced 2024-11-13 09:34:44 +03:00
Implemented new rules for reexports within a py.typed module. ".py" files now follow PEP 484 rules with an override based on __all__
.
This commit is contained in:
parent
5ca499b112
commit
bc298518e7
@ -192,6 +192,10 @@ export class Binder extends ParseTreeWalker {
|
||||
id: getUniqueFlowNodeId(),
|
||||
};
|
||||
|
||||
// Map of symbols at the module level that may be private depending
|
||||
// on whether they are listed in the __all__ list.
|
||||
private _potentialPrivateSymbols = new Map<string, Symbol>();
|
||||
|
||||
constructor(fileInfo: AnalyzerFileInfo) {
|
||||
super();
|
||||
|
||||
@ -237,6 +241,16 @@ export class Binder extends ParseTreeWalker {
|
||||
// Perform all analysis that was deferred during the first pass.
|
||||
this._bindDeferred();
|
||||
|
||||
// Use the __all__ list to determine whether any potential private
|
||||
// symbols should be made externally invisible.
|
||||
this._potentialPrivateSymbols.forEach((symbol, name) => {
|
||||
// If this symbol was found in the dunder all, don't mark it
|
||||
// as externally hidden.
|
||||
if (this._dunderAllNames?.some((sym) => sym === name)) {
|
||||
symbol.setIsExternallyHidden();
|
||||
}
|
||||
});
|
||||
|
||||
AnalyzerNodeInfo.setDunderAllNames(node, this._dunderAllNames);
|
||||
|
||||
return {
|
||||
@ -1260,6 +1274,8 @@ export class Binder extends ParseTreeWalker {
|
||||
// considered "reexported" from a type stub file unless
|
||||
// they are imported using the "as" form.
|
||||
symbol.setIsExternallyHidden();
|
||||
} else if (this._fileInfo.isInPyTypedPackage && this._currentScope.type === ScopeType.Module) {
|
||||
this._potentialPrivateSymbols.set(symbolName, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1422,6 +1438,8 @@ export class Binder extends ParseTreeWalker {
|
||||
// considered "reexported" from a type stub file unless
|
||||
// they are imported using the "as" form.
|
||||
symbol.setIsExternallyHidden();
|
||||
} else if (this._fileInfo.isInPyTypedPackage && this._currentScope.type === ScopeType.Module) {
|
||||
this._potentialPrivateSymbols.set(nameNode.value, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2233,6 +2251,8 @@ export class Binder extends ParseTreeWalker {
|
||||
if (isPrivateOrProtectedName(name)) {
|
||||
if (this._fileInfo.isStubFile) {
|
||||
symbol.setIsExternallyHidden();
|
||||
} else if (this._fileInfo.isInPyTypedPackage && this._currentScope.type === ScopeType.Module) {
|
||||
this._potentialPrivateSymbols.set(name, symbol);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user