Skip to content

Commit

Permalink
Merge pull request microsoft#765 from jakebailey/pull-pyright-94
Browse files Browse the repository at this point in the history
Pull pyright 1.1.89 and more
  • Loading branch information
jakebailey authored Nov 30, 2020
2 parents d7f5ff4 + df73f26 commit 23fd0ea
Show file tree
Hide file tree
Showing 87 changed files with 4,125 additions and 2,119 deletions.
2 changes: 1 addition & 1 deletion 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 = master
commit = a9d2528574087cc2f8c10a7c3aaeb287eb64a870
commit = 686d47de5da3290039e1d4a63a17fd51ced94399
parent = 151710c05972a651d7c9e8571b767fed18750973
method = merge
cmdver = 0.4.1
20 changes: 0 additions & 20 deletions packages/pyright/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,6 @@
"${workspaceRoot}/packages/vscode-pyright/dist/**/*.js"
]
},
{
"name": "Pyright extension (watch mode)",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/packages/vscode-pyright/dist/extension.js",
"preLaunchTask": "Watch extension",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/packages/vscode-pyright",
// The published extension is named "ms-pyright.pyright", but in debug mode it's "ms-pyright.vscode-pyright"
// to allow the extension code to participate in the lerna monorepo. Make sure that the published extension
// isn't enabled, otherwise both are loaded and conflict.
"--disable-extension=ms-pyright.pyright"
],
"stopOnEntry": false,
"smartStep": true,
"sourceMaps": true,
"outFiles": [
"${workspaceRoot}/packages/vscode-pyright/dist/**/*.js"
]
},
{
"name": "Pyright attach server",
"type": "node",
Expand Down
6 changes: 6 additions & 0 deletions packages/pyright/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The following settings control pyright’s diagnostic output (warnings or errors

**reportPropertyTypeMismatch** [boolean or string, optional]: Generate or suppress diagnostics for properties where the type of the value passed to the setter is not assignable to the value returned by the getter. Such mismatches violate the intended use of properties, which are meant to act like variables. The default value for this setting is 'error'.

**reportFunctionMemberAccess** [boolean or string, optional]: Generate or suppress diagnostics for non-standard member accesses for functions. The default value for this setting is 'none'.

**reportMissingImports** [boolean or string, optional]: Generate or suppress diagnostics for imports that have no corresponding imported python file or type stub file. The default value for this setting is 'none', although pyright can do a much better job of static type checking if type stub files are provided for all imports.

**reportMissingModuleSource** [boolean or string, optional]: Generate or suppress diagnostics for imports that have no corresponding source file. This happens when a type stub is found, but the module source file was not found, indicating that the code may fail at runtime when using this execution environment. Type checking will be done using the type stub. The default value for this setting is 'warning'.
Expand Down Expand Up @@ -130,6 +132,10 @@ The following settings control pyright’s diagnostic output (warnings or errors

**reportInvalidStubStatement** [boolean or string, optional]: Generate or suppress diagnostics for statements that are syntactically correct but have no purpose within a type stub file. 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'.

**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'.


## Execution Environment Options
Pyright allows multiple “execution environments” to be defined for different portions of your source tree. For example, a subtree may be designed to run with different import search paths or a different version of the python interpreter than the rest of the source base.
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.86",
"version": "1.1.89",
"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.86",
"version": "1.1.89",
"license": "MIT",
"private": true,
"files": [
Expand Down
69 changes: 66 additions & 3 deletions packages/pyright/packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import { CreateTypeStubFileAction, Diagnostic } from '../common/diagnostic';
import { DiagnosticRule } from '../common/diagnosticRules';
import { getFileName, stripFileExtension } from '../common/pathUtils';
import { convertOffsetsToRange } from '../common/positionUtils';
import { PythonVersion } from '../common/pythonVersion';
import { getEmptyRange } from '../common/textRange';
import { TextRange } from '../common/textRange';
import { Localizer } from '../localization/localize';
Expand Down Expand Up @@ -86,6 +85,7 @@ import {
FlowNode,
FlowPostFinally,
FlowPreFinallyGate,
FlowVariableAnnotation,
FlowWildcardImport,
getUniqueFlowNodeId,
isCodeFlowSupportedForReference,
Expand Down Expand Up @@ -567,6 +567,8 @@ export class Binder extends ParseTreeWalker {
node.leftExpression.leftExpression.nodeType === ParseNodeType.Name &&
node.leftExpression.leftExpression.value === '__all__'
) {
let emitDunderAllWarning = true;

// Is this a call to "__all__.extend()"?
if (node.leftExpression.memberName.value === 'extend' && node.arguments.length === 1) {
const argExpr = node.arguments[0].valueExpression;
Expand All @@ -580,6 +582,7 @@ export class Binder extends ParseTreeWalker {
listEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames?.push(listEntryNode.strings[0].value);
emitDunderAllWarning = false;
}
});
} else if (
Expand All @@ -589,10 +592,11 @@ export class Binder extends ParseTreeWalker {
) {
// Is this a call to "__all__.extend(<mod>.__all__)"?
const namesToAdd = this._getDunderAllNamesFromImport(argExpr.leftExpression.value);
if (namesToAdd) {
if (namesToAdd && namesToAdd.length > 0) {
namesToAdd.forEach((name) => {
this._dunderAllNames?.push(name);
});
emitDunderAllWarning = false;
}
}
} else if (node.leftExpression.memberName.value === 'remove' && node.arguments.length === 1) {
Expand All @@ -605,6 +609,7 @@ export class Binder extends ParseTreeWalker {
this._dunderAllNames
) {
this._dunderAllNames = this._dunderAllNames.filter((name) => name !== argExpr.strings[0].value);
emitDunderAllWarning = false;
}
} else if (node.leftExpression.memberName.value === 'append' && node.arguments.length === 1) {
// Is this a call to "__all__.append()"?
Expand All @@ -615,8 +620,18 @@ export class Binder extends ParseTreeWalker {
argExpr.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames?.push(argExpr.strings[0].value);
emitDunderAllWarning = false;
}
}

if (emitDunderAllWarning) {
this._addDiagnostic(
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
DiagnosticRule.reportUnsupportedDunderAll,
Localizer.Diagnostic.unsupportedDunderAllOperation(),
node
);
}
}

return false;
Expand Down Expand Up @@ -661,6 +676,7 @@ export class Binder extends ParseTreeWalker {
) {
const expr = node.rightExpression;
this._dunderAllNames = [];
let emitDunderAllWarning = false;

if (expr.nodeType === ParseNodeType.List) {
expr.entries.forEach((listEntryNode) => {
Expand All @@ -670,6 +686,8 @@ export class Binder extends ParseTreeWalker {
listEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames!.push(listEntryNode.strings[0].value);
} else {
emitDunderAllWarning = true;
}
});
} else if (expr.nodeType === ParseNodeType.Tuple) {
Expand All @@ -680,8 +698,21 @@ export class Binder extends ParseTreeWalker {
tupleEntryNode.strings[0].nodeType === ParseNodeType.String
) {
this._dunderAllNames!.push(tupleEntryNode.strings[0].value);
} else {
emitDunderAllWarning = true;
}
});
} else {
emitDunderAllWarning = true;
}

if (emitDunderAllWarning) {
this._addDiagnostic(
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
DiagnosticRule.reportUnsupportedDunderAll,
Localizer.Diagnostic.unsupportedDunderAllOperation(),
node
);
}
}
}
Expand Down Expand Up @@ -751,6 +782,7 @@ export class Binder extends ParseTreeWalker {
node.leftExpression.value === '__all__'
) {
const expr = node.rightExpression;
let emitDunderAllWarning = true;

if (expr.nodeType === ParseNodeType.List) {
// Is this the form __all__ += ["a", "b"]?
Expand All @@ -763,6 +795,7 @@ export class Binder extends ParseTreeWalker {
this._dunderAllNames?.push(listEntryNode.strings[0].value);
}
});
emitDunderAllWarning = false;
} else if (
expr.nodeType === ParseNodeType.MemberAccess &&
expr.leftExpression.nodeType === ParseNodeType.Name &&
Expand All @@ -774,8 +807,19 @@ export class Binder extends ParseTreeWalker {
namesToAdd.forEach((name) => {
this._dunderAllNames?.push(name);
});

emitDunderAllWarning = false;
}
}

