Skip to content

Commit

Permalink
Merge pull request microsoft#1684 from bschnurr/pull-pyright-169
Browse files Browse the repository at this point in the history
pull pyright
  • Loading branch information
jakebailey authored Jul 22, 2021
2 parents d2e5534 + 6c67e8e commit 921ac51
Show file tree
Hide file tree
Showing 381 changed files with 11,178 additions and 1,513 deletions.
2 changes: 1 addition & 1 deletion packages/pylance-internal/bundled/indices/stdlib.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/pyright/.gitrepo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[subrepo]
remote = https://github.com/microsoft/pyright.git
branch = main
commit = 5718a7139a7d4c1e8cc468cbb31ca6c3bca22804
parent = eb339f3dfe9eaab4aaa02f7a18428f153f42c110
commit = 261086ba680e4b6afb3d2edc54e3fb5550efbb40
parent = 01333ec47435ea95e27f2b105d1c4340a53c39be
method = merge
cmdver = 0.4.1
2 changes: 1 addition & 1 deletion packages/pyright/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ The following settings control pyright’s diagnostic output (warnings or errors

**reportIncompleteStub** [boolean or string, optional]: Generate or suppress diagnostics for a module-level `__getattr__` call in a type stub file, indicating that it is incomplete. The default value for this setting is 'none'.

**reportUnsupportedDunderAll** [boolean or string, optional]: Generate or suppress diagnostics for statements that define or manipulate `__all__` in a way that is not allowed by a static type checker, thus rendering the contents of `__all__` to be unknown or incorrect. The default value for this setting is 'warning'.
**reportUnsupportedDunderAll** [boolean or string, optional]: Generate or suppress diagnostics for statements that define or manipulate `__all__` in a way that is not allowed by a static type checker, thus rendering the contents of `__all__` to be unknown or incorrect. Also reports names within the `__all__` list that are not present in the module namespace. The default value for this setting is 'warning'.

**reportUnusedCallResult** [boolean or string, optional]: Generate or suppress diagnostics for call statements whose return value is not used in any way and is not None. The default value for this setting is 'none'.

Expand Down
2 changes: 1 addition & 1 deletion packages/pyright/lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "1.1.156",
"version": "1.1.157",
"command": {
"version": {
"push": false,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/pyright/packages/pyright-internal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pyright-internal",
"displayName": "pyright",
"description": "Type checker for the Python language",
"version": "1.1.156",
"version": "1.1.157",
"license": "MIT",
"private": true,
"files": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ import {
ListComprehensionNode,
ModuleNode,
ParseNode,
StringNode,
} from '../parser/parseNodes';
import { AnalyzerFileInfo } from './analyzerFileInfo';
import { FlowFlags, FlowNode } from './codeFlow';
import { Declaration } from './declaration';
import { ImportResult } from './importResult';
import { Scope } from './scope';

export interface DunderAllInfo {
names: string[];
stringNodes: StringNode[];
}

interface AnalyzerNodeInfo {
//---------------------------------------------------------------
// Set as part of import resolution
Expand Down Expand Up @@ -57,7 +63,7 @@ interface AnalyzerNodeInfo {
codeFlowExpressions?: Map<string, string>;

// List of __all__ symbols in the module.
dunderAllNames?: string[] | undefined;
dunderAllInfo?: DunderAllInfo | undefined;
}

export type ScopedNode = ModuleNode | ClassNode | FunctionNode | LambdaNode | ListComprehensionNode;
Expand Down Expand Up @@ -143,14 +149,14 @@ export function setCodeFlowExpressions(node: ExecutionScopeNode, map: Map<string
analyzerNode.codeFlowExpressions = map;
}

export function getDunderAllNames(node: ModuleNode): string[] | undefined {
export function getDunderAllInfo(node: ModuleNode): DunderAllInfo | undefined {
const analyzerNode = node as AnalyzerNodeInfo;
return analyzerNode.dunderAllNames;
return analyzerNode.dunderAllInfo;
}

export function setDunderAllNames(node: ModuleNode, names: string[] | undefined) {
export function setDunderAllInfo(node: ModuleNode, names: DunderAllInfo | undefined) {
const analyzerNode = node as AnalyzerNodeInfo;
analyzerNode.dunderAllNames = names;
analyzerNode.dunderAllInfo = names;
}

export function isCodeUnreachable(node: ParseNode): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
ReturnNode,
StatementNode,
StringListNode,
StringNode,
SuiteNode,
TernaryNode,
TryNode,
Expand Down Expand Up @@ -188,6 +189,9 @@ export class Binder extends ParseTreeWalker {
// List of names statically assigned to __all__ symbol.
private _dunderAllNames: string[] | undefined;

// List of string nodes associated with the "__all__" symbol.
private _dunderAllStringNodes: StringNode[] = [];

// Flow node that is used for unreachable code.
private static _unreachableFlowNode: FlowNode = {
flags: FlowFlags.Unreachable,
Expand Down Expand Up @@ -255,7 +259,14 @@ export class Binder extends ParseTreeWalker {
}
});

AnalyzerNodeInfo.setDunderAllNames(node, this._dunderAllNames);
if (this._dunderAllNames) {
AnalyzerNodeInfo.setDunderAllInfo(node, {
names: this._dunderAllNames,
stringNodes: this._dunderAllStringNodes,
});
} else {
AnalyzerNodeInfo.setDunderAllInfo(node, undefined);
}

// Set __all__ flags on the module symbols.
const scope = AnalyzerNodeInfo.getScope(node);
Expand Down Expand Up @@ -596,6 +607,7 @@ export class Binder extends ParseTreeWalker {
listEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames?.push(listEntryNode.strings[0].value);
this._dunderAllStringNodes?.push(listEntryNode.strings[0]);
emitDunderAllWarning = false;
}
});
Expand Down Expand Up @@ -623,6 +635,9 @@ export class Binder extends ParseTreeWalker {
this._dunderAllNames
) {
this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.strings[0].value);
this._dunderAllStringNodes = this._dunderAllStringNodes.filter(
(node) => node.value !== argExpr.strings[0].value
);
emitDunderAllWarning = false;
}
} else if (node.leftExpression.memberName.value === 'append' && node.arguments.length === 1) {
Expand All @@ -634,6 +649,7 @@ export class Binder extends ParseTreeWalker {
argExpr.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames?.push(argExpr.strings[0].value);
this._dunderAllStringNodes?.push(argExpr.strings[0]);
emitDunderAllWarning = false;
}
}
Expand Down Expand Up @@ -704,6 +720,7 @@ export class Binder extends ParseTreeWalker {
listEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames!.push(listEntryNode.strings[0].value);
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
} else {
emitDunderAllWarning = true;
}
Expand All @@ -716,6 +733,7 @@ export class Binder extends ParseTreeWalker {
tupleEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames!.push(tupleEntryNode.strings[0].value);
this._dunderAllStringNodes.push(tupleEntryNode.strings[0]);
} else {
emitDunderAllWarning = true;
}
Expand Down Expand Up @@ -859,6 +877,7 @@ export class Binder extends ParseTreeWalker {
listEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames?.push(listEntryNode.strings[0].value);
this._dunderAllStringNodes.push(listEntryNode.strings[0]);
}
});
emitDunderAllWarning = false;
Expand Down
32 changes: 29 additions & 3 deletions packages/pyright/packages/pyright-internal/src/analyzer/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
StatementListNode,
StatementNode,
StringListNode,
StringNode,
SuiteNode,
TernaryNode,
TupleNode,
Expand Down Expand Up @@ -167,9 +168,11 @@ export class Checker extends ParseTreeWalker {
this._walkStatementsAndReportUnreachable(this._moduleNode.statements);

// Mark symbols accessed by __all__ as accessed.
const dunderAllNames = AnalyzerNodeInfo.getDunderAllNames(this._moduleNode);
if (dunderAllNames) {
this._evaluator.markNamesAccessed(this._moduleNode, dunderAllNames);
const dunderAllInfo = AnalyzerNodeInfo.getDunderAllInfo(this._moduleNode);
if (dunderAllInfo) {
this._evaluator.markNamesAccessed(this._moduleNode, dunderAllInfo.names);

this._reportUnusedDunderAllSymbols(dunderAllInfo.stringNodes);
}

// Perform a one-time validation of symbols in all scopes
Expand Down Expand Up @@ -1676,6 +1679,29 @@ export class Checker extends ParseTreeWalker {
return resultingExceptionType || UnknownType.create();
}

private _reportUnusedDunderAllSymbols(nodes: StringNode[]) {
// If this rule is disabled, don't bother doing the work.
if (this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll === 'none') {
return;
}

const moduleScope = AnalyzerNodeInfo.getScope(this._moduleNode);
if (!moduleScope) {
return;
}

nodes.forEach((node) => {
if (!moduleScope.symbolTable.has(node.value)) {
this._evaluator.addDiagnostic(
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
DiagnosticRule.reportUnsupportedDunderAll,
Localizer.Diagnostic.dunderAllSymbolNotPresent().format({ name: node.value }),
node
);
}
});
}

private _validateSymbolTables() {
for (const scopedNode of this._scopedNodes) {
const scope = AnalyzerNodeInfo.getScope(scopedNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ export class Program {

return {
symbolTable,
dunderAllNames: AnalyzerNodeInfo.getDunderAllNames(parseResults!.parseTree),
dunderAllNames: AnalyzerNodeInfo.getDunderAllInfo(parseResults!.parseTree)?.names,
get docString() {
return getDocString(moduleNode.statements);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class SourceFile {
if (this._parseResults) {
if (
this._parseResults.containsWildcardImport ||
AnalyzerNodeInfo.getDunderAllNames(this._parseResults.parseTree)
AnalyzerNodeInfo.getDunderAllInfo(this._parseResults.parseTree) !== undefined
) {
this._parseTreeNeedsCleaning = true;
this._isBindingNeeded = true;
Expand Down
Loading

0 comments on commit 921ac51

Please sign in to comment.