@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/analyzer/binder.js
CHANGED
@@ -65,6 +65,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
65
65
|
this._moduleSymbolOnly = _moduleSymbolOnly;
|
66
66
|
// A queue of deferred analysis operations.
|
67
67
|
this._deferredBindingTasks = [];
|
68
|
+
// Tracks the type parameters that are currently active within the
|
69
|
+
// scope and any outer scopes.
|
70
|
+
this._activeTypeParams = new Map();
|
68
71
|
// Flow nodes used within try blocks.
|
69
72
|
this._currentExceptTargets = [];
|
70
73
|
// Flow nodes used within try/finally flows.
|
@@ -207,19 +210,22 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
207
210
|
visitClass(node) {
|
208
211
|
this.walkMultiple(node.decorators);
|
209
212
|
const classDeclaration = {
|
210
|
-
type:
|
213
|
+
type: 6 /* Class */,
|
211
214
|
node,
|
212
215
|
path: this._fileInfo.filePath,
|
213
216
|
range: (0, positionUtils_1.convertOffsetsToRange)(node.name.start, textRange_2.TextRange.getEnd(node.name), this._fileInfo.lines),
|
214
217
|
moduleName: this._fileInfo.moduleName,
|
215
218
|
isInExceptSuite: this._isInExceptSuite,
|
216
219
|
};
|
217
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name
|
220
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
218
221
|
if (symbol) {
|
219
222
|
symbol.addDeclaration(classDeclaration);
|
220
223
|
}
|
221
224
|
// Stash the declaration in the parse node for later access.
|
222
225
|
AnalyzerNodeInfo.setDeclaration(node, classDeclaration);
|
226
|
+
if (node.typeParameters) {
|
227
|
+
this.walk(node.typeParameters);
|
228
|
+
}
|
223
229
|
this.walkMultiple(node.arguments);
|
224
230
|
this._createNewScope(2 /* Class */, this._getNonClassParentScope(), () => {
|
225
231
|
AnalyzerNodeInfo.setScope(node, this._currentScope);
|
@@ -236,15 +242,18 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
236
242
|
this._dunderSlotsEntries = undefined;
|
237
243
|
});
|
238
244
|
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
|
245
|
+
if (node.typeParameters) {
|
246
|
+
this._removeActiveTypeParameters(node.typeParameters);
|
247
|
+
}
|
239
248
|
return false;
|
240
249
|
}
|
241
250
|
visitFunction(node) {
|
242
251
|
this._createVariableAnnotationFlowNode();
|
243
252
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
244
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name
|
253
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
245
254
|
const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
|
246
255
|
const functionDeclaration = {
|
247
|
-
type:
|
256
|
+
type: 5 /* Function */,
|
248
257
|
node,
|
249
258
|
isMethod: !!containingClassNode,
|
250
259
|
isGenerator: false,
|
@@ -258,11 +267,17 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
258
267
|
}
|
259
268
|
// Stash the declaration in the parse node for later access.
|
260
269
|
AnalyzerNodeInfo.setDeclaration(node, functionDeclaration);
|
261
|
-
|
270
|
+
// Walk the default values prior to the type parameters.
|
262
271
|
node.parameters.forEach((param) => {
|
263
272
|
if (param.defaultValue) {
|
264
273
|
this.walk(param.defaultValue);
|
265
274
|
}
|
275
|
+
});
|
276
|
+
if (node.typeParameters) {
|
277
|
+
this.walk(node.typeParameters);
|
278
|
+
}
|
279
|
+
this.walkMultiple(node.decorators);
|
280
|
+
node.parameters.forEach((param) => {
|
266
281
|
if (param.typeAnnotation) {
|
267
282
|
this.walk(param.typeAnnotation);
|
268
283
|
}
|
@@ -291,7 +306,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
291
306
|
this._codeFlowComplexity = 0;
|
292
307
|
node.parameters.forEach((paramNode) => {
|
293
308
|
if (paramNode.name) {
|
294
|
-
const symbol = this._bindNameToScope(this._currentScope, paramNode.name
|
309
|
+
const symbol = this._bindNameToScope(this._currentScope, paramNode.name);
|
295
310
|
if (symbol) {
|
296
311
|
const paramDeclaration = {
|
297
312
|
type: 2 /* Parameter */,
|
@@ -325,6 +340,9 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
325
340
|
});
|
326
341
|
});
|
327
342
|
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ false, /* unbound */ false);
|
343
|
+
if (node.typeParameters) {
|
344
|
+
this._removeActiveTypeParameters(node.typeParameters);
|
345
|
+
}
|
328
346
|
// We'll walk the child nodes in a deferred manner, so don't walk them now.
|
329
347
|
return false;
|
330
348
|
}
|
@@ -345,7 +363,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
345
363
|
this._currentFlowNode = this._createStartFlowNode();
|
346
364
|
node.parameters.forEach((paramNode) => {
|
347
365
|
if (paramNode.name) {
|
348
|
-
const symbol = this._bindNameToScope(this._currentScope, paramNode.name
|
366
|
+
const symbol = this._bindNameToScope(this._currentScope, paramNode.name);
|
349
367
|
if (symbol) {
|
350
368
|
const paramDeclaration = {
|
351
369
|
type: 2 /* Parameter */,
|
@@ -360,6 +378,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
360
378
|
}
|
361
379
|
this._createFlowAssignment(paramNode.name);
|
362
380
|
this.walk(paramNode.name);
|
381
|
+
AnalyzerNodeInfo.setFlowNode(paramNode, this._currentFlowNode);
|
363
382
|
}
|
364
383
|
});
|
365
384
|
// Walk the expression that make up the lambda body.
|
@@ -455,6 +474,62 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
455
474
|
}
|
456
475
|
return false;
|
457
476
|
}
|
477
|
+
visitTypeParameterList(node) {
|
478
|
+
node.parameters.forEach((param) => {
|
479
|
+
if (param.boundExpression) {
|
480
|
+
this.walk(param.boundExpression);
|
481
|
+
}
|
482
|
+
});
|
483
|
+
node.parameters.forEach((param) => {
|
484
|
+
const name = param.name;
|
485
|
+
const symbol = new symbol_1.Symbol(0 /* None */);
|
486
|
+
const paramDeclaration = {
|
487
|
+
type: 3 /* TypeParameter */,
|
488
|
+
node: param,
|
489
|
+
path: this._fileInfo.filePath,
|
490
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(node.start, textRange_2.TextRange.getEnd(node), this._fileInfo.lines),
|
491
|
+
moduleName: this._fileInfo.moduleName,
|
492
|
+
isInExceptSuite: this._isInExceptSuite,
|
493
|
+
};
|
494
|
+
symbol.addDeclaration(paramDeclaration);
|
495
|
+
AnalyzerNodeInfo.setDeclaration(name, paramDeclaration);
|
496
|
+
AnalyzerNodeInfo.setTypeParameterSymbol(name, symbol);
|
497
|
+
if (this._activeTypeParams.has(name.value)) {
|
498
|
+
this._addError(localize_1.Localizer.Diagnostic.typeParameterExistingTypeParameter().format({ name: name.value }), name);
|
499
|
+
}
|
500
|
+
else {
|
501
|
+
this._activeTypeParams.set(name.value, symbol);
|
502
|
+
}
|
503
|
+
});
|
504
|
+
return false;
|
505
|
+
}
|
506
|
+
visitTypeAlias(node) {
|
507
|
+
this._bindNameToScope(this._currentScope, node.name);
|
508
|
+
this.walk(node.name);
|
509
|
+
if (node.typeParameters) {
|
510
|
+
this.walk(node.typeParameters);
|
511
|
+
}
|
512
|
+
const typeAliasDeclaration = {
|
513
|
+
type: 4 /* TypeAlias */,
|
514
|
+
node,
|
515
|
+
path: this._fileInfo.filePath,
|
516
|
+
range: (0, positionUtils_1.convertOffsetsToRange)(node.name.start, textRange_2.TextRange.getEnd(node.name), this._fileInfo.lines),
|
517
|
+
moduleName: this._fileInfo.moduleName,
|
518
|
+
isInExceptSuite: this._isInExceptSuite,
|
519
|
+
};
|
520
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
521
|
+
if (symbol) {
|
522
|
+
symbol.addDeclaration(typeAliasDeclaration);
|
523
|
+
}
|
524
|
+
// Stash the declaration in the parse node for later access.
|
525
|
+
AnalyzerNodeInfo.setDeclaration(node, typeAliasDeclaration);
|
526
|
+
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
527
|
+
this.walk(node.expression);
|
528
|
+
if (node.typeParameters) {
|
529
|
+
this._removeActiveTypeParameters(node.typeParameters);
|
530
|
+
}
|
531
|
+
return false;
|
532
|
+
}
|
458
533
|
visitAssignment(node) {
|
459
534
|
if (this._handleTypingStubAssignmentOrAnnotation(node)) {
|
460
535
|
return false;
|
@@ -475,6 +550,20 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
475
550
|
this._createAssignmentTargetFlowNodes(node.leftExpression, /* walkTargets */ true, /* unbound */ false);
|
476
551
|
createdAssignmentTargetFlowNodes = true;
|
477
552
|
}
|
553
|
+
// If the assignment target base expression is potentially a
|
554
|
+
// TypedDict, add the base expression to the flow expressions set
|
555
|
+
// to accommodate TypedDict type narrowing.
|
556
|
+
if (node.leftExpression.nodeType === 24 /* Index */) {
|
557
|
+
const target = node.leftExpression;
|
558
|
+
if (target.items.length === 1 &&
|
559
|
+
!target.trailingComma &&
|
560
|
+
target.items[0].valueExpression.nodeType === 48 /* StringList */) {
|
561
|
+
if ((0, codeFlowTypes_1.isCodeFlowSupportedForReference)(target.baseExpression)) {
|
562
|
+
const baseExprReferenceKey = (0, codeFlowTypes_1.createKeyForReference)(target.baseExpression);
|
563
|
+
this._currentScopeCodeFlowExpressions.add(baseExprReferenceKey);
|
564
|
+
}
|
565
|
+
}
|
566
|
+
}
|
478
567
|
this.walk(node.rightExpression);
|
479
568
|
let isPossibleTypeAlias = true;
|
480
569
|
if (ParseTreeUtils.getEnclosingFunction(node)) {
|
@@ -617,7 +706,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
617
706
|
}
|
618
707
|
curScope = curScope.parent;
|
619
708
|
}
|
620
|
-
this._bindNameToScope(containerScope, node.name
|
709
|
+
this._bindNameToScope(containerScope, node.name);
|
621
710
|
this._addInferredTypeAssignmentForVariable(node.name, node.rightExpression);
|
622
711
|
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
623
712
|
}
|
@@ -794,6 +883,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
794
883
|
}
|
795
884
|
visitName(node) {
|
796
885
|
AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
|
886
|
+
const typeParamSymbol = this._activeTypeParams.get(node.value);
|
887
|
+
if (typeParamSymbol) {
|
888
|
+
AnalyzerNodeInfo.setTypeParameterSymbol(node, typeParamSymbol);
|
889
|
+
}
|
797
890
|
// Name nodes have no children.
|
798
891
|
return false;
|
799
892
|
}
|
@@ -876,7 +969,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
876
969
|
}
|
877
970
|
if (node.name) {
|
878
971
|
this.walk(node.name);
|
879
|
-
const symbol = this._bindNameToScope(this._currentScope, node.name
|
972
|
+
const symbol = this._bindNameToScope(this._currentScope, node.name);
|
880
973
|
this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
|
881
974
|
if (symbol) {
|
882
975
|
const declaration = {
|
@@ -1047,7 +1140,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1047
1140
|
// Make sure this is within an async lambda or function.
|
1048
1141
|
const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
|
1049
1142
|
if (enclosingFunction === undefined || !enclosingFunction.isAsync) {
|
1050
|
-
if (this._fileInfo.
|
1143
|
+
if (this._fileInfo.ipythonMode && enclosingFunction === undefined) {
|
1051
1144
|
// Top level await is allowed in ipython mode.
|
1052
1145
|
return true;
|
1053
1146
|
}
|
@@ -1074,7 +1167,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1074
1167
|
this._addError(localize_1.Localizer.Diagnostic.globalReassignment().format({ name: nameValue }), name);
|
1075
1168
|
}
|
1076
1169
|
// Add it to the global scope if it's not already added.
|
1077
|
-
this._bindNameToScope(globalScope,
|
1170
|
+
this._bindNameToScope(globalScope, name);
|
1078
1171
|
if (this._currentScope !== globalScope) {
|
1079
1172
|
this._currentScope.setBindingType(nameValue, 1 /* Global */);
|
1080
1173
|
}
|
@@ -1113,16 +1206,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1113
1206
|
if (node.module.nameParts.length > 0) {
|
1114
1207
|
const firstNamePartValue = node.module.nameParts[0].value;
|
1115
1208
|
let symbolName;
|
1209
|
+
let symbolNameNode;
|
1116
1210
|
if (node.alias) {
|
1117
1211
|
// The symbol name is defined by the alias.
|
1118
1212
|
symbolName = node.alias.value;
|
1213
|
+
symbolNameNode = node.alias;
|
1119
1214
|
}
|
1120
1215
|
else {
|
1121
1216
|
// There was no alias, so we need to use the first element of
|
1122
1217
|
// the name parts as the symbol.
|
1123
1218
|
symbolName = firstNamePartValue;
|
1219
|
+
symbolNameNode = node.module.nameParts[0];
|
1124
1220
|
}
|
1125
|
-
const symbol = this._bindNameToScope(this._currentScope,
|
1221
|
+
const symbol = this._bindNameToScope(this._currentScope, symbolNameNode);
|
1126
1222
|
if (symbol &&
|
1127
1223
|
(this._currentScope.type === 3 /* Module */ || this._currentScope.type === 4 /* Builtin */) &&
|
1128
1224
|
(!node.alias ||
|
@@ -1203,14 +1299,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1203
1299
|
}
|
1204
1300
|
}
|
1205
1301
|
wildcardNames.forEach((name) => {
|
1206
|
-
const localSymbol = this.
|
1302
|
+
const localSymbol = this._bindNameValueToScope(this._currentScope, name);
|
1207
1303
|
if (localSymbol) {
|
1208
1304
|
const importedSymbol = lookupInfo.symbolTable.get(name);
|
1209
1305
|
// Is the symbol in the target module's symbol table? If so,
|
1210
1306
|
// alias it.
|
1211
1307
|
if (importedSymbol) {
|
1212
1308
|
const aliasDecl = {
|
1213
|
-
type:
|
1309
|
+
type: 8 /* Alias */,
|
1214
1310
|
node,
|
1215
1311
|
path: resolvedPath,
|
1216
1312
|
loadSymbolsFromPath: true,
|
@@ -1230,7 +1326,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1230
1326
|
const implicitImport = importInfo.filteredImplicitImports.find((imp) => imp.name === name);
|
1231
1327
|
if (implicitImport) {
|
1232
1328
|
const submoduleFallback = {
|
1233
|
-
type:
|
1329
|
+
type: 8 /* Alias */,
|
1234
1330
|
node,
|
1235
1331
|
path: implicitImport.path,
|
1236
1332
|
loadSymbolsFromPath: true,
|
@@ -1240,7 +1336,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1240
1336
|
isInExceptSuite: this._isInExceptSuite,
|
1241
1337
|
};
|
1242
1338
|
const aliasDecl = {
|
1243
|
-
type:
|
1339
|
+
type: 8 /* Alias */,
|
1244
1340
|
node,
|
1245
1341
|
path: resolvedPath,
|
1246
1342
|
loadSymbolsFromPath: true,
|
@@ -1278,7 +1374,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1278
1374
|
node.imports.forEach((importSymbolNode) => {
|
1279
1375
|
const importedName = importSymbolNode.name.value;
|
1280
1376
|
const nameNode = importSymbolNode.alias || importSymbolNode.name;
|
1281
|
-
const symbol = this._bindNameToScope(this._currentScope, nameNode
|
1377
|
+
const symbol = this._bindNameToScope(this._currentScope, nameNode);
|
1282
1378
|
if (symbol) {
|
1283
1379
|
// All import statements of the form `from . import x` treat x
|
1284
1380
|
// as an externally-visible (not hidden) symbol.
|
@@ -1306,7 +1402,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1306
1402
|
let loadSymbolsFromPath = true;
|
1307
1403
|
if (implicitImport) {
|
1308
1404
|
submoduleFallback = {
|
1309
|
-
type:
|
1405
|
+
type: 8 /* Alias */,
|
1310
1406
|
node: importSymbolNode,
|
1311
1407
|
path: implicitImport.path,
|
1312
1408
|
loadSymbolsFromPath: true,
|
@@ -1325,7 +1421,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1325
1421
|
}
|
1326
1422
|
}
|
1327
1423
|
const aliasDecl = {
|
1328
|
-
type:
|
1424
|
+
type: 8 /* Alias */,
|
1329
1425
|
node: importSymbolNode,
|
1330
1426
|
path: resolvedPath,
|
1331
1427
|
loadSymbolsFromPath,
|
@@ -1605,7 +1701,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1605
1701
|
this._currentFlowNode = this._finishFlowLabel(postOrLabel);
|
1606
1702
|
if (node.target) {
|
1607
1703
|
this.walk(node.target);
|
1608
|
-
const symbol = this._bindNameToScope(this._currentScope, node.target
|
1704
|
+
const symbol = this._bindNameToScope(this._currentScope, node.target);
|
1609
1705
|
this._createAssignmentTargetFlowNodes(node.target, /* walkTargets */ false, /* unbound */ false);
|
1610
1706
|
if (symbol) {
|
1611
1707
|
const declaration = {
|
@@ -1635,6 +1731,18 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1635
1731
|
}
|
1636
1732
|
return true;
|
1637
1733
|
}
|
1734
|
+
_removeActiveTypeParameters(node) {
|
1735
|
+
node.parameters.forEach((typeParamNode) => {
|
1736
|
+
const entry = this._activeTypeParams.get(typeParamNode.name.value);
|
1737
|
+
if (entry) {
|
1738
|
+
const decls = entry.getDeclarations();
|
1739
|
+
(0, debug_1.assert)(decls && decls.length === 1 && decls[0].type === 3 /* TypeParameter */);
|
1740
|
+
if (decls[0].node === typeParamNode) {
|
1741
|
+
this._activeTypeParams.delete(typeParamNode.name.value);
|
1742
|
+
}
|
1743
|
+
}
|
1744
|
+
});
|
1745
|
+
}
|
1638
1746
|
_getNonClassParentScope() {
|
1639
1747
|
// We may not be able to use the current scope if it's a class scope.
|
1640
1748
|
// Walk up until we find a non-class scope instead.
|
@@ -1700,7 +1808,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1700
1808
|
return false;
|
1701
1809
|
}
|
1702
1810
|
_addPatternCaptureTarget(target) {
|
1703
|
-
const symbol = this._bindNameToScope(this._currentScope, target
|
1811
|
+
const symbol = this._bindNameToScope(this._currentScope, target);
|
1704
1812
|
this._createAssignmentTargetFlowNodes(target, /* walkTargets */ false, /* unbound */ false);
|
1705
1813
|
if (symbol) {
|
1706
1814
|
const declaration = {
|
@@ -1731,7 +1839,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1731
1839
|
return undefined;
|
1732
1840
|
}
|
1733
1841
|
// There should be only one declaration for the variable.
|
1734
|
-
const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type ===
|
1842
|
+
const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === 8 /* Alias */);
|
1735
1843
|
const resolvedPath = (aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.path) && aliasDecl.loadSymbolsFromPath
|
1736
1844
|
? aliasDecl.path
|
1737
1845
|
: ((_a = aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.submoduleFallback) === null || _a === void 0 ? void 0 : _a.path) && aliasDecl.submoduleFallback.loadSymbolsFromPath
|
@@ -1748,7 +1856,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1748
1856
|
}
|
1749
1857
|
_addImplicitFromImport(node, importInfo) {
|
1750
1858
|
const symbolName = node.module.nameParts[0].value;
|
1751
|
-
const symbol = this.
|
1859
|
+
const symbol = this._bindNameValueToScope(this._currentScope, symbolName);
|
1752
1860
|
if (symbol) {
|
1753
1861
|
this._createAliasDeclarationForMultipartImportName(node, /* importAlias */ undefined, importInfo, symbol);
|
1754
1862
|
}
|
@@ -1766,7 +1874,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1766
1874
|
// python module loader.
|
1767
1875
|
const existingDecl = symbol
|
1768
1876
|
.getDeclarations()
|
1769
|
-
.find((decl) => decl.type ===
|
1877
|
+
.find((decl) => decl.type === 8 /* Alias */ && decl.firstNamePart === firstNamePartValue);
|
1770
1878
|
let newDecl;
|
1771
1879
|
let pathOfLastSubmodule;
|
1772
1880
|
if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0) {
|
@@ -1781,7 +1889,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1781
1889
|
}
|
1782
1890
|
else if (isResolved) {
|
1783
1891
|
newDecl = {
|
1784
|
-
type:
|
1892
|
+
type: 8 /* Alias */,
|
1785
1893
|
node,
|
1786
1894
|
path: pathOfLastSubmodule,
|
1787
1895
|
loadSymbolsFromPath: false,
|
@@ -1797,7 +1905,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
1797
1905
|
// bogus path so it gets an unknown type (rather than an unbound type) at
|
1798
1906
|
// analysis time.
|
1799
1907
|
newDecl = {
|
1800
|
-
type:
|
1908
|
+
type: 8 /* Alias */,
|
1801
1909
|
node,
|
1802
1910
|
path: pathOfLastSubmodule,
|
1803
1911
|
loadSymbolsFromPath: true,
|
@@ -2388,7 +2496,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2388
2496
|
}
|
2389
2497
|
}
|
2390
2498
|
}
|
2391
|
-
_bindNameToScope(scope,
|
2499
|
+
_bindNameToScope(scope, node, addedSymbols) {
|
2500
|
+
// Is this name already used by an active type parameter?
|
2501
|
+
if (this._activeTypeParams.get(node.value)) {
|
2502
|
+
this._addError(localize_1.Localizer.Diagnostic.overwriteTypeParameter().format({ name: node.value }), node);
|
2503
|
+
}
|
2504
|
+
return this._bindNameValueToScope(scope, node.value, addedSymbols);
|
2505
|
+
}
|
2506
|
+
_bindNameValueToScope(scope, name, addedSymbols) {
|
2392
2507
|
// Is this name already bound to a scope other than the local one?
|
2393
2508
|
const bindingType = this._currentScope.getBindingType(name);
|
2394
2509
|
if (bindingType !== undefined) {
|
@@ -2436,7 +2551,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2436
2551
|
_bindPossibleTupleNamedTarget(target, addedSymbols) {
|
2437
2552
|
switch (target.nodeType) {
|
2438
2553
|
case 38 /* Name */: {
|
2439
|
-
this._bindNameToScope(this._currentScope, target
|
2554
|
+
this._bindNameToScope(this._currentScope, target, addedSymbols);
|
2440
2555
|
break;
|
2441
2556
|
}
|
2442
2557
|
case 52 /* Tuple */: {
|
@@ -2554,7 +2669,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
2554
2669
|
if (!symbol.isClassMember() ||
|
2555
2670
|
!symbol
|
2556
2671
|
.getDeclarations()
|
2557
|
-
.some((decl) => decl.type ===
|
2672
|
+
.some((decl) => decl.type === 5 /* Function */ && decl.isMethod)) {
|
2558
2673
|
symbol.setIsInstanceMember();
|
2559
2674
|
}
|
2560
2675
|
}
|
@@ -3067,10 +3182,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3067
3182
|
if (!specialTypes.has(assignedName)) {
|
3068
3183
|
return false;
|
3069
3184
|
}
|
3070
|
-
const symbol = this._bindNameToScope(this._currentScope,
|
3185
|
+
const symbol = this._bindNameToScope(this._currentScope, annotationNode.valueExpression);
|
3071
3186
|
if (symbol) {
|
3072
3187
|
symbol.addDeclaration({
|
3073
|
-
type:
|
3188
|
+
type: 7 /* SpecialBuiltInClass */,
|
3074
3189
|
node: annotationNode,
|
3075
3190
|
path: this._fileInfo.filePath,
|
3076
3191
|
range: (0, positionUtils_1.convertOffsetsToRange)(annotationNode.start, textRange_2.TextRange.getEnd(annotationNode), this._fileInfo.lines),
|
@@ -3087,6 +3202,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3087
3202
|
this._deferredBindingTasks.push({
|
3088
3203
|
scope: this._currentScope,
|
3089
3204
|
codeFlowExpressions: this._currentScopeCodeFlowExpressions,
|
3205
|
+
activeTypeParams: new Map(this._activeTypeParams),
|
3090
3206
|
callback,
|
3091
3207
|
});
|
3092
3208
|
}
|
@@ -3096,6 +3212,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
|
|
3096
3212
|
// Reset the state
|
3097
3213
|
this._currentScope = nextItem.scope;
|
3098
3214
|
this._currentScopeCodeFlowExpressions = nextItem.codeFlowExpressions;
|
3215
|
+
this._activeTypeParams = nextItem.activeTypeParams;
|
3099
3216
|
nextItem.callback();
|
3100
3217
|
}
|
3101
3218
|
}
|