if (emitDunderAllWarning) {
this._addDiagnostic(
this._fileInfo.diagnosticRuleSet.reportUnsupportedDunderAll,
DiagnosticRule.reportUnsupportedDunderAll,
Localizer.Diagnostic.unsupportedDunderAllOperation(),
node
);
}
}

return false;
Expand All @@ -796,6 +840,11 @@ export class Binder extends ParseTreeWalker {
return false;
}

// Walk the type annotation first so it is "before" the target
// in the code flow graph.
this.walk(node.typeAnnotation);
this._createVariableAnnotationFlowNode();

this._bindPossibleTupleNamedTarget(node.valueExpression);
this._addTypeDeclarationForVariable(node.valueExpression, node.typeAnnotation);

Expand All @@ -810,7 +859,9 @@ export class Binder extends ParseTreeWalker {
this._currentExecutionScopeReferenceMap!.set(referenceKey, referenceKey);
});
}
return true;

this.walk(node.valueExpression);
return false;
}

visitFor(node: ForNode) {
Expand Down Expand Up @@ -2191,6 +2242,18 @@ export class Binder extends ParseTreeWalker {
}
}

private _createVariableAnnotationFlowNode() {
if (!this._isCodeUnreachable()) {
const flowNode: FlowVariableAnnotation = {
flags: FlowFlags.VariableAnnotation,
id: getUniqueFlowNodeId(),
antecedent: this._currentFlowNode!,
};

this._currentFlowNode = flowNode;
}
}

private _createFlowAssignment(node: NameNode | MemberAccessNode, unbound = false) {
let targetSymbolId = indeterminateSymbolId;
if (node.nodeType === ParseNodeType.Name) {
Expand Down
Loading

0 comments on commit 23fd0ea

Please sign in to comment.