@zzzen/pyright-internal 1.2.0-dev.2022-07-02 → 1.2.0-dev.20220717
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -1
- package/dist/analyzer/aliasDeclarationUtils.js +2 -2
- package/dist/analyzer/analyzerFileInfo.d.ts +2 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/analyzerNodeInfo.d.ts +4 -1
- package/dist/analyzer/analyzerNodeInfo.js +12 -1
- package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
- package/dist/analyzer/binder.d.ts +6 -1
- package/dist/analyzer/binder.js +148 -31
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +4 -1
- package/dist/analyzer/checker.js +176 -90
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +0 -1
- package/dist/analyzer/codeFlowEngine.js +196 -197
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/codeFlowTypes.d.ts +1 -1
- package/dist/analyzer/codeFlowTypes.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +9 -6
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/declaration.d.ts +18 -6
- package/dist/analyzer/declaration.js +19 -9
- package/dist/analyzer/declaration.js.map +1 -1
- package/dist/analyzer/declarationUtils.d.ts +1 -1
- package/dist/analyzer/declarationUtils.js +19 -16
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/functionTransform.js +2 -1
- package/dist/analyzer/functionTransform.js.map +1 -1
- package/dist/analyzer/importResolver.js +3 -2
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +6 -6
- package/dist/analyzer/parseTreeUtils.d.ts +6 -3
- package/dist/analyzer/parseTreeUtils.js +65 -21
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +4 -1
- package/dist/analyzer/parseTreeWalker.js +19 -1
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +1 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +2 -2
- package/dist/analyzer/program.js +1 -1
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +2 -0
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.d.ts +0 -1
- package/dist/analyzer/protocols.js +1 -63
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -2
- package/dist/analyzer/service.js +4 -2
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +6 -1
- package/dist/analyzer/sourceFile.js +57 -14
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/tracePrinter.js +8 -4
- package/dist/analyzer/tracePrinter.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +1 -1
- package/dist/analyzer/typeEvaluator.js +839 -375
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +9 -7
- package/dist/analyzer/typeEvaluatorWithTracker.js +10 -7
- package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
- package/dist/analyzer/typeGuards.js +6 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +4 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.d.ts +4 -1
- package/dist/analyzer/typeStubWriter.js +36 -0
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -2
- package/dist/analyzer/typeUtils.js +94 -13
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.d.ts +1 -0
- package/dist/analyzer/typedDicts.js +25 -2
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +21 -5
- package/dist/analyzer/types.js +87 -11
- package/dist/analyzer/types.js.map +1 -1
- package/dist/common/diagnostic.d.ts +2 -1
- package/dist/common/diagnostic.js +2 -1
- package/dist/common/diagnostic.js.map +1 -1
- package/dist/common/diagnosticSink.d.ts +3 -0
- package/dist/common/diagnosticSink.js +15 -2
- package/dist/common/diagnosticSink.js.map +1 -1
- package/dist/languageServerBase.d.ts +5 -8
- package/dist/languageServerBase.js +30 -18
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.js +1 -1
- package/dist/languageService/callHierarchyProvider.js +9 -9
- package/dist/languageService/completionProvider.d.ts +15 -11
- package/dist/languageService/completionProvider.js +95 -18
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/definitionProvider.js +3 -3
- package/dist/languageService/documentSymbolCollector.js +1 -1
- package/dist/languageService/documentSymbolProvider.js +10 -7
- package/dist/languageService/documentSymbolProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.js +19 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/indentationUtils.js +3 -2
- package/dist/languageService/indentationUtils.js.map +1 -1
- package/dist/languageService/insertionPointUtils.d.ts +9 -0
- package/dist/languageService/insertionPointUtils.js +110 -0
- package/dist/languageService/insertionPointUtils.js.map +1 -0
- package/dist/languageService/referencesProvider.js +8 -5
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +4 -2
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/tooltipUtils.js +2 -4
- package/dist/languageService/tooltipUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +32 -0
- package/dist/localization/localize.js +18 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +20 -2
- package/dist/parser/parseNodes.d.ts +41 -5
- package/dist/parser/parseNodes.js +83 -4
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +5 -1
- package/dist/parser/parser.js +140 -14
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +2 -1
- package/dist/parser/tokenizer.js +7 -5
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +5 -3
- package/dist/parser/tokenizerTypes.js +6 -4
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/pyright.js +3 -1
- package/dist/pyright.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -1
- package/dist/pyrightFileSystem.js +11 -1
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/tests/chainedSourceFiles.test.js +4 -1
- package/dist/tests/chainedSourceFiles.test.js.map +1 -1
- package/dist/tests/fourslash/completions.commitChars.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.commitChars.fourslash.js +47 -0
- package/dist/tests/fourslash/completions.commitChars.fourslash.js.map +1 -0
- package/dist/tests/fourslash/completions.triggers.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/completions.triggers.fourslash.js +29 -0
- package/dist/tests/fourslash/completions.triggers.fourslash.js.map +1 -0
- package/dist/tests/fourslash/fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/import.multipart.fourslash.js +18 -0
- package/dist/tests/fourslash/import.multipart.fourslash.js.map +1 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js +16 -0
- package/dist/tests/fourslash/signature.simple.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +11 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/insertionPointUtils.test.d.ts +1 -0
- package/dist/tests/insertionPointUtils.test.js +74 -0
- package/dist/tests/insertionPointUtils.test.js.map +1 -0
- package/dist/tests/pyrightFileSystem.test.js +28 -0
- package/dist/tests/pyrightFileSystem.test.js.map +1 -1
- package/dist/tests/testUtils.d.ts +2 -1
- package/dist/tests/testUtils.js +10 -6
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +2 -2
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +12 -4
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +9 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +18 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.d.ts +1 -0
- package/dist/tests/typeEvaluator5.test.js +118 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -0
- package/package.json +3 -2
package/dist/parser/parser.js
CHANGED
@@ -32,12 +32,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
32
32
|
};
|
33
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
34
34
|
exports.Parser = exports.ParseOptions = void 0;
|
35
|
+
const sourceFile_1 = require("../analyzer/sourceFile");
|
35
36
|
const collectionUtils_1 = require("../common/collectionUtils");
|
36
37
|
const debug_1 = require("../common/debug");
|
37
38
|
const diagnostic_1 = require("../common/diagnostic");
|
38
39
|
const diagnosticSink_1 = require("../common/diagnosticSink");
|
39
40
|
const positionUtils_1 = require("../common/positionUtils");
|
40
41
|
const pythonVersion_1 = require("../common/pythonVersion");
|
42
|
+
const textRange_1 = require("../common/textRange");
|
41
43
|
const timing_1 = require("../common/timing");
|
42
44
|
const localize_1 = require("../localization/localize");
|
43
45
|
const parseNodes_1 = require("./parseNodes");
|
@@ -50,7 +52,7 @@ class ParseOptions {
|
|
50
52
|
this.pythonVersion = pythonVersion_1.latestStablePythonVersion;
|
51
53
|
this.reportInvalidStringEscapeSequence = false;
|
52
54
|
this.skipFunctionAndClassBody = false;
|
53
|
-
this.ipythonMode =
|
55
|
+
this.ipythonMode = sourceFile_1.IPythonMode.None;
|
54
56
|
this.reportErrorsForParsedStringContents = false;
|
55
57
|
}
|
56
58
|
}
|
@@ -184,13 +186,13 @@ class Parser {
|
|
184
186
|
switch (this._peekKeywordType()) {
|
185
187
|
case 20 /* If */:
|
186
188
|
return this._parseIfStatement();
|
187
|
-
case
|
189
|
+
case 36 /* While */:
|
188
190
|
return this._parseWhileStatement();
|
189
191
|
case 17 /* For */:
|
190
192
|
return this._parseForStatement();
|
191
193
|
case 34 /* Try */:
|
192
194
|
return this._parseTryStatement();
|
193
|
-
case
|
195
|
+
case 37 /* With */:
|
194
196
|
return this._parseWithStatement();
|
195
197
|
case 10 /* Def */:
|
196
198
|
return this._parseFunctionDef();
|
@@ -227,6 +229,7 @@ class Parser {
|
|
227
229
|
return matchStatement;
|
228
230
|
}
|
229
231
|
}
|
232
|
+
break;
|
230
233
|
}
|
231
234
|
}
|
232
235
|
if (this._peekOperatorType() === 22 /* MatrixMultiply */) {
|
@@ -240,7 +243,7 @@ class Parser {
|
|
240
243
|
switch (this._peekKeywordType()) {
|
241
244
|
case 10 /* Def */:
|
242
245
|
return this._parseFunctionDef(asyncToken);
|
243
|
-
case
|
246
|
+
case 37 /* With */:
|
244
247
|
return this._parseWithStatement(asyncToken);
|
245
248
|
case 17 /* For */:
|
246
249
|
return this._parseForStatement(asyncToken);
|
@@ -248,6 +251,87 @@ class Parser {
|
|
248
251
|
this._addError(localize_1.Localizer.Diagnostic.unexpectedAsyncToken(), asyncToken);
|
249
252
|
return undefined;
|
250
253
|
}
|
254
|
+
// type_alias_stmt: "type" name [type_param_seq] = expr
|
255
|
+
_parseTypeAliasStatement() {
|
256
|
+
const typeToken = this._getKeywordToken(35 /* Type */);
|
257
|
+
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_12) {
|
258
|
+
this._addError(localize_1.Localizer.Diagnostic.typeAliasStatementIllegal(), typeToken);
|
259
|
+
}
|
260
|
+
const nameToken = this._getTokenIfIdentifier();
|
261
|
+
(0, debug_1.assert)(nameToken !== undefined);
|
262
|
+
const name = parseNodes_1.NameNode.create(nameToken);
|
263
|
+
let typeParameters;
|
264
|
+
if (this._peekToken().type === 15 /* OpenBracket */) {
|
265
|
+
typeParameters = this._parseTypeParameterList();
|
266
|
+
}
|
267
|
+
const assignToken = this._peekToken();
|
268
|
+
if (assignToken.type !== 9 /* Operator */ ||
|
269
|
+
assignToken.operatorType !== 2 /* Assign */) {
|
270
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedEquals(), assignToken);
|
271
|
+
}
|
272
|
+
else {
|
273
|
+
this._getNextToken();
|
274
|
+
}
|
275
|
+
const expression = this._parseOrTest();
|
276
|
+
return parseNodes_1.TypeAliasNode.create(typeToken, name, expression, typeParameters);
|
277
|
+
}
|
278
|
+
// type_param_seq: '[' (type_param ',')+ ']'
|
279
|
+
_parseTypeParameterList() {
|
280
|
+
const typeVariableNodes = [];
|
281
|
+
const openBracketToken = this._getNextToken();
|
282
|
+
(0, debug_1.assert)(openBracketToken.type === 15 /* OpenBracket */);
|
283
|
+
while (true) {
|
284
|
+
const firstToken = this._peekToken();
|
285
|
+
if (firstToken.type === 16 /* CloseBracket */) {
|
286
|
+
if (typeVariableNodes.length === 0) {
|
287
|
+
this._addError(localize_1.Localizer.Diagnostic.typeParametersMissing(), this._peekToken());
|
288
|
+
}
|
289
|
+
break;
|
290
|
+
}
|
291
|
+
const typeVarNode = this._parseTypeParameter();
|
292
|
+
if (!typeVarNode) {
|
293
|
+
break;
|
294
|
+
}
|
295
|
+
typeVariableNodes.push(typeVarNode);
|
296
|
+
if (!this._consumeTokenIfType(12 /* Comma */)) {
|
297
|
+
break;
|
298
|
+
}
|
299
|
+
}
|
300
|
+
const closingToken = this._peekToken();
|
301
|
+
if (closingToken.type !== 16 /* CloseBracket */) {
|
302
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedCloseBracket(), this._peekToken());
|
303
|
+
this._consumeTokensUntilType([2 /* NewLine */, 16 /* CloseBracket */, 10 /* Colon */]);
|
304
|
+
}
|
305
|
+
else {
|
306
|
+
this._getNextToken();
|
307
|
+
}
|
308
|
+
return parseNodes_1.TypeParameterListNode.create(openBracketToken, closingToken, typeVariableNodes);
|
309
|
+
}
|
310
|
+
// type_param: ['*' | '**'] NAME [':' expr]
|
311
|
+
_parseTypeParameter() {
|
312
|
+
let typeParamCategory = parseNodes_1.TypeParameterCategory.TypeVar;
|
313
|
+
if (this._consumeTokenIfOperator(26 /* Multiply */)) {
|
314
|
+
typeParamCategory = parseNodes_1.TypeParameterCategory.TypeVarTuple;
|
315
|
+
}
|
316
|
+
else if (this._consumeTokenIfOperator(29 /* Power */)) {
|
317
|
+
typeParamCategory = parseNodes_1.TypeParameterCategory.ParamSpec;
|
318
|
+
}
|
319
|
+
const nameToken = this._getTokenIfIdentifier();
|
320
|
+
if (!nameToken) {
|
321
|
+
this._addError(localize_1.Localizer.Diagnostic.expectedTypeParameterName(), this._peekToken());
|
322
|
+
return undefined;
|
323
|
+
}
|
324
|
+
const name = parseNodes_1.NameNode.create(nameToken);
|
325
|
+
let boundExpression;
|
326
|
+
if (this._peekTokenType() === 10 /* Colon */) {
|
327
|
+
this._getNextToken();
|
328
|
+
boundExpression = this._parseTestExpression(/* allowAssignmentExpression */ false);
|
329
|
+
if (typeParamCategory !== parseNodes_1.TypeParameterCategory.TypeVar) {
|
330
|
+
this._addError(localize_1.Localizer.Diagnostic.typeParameterBoundNotAllowed(), boundExpression);
|
331
|
+
}
|
332
|
+
}
|
333
|
+
return parseNodes_1.TypeParameterNode.create(name, typeParamCategory, boundExpression);
|
334
|
+
}
|
251
335
|
// match_stmt: "match" subject_expr ':' NEWLINE INDENT case_block+ DEDENT
|
252
336
|
// subject_expr:
|
253
337
|
// | star_named_expression ',' star_named_expressions?
|
@@ -1137,7 +1221,7 @@ class Parser {
|
|
1137
1221
|
}
|
1138
1222
|
// while_stmt: 'while' test suite ['else' suite]
|
1139
1223
|
_parseWhileStatement() {
|
1140
|
-
const whileToken = this._getKeywordToken(
|
1224
|
+
const whileToken = this._getKeywordToken(36 /* While */);
|
1141
1225
|
const whileNode = parseNodes_1.WhileNode.create(whileToken, this._parseTestExpression(/* allowAssignmentExpression */ true), this._parseLoopSuite());
|
1142
1226
|
if (this._consumeTokenIfKeyword(13 /* Else */)) {
|
1143
1227
|
whileNode.elseSuite = this._parseSuite(this._isInFunction);
|
@@ -1242,6 +1326,14 @@ class Parser {
|
|
1242
1326
|
this._addError(localize_1.Localizer.Diagnostic.expectedFunctionName(), defToken);
|
1243
1327
|
return parseNodes_1.ErrorNode.create(defToken, 10 /* MissingFunctionParameterList */, undefined, decorators);
|
1244
1328
|
}
|
1329
|
+
let typeParameters;
|
1330
|
+
const possibleOpenBracket = this._peekToken();
|
1331
|
+
if (possibleOpenBracket.type === 15 /* OpenBracket */) {
|
1332
|
+
typeParameters = this._parseTypeParameterList();
|
1333
|
+
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_12) {
|
1334
|
+
this._addError(localize_1.Localizer.Diagnostic.functionTypeParametersIllegal(), typeParameters);
|
1335
|
+
}
|
1336
|
+
}
|
1245
1337
|
const openParenToken = this._peekToken();
|
1246
1338
|
if (!this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
1247
1339
|
this._addError(localize_1.Localizer.Diagnostic.expectedOpenParen(), this._peekToken());
|
@@ -1262,7 +1354,7 @@ class Parser {
|
|
1262
1354
|
functionTypeAnnotationToken = this._getTypeAnnotationCommentText();
|
1263
1355
|
}
|
1264
1356
|
});
|
1265
|
-
const functionNode = parseNodes_1.FunctionNode.create(defToken, parseNodes_1.NameNode.create(nameToken), suite);
|
1357
|
+
const functionNode = parseNodes_1.FunctionNode.create(defToken, parseNodes_1.NameNode.create(nameToken), suite, typeParameters);
|
1266
1358
|
if (asyncToken) {
|
1267
1359
|
functionNode.isAsync = true;
|
1268
1360
|
(0, parseNodes_1.extendRange)(functionNode, asyncToken);
|
@@ -1481,7 +1573,7 @@ class Parser {
|
|
1481
1573
|
// Python 3.10 adds support for optional parentheses around
|
1482
1574
|
// with_item list.
|
1483
1575
|
_parseWithStatement(asyncToken) {
|
1484
|
-
const withToken = this._getKeywordToken(
|
1576
|
+
const withToken = this._getKeywordToken(37 /* With */);
|
1485
1577
|
let withItemList = [];
|
1486
1578
|
const possibleParen = this._peekToken();
|
1487
1579
|
// If the expression starts with a paren, parse it as though the
|
@@ -1642,6 +1734,14 @@ class Parser {
|
|
1642
1734
|
this._addError(localize_1.Localizer.Diagnostic.expectedClassName(), this._peekToken());
|
1643
1735
|
nameToken = tokenizerTypes_1.IdentifierToken.create(0, 0, '', /* comments */ undefined);
|
1644
1736
|
}
|
1737
|
+
let typeParameters;
|
1738
|
+
const possibleOpenBracket = this._peekToken();
|
1739
|
+
if (possibleOpenBracket.type === 15 /* OpenBracket */) {
|
1740
|
+
typeParameters = this._parseTypeParameterList();
|
1741
|
+
if (!this._parseOptions.isStubFile && this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_12) {
|
1742
|
+
this._addError(localize_1.Localizer.Diagnostic.classTypeParametersIllegal(), typeParameters);
|
1743
|
+
}
|
1744
|
+
}
|
1645
1745
|
let argList = [];
|
1646
1746
|
const openParenToken = this._peekToken();
|
1647
1747
|
if (this._consumeTokenIfType(13 /* OpenParenthesis */)) {
|
@@ -1651,7 +1751,7 @@ class Parser {
|
|
1651
1751
|
}
|
1652
1752
|
}
|
1653
1753
|
const suite = this._parseSuite(/* isFunction */ false, this._parseOptions.skipFunctionAndClassBody);
|
1654
|
-
const classNode = parseNodes_1.ClassNode.create(classToken, parseNodes_1.NameNode.create(nameToken), suite);
|
1754
|
+
const classNode = parseNodes_1.ClassNode.create(classToken, parseNodes_1.NameNode.create(nameToken), suite, typeParameters);
|
1655
1755
|
classNode.arguments = argList;
|
1656
1756
|
argList.forEach((arg) => {
|
1657
1757
|
arg.parent = classNode;
|
@@ -2008,7 +2108,7 @@ class Parser {
|
|
2008
2108
|
// yield_expr: 'yield' [yield_arg]
|
2009
2109
|
// yield_arg: 'from' test | testlist
|
2010
2110
|
_parseYieldExpression() {
|
2011
|
-
const yieldToken = this._getKeywordToken(
|
2111
|
+
const yieldToken = this._getKeywordToken(38 /* Yield */);
|
2012
2112
|
const nextToken = this._peekToken();
|
2013
2113
|
if (this._consumeTokenIfKeyword(18 /* From */)) {
|
2014
2114
|
if (this._getLanguageVersion() < pythonVersion_1.PythonVersion.V3_3) {
|
@@ -2026,7 +2126,7 @@ class Parser {
|
|
2026
2126
|
return parseNodes_1.YieldNode.create(yieldToken, exprList);
|
2027
2127
|
}
|
2028
2128
|
_tryParseYieldExpression() {
|
2029
|
-
if (this._peekKeywordType() !==
|
2129
|
+
if (this._peekKeywordType() !== 38 /* Yield */) {
|
2030
2130
|
return undefined;
|
2031
2131
|
}
|
2032
2132
|
return this._parseYieldExpression();
|
@@ -2096,8 +2196,28 @@ class Parser {
|
|
2096
2196
|
return this._parseAssertStatement();
|
2097
2197
|
case 11 /* Del */:
|
2098
2198
|
return this._parseDelStatement();
|
2099
|
-
case
|
2199
|
+
case 38 /* Yield */:
|
2100
2200
|
return this._parseYieldExpression();
|
2201
|
+
case 35 /* Type */: {
|
2202
|
+
// Type is considered a "soft" keyword, so we will treat it
|
2203
|
+
// as an identifier if it is followed by an unexpected token.
|
2204
|
+
const peekToken1 = this._peekToken(1);
|
2205
|
+
const peekToken2 = this._peekToken(2);
|
2206
|
+
let isInvalidTypeToken = true;
|
2207
|
+
if (peekToken1.type === 7 /* Identifier */ || peekToken1.type === 8 /* Keyword */) {
|
2208
|
+
if (peekToken2.type === 15 /* OpenBracket */) {
|
2209
|
+
isInvalidTypeToken = false;
|
2210
|
+
}
|
2211
|
+
else if (peekToken2.type === 9 /* Operator */ &&
|
2212
|
+
peekToken2.operatorType === 2 /* Assign */) {
|
2213
|
+
isInvalidTypeToken = false;
|
2214
|
+
}
|
2215
|
+
}
|
2216
|
+
if (!isInvalidTypeToken) {
|
2217
|
+
return this._parseTypeAliasStatement();
|
2218
|
+
}
|
2219
|
+
break;
|
2220
|
+
}
|
2101
2221
|
}
|
2102
2222
|
return this._parseExpressionStatement();
|
2103
2223
|
}
|
@@ -2883,12 +3003,19 @@ class Parser {
|
|
2883
3003
|
// child node can be passed to help the completion provider determine
|
2884
3004
|
// what to do.
|
2885
3005
|
_handleExpressionParseError(category, errorMsg, targetToken, childNode, additionalStopTokens) {
|
3006
|
+
var _a;
|
2886
3007
|
this._addError(errorMsg, targetToken !== null && targetToken !== void 0 ? targetToken : this._peekToken());
|
2887
|
-
const expr = parseNodes_1.ErrorNode.create(this._peekToken(), category, childNode);
|
2888
3008
|
const stopTokens = [2 /* NewLine */];
|
2889
3009
|
if (additionalStopTokens) {
|
2890
3010
|
(0, collectionUtils_1.appendArray)(stopTokens, additionalStopTokens);
|
2891
3011
|
}
|
3012
|
+
// Using token that is not consumed by error node will mess up spans in parse node.
|
3013
|
+
// Sibling nodes in parse tree shouldn't overlap each other.
|
3014
|
+
const nextToken = this._peekToken();
|
3015
|
+
const initialRange = stopTokens.some((k) => nextToken.type === k)
|
3016
|
+
? (_a = targetToken !== null && targetToken !== void 0 ? targetToken : childNode) !== null && _a !== void 0 ? _a : textRange_1.TextRange.create(nextToken.start, /* length */ 0)
|
3017
|
+
: nextToken;
|
3018
|
+
const expr = parseNodes_1.ErrorNode.create(initialRange, category, childNode);
|
2892
3019
|
this._consumeTokensUntilType(stopTokens);
|
2893
3020
|
return expr;
|
2894
3021
|
}
|
@@ -3743,8 +3870,7 @@ class Parser {
|
|
3743
3870
|
// If this is a "soft keyword", it can be converted into an identifier.
|
3744
3871
|
if (nextToken.type === 8 /* Keyword */) {
|
3745
3872
|
const keywordType = this._peekKeywordType();
|
3746
|
-
|
3747
|
-
if (softKeywords.find((type) => type === keywordType)) {
|
3873
|
+
if (tokenizerTypes_1.softKeywords.find((type) => type === keywordType)) {
|
3748
3874
|
const keywordText = this._fileContents.substr(nextToken.start, nextToken.length);
|
3749
3875
|
this._getNextToken();
|
3750
3876
|
return tokenizerTypes_1.IdentifierToken.create(nextToken.start, nextToken.length, keywordText, nextToken.comments);
|