@zzzen/pyright-internal 1.2.0-beta → 1.2.0-dev.20220710

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.
Files changed (130) hide show
  1. package/README.md +82 -1
  2. package/dist/analyzer/aliasDeclarationUtils.js +2 -2
  3. package/dist/analyzer/analyzerFileInfo.d.ts +2 -1
  4. package/dist/analyzer/analyzerFileInfo.js.map +1 -1
  5. package/dist/analyzer/analyzerNodeInfo.d.ts +4 -1
  6. package/dist/analyzer/analyzerNodeInfo.js +12 -1
  7. package/dist/analyzer/analyzerNodeInfo.js.map +1 -1
  8. package/dist/analyzer/binder.d.ts +6 -1
  9. package/dist/analyzer/binder.js +134 -31
  10. package/dist/analyzer/binder.js.map +1 -1
  11. package/dist/analyzer/checker.d.ts +4 -1
  12. package/dist/analyzer/checker.js +129 -48
  13. package/dist/analyzer/checker.js.map +1 -1
  14. package/dist/analyzer/codeFlowEngine.js +6 -1
  15. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  16. package/dist/analyzer/constraintSolver.js +8 -5
  17. package/dist/analyzer/constraintSolver.js.map +1 -1
  18. package/dist/analyzer/declaration.d.ts +18 -6
  19. package/dist/analyzer/declaration.js +19 -9
  20. package/dist/analyzer/declaration.js.map +1 -1
  21. package/dist/analyzer/declarationUtils.d.ts +1 -1
  22. package/dist/analyzer/declarationUtils.js +19 -16
  23. package/dist/analyzer/declarationUtils.js.map +1 -1
  24. package/dist/analyzer/functionTransform.js +2 -1
  25. package/dist/analyzer/functionTransform.js.map +1 -1
  26. package/dist/analyzer/packageTypeVerifier.js +6 -6
  27. package/dist/analyzer/parseTreeUtils.d.ts +3 -3
  28. package/dist/analyzer/parseTreeUtils.js +28 -18
  29. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  30. package/dist/analyzer/parseTreeWalker.d.ts +4 -1
  31. package/dist/analyzer/parseTreeWalker.js +19 -1
  32. package/dist/analyzer/parseTreeWalker.js.map +1 -1
  33. package/dist/analyzer/patternMatching.js +1 -1
  34. package/dist/analyzer/patternMatching.js.map +1 -1
  35. package/dist/analyzer/program.d.ts +2 -2
  36. package/dist/analyzer/program.js +1 -1
  37. package/dist/analyzer/program.js.map +1 -1
  38. package/dist/analyzer/properties.js +2 -0
  39. package/dist/analyzer/properties.js.map +1 -1
  40. package/dist/analyzer/protocols.d.ts +0 -1
  41. package/dist/analyzer/protocols.js +1 -63
  42. package/dist/analyzer/protocols.js.map +1 -1
  43. package/dist/analyzer/service.d.ts +3 -2
  44. package/dist/analyzer/service.js +3 -2
  45. package/dist/analyzer/service.js.map +1 -1
  46. package/dist/analyzer/sourceFile.d.ts +6 -1
  47. package/dist/analyzer/sourceFile.js +17 -5
  48. package/dist/analyzer/sourceFile.js.map +1 -1
  49. package/dist/analyzer/tracePrinter.js +8 -4
  50. package/dist/analyzer/tracePrinter.js.map +1 -1
  51. package/dist/analyzer/typeDocStringUtils.js +1 -1
  52. package/dist/analyzer/typeEvaluator.js +692 -293
  53. package/dist/analyzer/typeEvaluator.js.map +1 -1
  54. package/dist/analyzer/typeEvaluatorTypes.d.ts +5 -3
  55. package/dist/analyzer/typeEvaluatorWithTracker.js +2 -0
  56. package/dist/analyzer/typeEvaluatorWithTracker.js.map +1 -1
  57. package/dist/analyzer/typeGuards.js +5 -0
  58. package/dist/analyzer/typeGuards.js.map +1 -1
  59. package/dist/analyzer/typePrinter.js +4 -1
  60. package/dist/analyzer/typePrinter.js.map +1 -1
  61. package/dist/analyzer/typeStubWriter.d.ts +4 -1
  62. package/dist/analyzer/typeStubWriter.js +36 -0
  63. package/dist/analyzer/typeStubWriter.js.map +1 -1
  64. package/dist/analyzer/typeUtils.d.ts +1 -1
  65. package/dist/analyzer/typeUtils.js +14 -9
  66. package/dist/analyzer/typeUtils.js.map +1 -1
  67. package/dist/analyzer/typedDicts.js +3 -1
  68. package/dist/analyzer/typedDicts.js.map +1 -1
  69. package/dist/analyzer/types.d.ts +13 -5
  70. package/dist/analyzer/types.js +34 -11
  71. package/dist/analyzer/types.js.map +1 -1
  72. package/dist/languageServerBase.d.ts +3 -2
  73. package/dist/languageServerBase.js +3 -2
  74. package/dist/languageServerBase.js.map +1 -1
  75. package/dist/languageService/autoImporter.js +1 -1
  76. package/dist/languageService/callHierarchyProvider.js +9 -9
  77. package/dist/languageService/completionProvider.js +19 -13
  78. package/dist/languageService/completionProvider.js.map +1 -1
  79. package/dist/languageService/definitionProvider.js +3 -3
  80. package/dist/languageService/documentSymbolCollector.js +1 -1
  81. package/dist/languageService/documentSymbolProvider.js +10 -7
  82. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  83. package/dist/languageService/hoverProvider.js +19 -5
  84. package/dist/languageService/hoverProvider.js.map +1 -1
  85. package/dist/languageService/indentationUtils.js +3 -2
  86. package/dist/languageService/indentationUtils.js.map +1 -1
  87. package/dist/languageService/insertionPointUtils.d.ts +9 -0
  88. package/dist/languageService/insertionPointUtils.js +110 -0
  89. package/dist/languageService/insertionPointUtils.js.map +1 -0
  90. package/dist/languageService/referencesProvider.js +8 -5
  91. package/dist/languageService/referencesProvider.js.map +1 -1
  92. package/dist/languageService/signatureHelpProvider.js +4 -2
  93. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  94. package/dist/languageService/tooltipUtils.js +1 -1
  95. package/dist/localization/localize.d.ts +27 -0
  96. package/dist/localization/localize.js +16 -0
  97. package/dist/localization/localize.js.map +1 -1
  98. package/dist/localization/package.nls.en-us.json +18 -2
  99. package/dist/parser/parseNodes.d.ts +41 -5
  100. package/dist/parser/parseNodes.js +83 -4
  101. package/dist/parser/parseNodes.js.map +1 -1
  102. package/dist/parser/parser.d.ts +5 -1
  103. package/dist/parser/parser.js +131 -13
  104. package/dist/parser/parser.js.map +1 -1
  105. package/dist/parser/tokenizer.d.ts +2 -1
  106. package/dist/parser/tokenizer.js +7 -5
  107. package/dist/parser/tokenizer.js.map +1 -1
  108. package/dist/parser/tokenizerTypes.d.ts +5 -3
  109. package/dist/parser/tokenizerTypes.js +6 -4
  110. package/dist/parser/tokenizerTypes.js.map +1 -1
  111. package/dist/tests/chainedSourceFiles.test.js +2 -1
  112. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  113. package/dist/tests/fourslash/import.multipart.fourslash.d.ts +1 -0
  114. package/dist/tests/fourslash/import.multipart.fourslash.js +18 -0
  115. package/dist/tests/fourslash/import.multipart.fourslash.js.map +1 -0
  116. package/dist/tests/fourslash/signature.simple.fourslash.js +16 -0
  117. package/dist/tests/fourslash/signature.simple.fourslash.js.map +1 -1
  118. package/dist/tests/insertionPointUtils.test.d.ts +1 -0
  119. package/dist/tests/insertionPointUtils.test.js +74 -0
  120. package/dist/tests/insertionPointUtils.test.js.map +1 -0
  121. package/dist/tests/testUtils.js +2 -1
  122. package/dist/tests/testUtils.js.map +1 -1
  123. package/dist/tests/typeEvaluator3.test.js +8 -0
  124. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  125. package/dist/tests/typeEvaluator4.test.js +10 -0
  126. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  127. package/dist/tests/typeEvaluator5.test.d.ts +1 -0
  128. package/dist/tests/typeEvaluator5.test.js +118 -0
  129. package/dist/tests/typeEvaluator5.test.js.map +1 -0
  130. package/package.json +3 -2
@@ -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: 4 /* Class */,
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.value);
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.value);
253
+ const symbol = this._bindNameToScope(this._currentScope, node.name);
245
254
  const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
246
255
  const functionDeclaration = {
247
- type: 3 /* Function */,
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
- this.walkMultiple(node.decorators);
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.value);
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.value);
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;
@@ -617,7 +692,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
617
692
  }
618
693
  curScope = curScope.parent;
619
694
  }
620
- this._bindNameToScope(containerScope, node.name.value);
695
+ this._bindNameToScope(containerScope, node.name);
621
696
  this._addInferredTypeAssignmentForVariable(node.name, node.rightExpression);
622
697
  this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
623
698
  }
@@ -794,6 +869,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
794
869
  }
795
870
  visitName(node) {
796
871
  AnalyzerNodeInfo.setFlowNode(node, this._currentFlowNode);
872
+ const typeParamSymbol = this._activeTypeParams.get(node.value);
873
+ if (typeParamSymbol) {
874
+ AnalyzerNodeInfo.setTypeParameterSymbol(node, typeParamSymbol);
875
+ }
797
876
  // Name nodes have no children.
798
877
  return false;
799
878
  }
@@ -876,7 +955,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
876
955
  }
877
956
  if (node.name) {
878
957
  this.walk(node.name);
879
- const symbol = this._bindNameToScope(this._currentScope, node.name.value);
958
+ const symbol = this._bindNameToScope(this._currentScope, node.name);
880
959
  this._createAssignmentTargetFlowNodes(node.name, /* walkTargets */ true, /* unbound */ false);
881
960
  if (symbol) {
882
961
  const declaration = {
@@ -1047,7 +1126,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1047
1126
  // Make sure this is within an async lambda or function.
1048
1127
  const enclosingFunction = ParseTreeUtils.getEnclosingFunction(node);
1049
1128
  if (enclosingFunction === undefined || !enclosingFunction.isAsync) {
1050
- if (this._fileInfo.isIPythonMode && enclosingFunction === undefined) {
1129
+ if (this._fileInfo.ipythonMode && enclosingFunction === undefined) {
1051
1130
  // Top level await is allowed in ipython mode.
1052
1131
  return true;
1053
1132
  }
@@ -1074,7 +1153,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1074
1153
  this._addError(localize_1.Localizer.Diagnostic.globalReassignment().format({ name: nameValue }), name);
1075
1154
  }
1076
1155
  // Add it to the global scope if it's not already added.
1077
- this._bindNameToScope(globalScope, nameValue);
1156
+ this._bindNameToScope(globalScope, name);
1078
1157
  if (this._currentScope !== globalScope) {
1079
1158
  this._currentScope.setBindingType(nameValue, 1 /* Global */);
1080
1159
  }
@@ -1113,16 +1192,19 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1113
1192
  if (node.module.nameParts.length > 0) {
1114
1193
  const firstNamePartValue = node.module.nameParts[0].value;
1115
1194
  let symbolName;
1195
+ let symbolNameNode;
1116
1196
  if (node.alias) {
1117
1197
  // The symbol name is defined by the alias.
1118
1198
  symbolName = node.alias.value;
1199
+ symbolNameNode = node.alias;
1119
1200
  }
1120
1201
  else {
1121
1202
  // There was no alias, so we need to use the first element of
1122
1203
  // the name parts as the symbol.
1123
1204
  symbolName = firstNamePartValue;
1205
+ symbolNameNode = node.module.nameParts[0];
1124
1206
  }
1125
- const symbol = this._bindNameToScope(this._currentScope, symbolName);
1207
+ const symbol = this._bindNameToScope(this._currentScope, symbolNameNode);
1126
1208
  if (symbol &&
1127
1209
  (this._currentScope.type === 3 /* Module */ || this._currentScope.type === 4 /* Builtin */) &&
1128
1210
  (!node.alias ||
@@ -1203,14 +1285,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1203
1285
  }
1204
1286
  }
1205
1287
  wildcardNames.forEach((name) => {
1206
- const localSymbol = this._bindNameToScope(this._currentScope, name);
1288
+ const localSymbol = this._bindNameValueToScope(this._currentScope, name);
1207
1289
  if (localSymbol) {
1208
1290
  const importedSymbol = lookupInfo.symbolTable.get(name);
1209
1291
  // Is the symbol in the target module's symbol table? If so,
1210
1292
  // alias it.
1211
1293
  if (importedSymbol) {
1212
1294
  const aliasDecl = {
1213
- type: 6 /* Alias */,
1295
+ type: 8 /* Alias */,
1214
1296
  node,
1215
1297
  path: resolvedPath,
1216
1298
  loadSymbolsFromPath: true,
@@ -1230,7 +1312,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1230
1312
  const implicitImport = importInfo.filteredImplicitImports.find((imp) => imp.name === name);
1231
1313
  if (implicitImport) {
1232
1314
  const submoduleFallback = {
1233
- type: 6 /* Alias */,
1315
+ type: 8 /* Alias */,
1234
1316
  node,
1235
1317
  path: implicitImport.path,
1236
1318
  loadSymbolsFromPath: true,
@@ -1240,7 +1322,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1240
1322
  isInExceptSuite: this._isInExceptSuite,
1241
1323
  };
1242
1324
  const aliasDecl = {
1243
- type: 6 /* Alias */,
1325
+ type: 8 /* Alias */,
1244
1326
  node,
1245
1327
  path: resolvedPath,
1246
1328
  loadSymbolsFromPath: true,
@@ -1278,7 +1360,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1278
1360
  node.imports.forEach((importSymbolNode) => {
1279
1361
  const importedName = importSymbolNode.name.value;
1280
1362
  const nameNode = importSymbolNode.alias || importSymbolNode.name;
1281
- const symbol = this._bindNameToScope(this._currentScope, nameNode.value);
1363
+ const symbol = this._bindNameToScope(this._currentScope, nameNode);
1282
1364
  if (symbol) {
1283
1365
  // All import statements of the form `from . import x` treat x
1284
1366
  // as an externally-visible (not hidden) symbol.
@@ -1306,7 +1388,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1306
1388
  let loadSymbolsFromPath = true;
1307
1389
  if (implicitImport) {
1308
1390
  submoduleFallback = {
1309
- type: 6 /* Alias */,
1391
+ type: 8 /* Alias */,
1310
1392
  node: importSymbolNode,
1311
1393
  path: implicitImport.path,
1312
1394
  loadSymbolsFromPath: true,
@@ -1325,7 +1407,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1325
1407
  }
1326
1408
  }
1327
1409
  const aliasDecl = {
1328
- type: 6 /* Alias */,
1410
+ type: 8 /* Alias */,
1329
1411
  node: importSymbolNode,
1330
1412
  path: resolvedPath,
1331
1413
  loadSymbolsFromPath,
@@ -1605,7 +1687,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1605
1687
  this._currentFlowNode = this._finishFlowLabel(postOrLabel);
1606
1688
  if (node.target) {
1607
1689
  this.walk(node.target);
1608
- const symbol = this._bindNameToScope(this._currentScope, node.target.value);
1690
+ const symbol = this._bindNameToScope(this._currentScope, node.target);
1609
1691
  this._createAssignmentTargetFlowNodes(node.target, /* walkTargets */ false, /* unbound */ false);
1610
1692
  if (symbol) {
1611
1693
  const declaration = {
@@ -1635,6 +1717,18 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1635
1717
  }
1636
1718
  return true;
1637
1719
  }
1720
+ _removeActiveTypeParameters(node) {
1721
+ node.parameters.forEach((typeParamNode) => {
1722
+ const entry = this._activeTypeParams.get(typeParamNode.name.value);
1723
+ if (entry) {
1724
+ const decls = entry.getDeclarations();
1725
+ (0, debug_1.assert)(decls && decls.length === 1 && decls[0].type === 3 /* TypeParameter */);
1726
+ if (decls[0].node === typeParamNode) {
1727
+ this._activeTypeParams.delete(typeParamNode.name.value);
1728
+ }
1729
+ }
1730
+ });
1731
+ }
1638
1732
  _getNonClassParentScope() {
1639
1733
  // We may not be able to use the current scope if it's a class scope.
1640
1734
  // Walk up until we find a non-class scope instead.
@@ -1700,7 +1794,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1700
1794
  return false;
1701
1795
  }
1702
1796
  _addPatternCaptureTarget(target) {
1703
- const symbol = this._bindNameToScope(this._currentScope, target.value);
1797
+ const symbol = this._bindNameToScope(this._currentScope, target);
1704
1798
  this._createAssignmentTargetFlowNodes(target, /* walkTargets */ false, /* unbound */ false);
1705
1799
  if (symbol) {
1706
1800
  const declaration = {
@@ -1731,7 +1825,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1731
1825
  return undefined;
1732
1826
  }
1733
1827
  // There should be only one declaration for the variable.
1734
- const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === 6 /* Alias */);
1828
+ const aliasDecl = varSymbol.getDeclarations().find((decl) => decl.type === 8 /* Alias */);
1735
1829
  const resolvedPath = (aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.path) && aliasDecl.loadSymbolsFromPath
1736
1830
  ? aliasDecl.path
1737
1831
  : ((_a = aliasDecl === null || aliasDecl === void 0 ? void 0 : aliasDecl.submoduleFallback) === null || _a === void 0 ? void 0 : _a.path) && aliasDecl.submoduleFallback.loadSymbolsFromPath
@@ -1748,7 +1842,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1748
1842
  }
1749
1843
  _addImplicitFromImport(node, importInfo) {
1750
1844
  const symbolName = node.module.nameParts[0].value;
1751
- const symbol = this._bindNameToScope(this._currentScope, symbolName);
1845
+ const symbol = this._bindNameValueToScope(this._currentScope, symbolName);
1752
1846
  if (symbol) {
1753
1847
  this._createAliasDeclarationForMultipartImportName(node, /* importAlias */ undefined, importInfo, symbol);
1754
1848
  }
@@ -1766,7 +1860,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1766
1860
  // python module loader.
1767
1861
  const existingDecl = symbol
1768
1862
  .getDeclarations()
1769
- .find((decl) => decl.type === 6 /* Alias */ && decl.firstNamePart === firstNamePartValue);
1863
+ .find((decl) => decl.type === 8 /* Alias */ && decl.firstNamePart === firstNamePartValue);
1770
1864
  let newDecl;
1771
1865
  let pathOfLastSubmodule;
1772
1866
  if (importInfo && importInfo.isImportFound && !importInfo.isNativeLib && importInfo.resolvedPaths.length > 0) {
@@ -1781,7 +1875,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1781
1875
  }
1782
1876
  else if (isResolved) {
1783
1877
  newDecl = {
1784
- type: 6 /* Alias */,
1878
+ type: 8 /* Alias */,
1785
1879
  node,
1786
1880
  path: pathOfLastSubmodule,
1787
1881
  loadSymbolsFromPath: false,
@@ -1797,7 +1891,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
1797
1891
  // bogus path so it gets an unknown type (rather than an unbound type) at
1798
1892
  // analysis time.
1799
1893
  newDecl = {
1800
- type: 6 /* Alias */,
1894
+ type: 8 /* Alias */,
1801
1895
  node,
1802
1896
  path: pathOfLastSubmodule,
1803
1897
  loadSymbolsFromPath: true,
@@ -2388,7 +2482,14 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2388
2482
  }
2389
2483
  }
2390
2484
  }
2391
- _bindNameToScope(scope, name, addedSymbols) {
2485
+ _bindNameToScope(scope, node, addedSymbols) {
2486
+ // Is this name already used by an active type parameter?
2487
+ if (this._activeTypeParams.get(node.value)) {
2488
+ this._addError(localize_1.Localizer.Diagnostic.overwriteTypeParameter().format({ name: node.value }), node);
2489
+ }
2490
+ return this._bindNameValueToScope(scope, node.value, addedSymbols);
2491
+ }
2492
+ _bindNameValueToScope(scope, name, addedSymbols) {
2392
2493
  // Is this name already bound to a scope other than the local one?
2393
2494
  const bindingType = this._currentScope.getBindingType(name);
2394
2495
  if (bindingType !== undefined) {
@@ -2436,7 +2537,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2436
2537
  _bindPossibleTupleNamedTarget(target, addedSymbols) {
2437
2538
  switch (target.nodeType) {
2438
2539
  case 38 /* Name */: {
2439
- this._bindNameToScope(this._currentScope, target.value, addedSymbols);
2540
+ this._bindNameToScope(this._currentScope, target, addedSymbols);
2440
2541
  break;
2441
2542
  }
2442
2543
  case 52 /* Tuple */: {
@@ -2554,7 +2655,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
2554
2655
  if (!symbol.isClassMember() ||
2555
2656
  !symbol
2556
2657
  .getDeclarations()
2557
- .some((decl) => decl.type === 3 /* Function */ && decl.isMethod)) {
2658
+ .some((decl) => decl.type === 5 /* Function */ && decl.isMethod)) {
2558
2659
  symbol.setIsInstanceMember();
2559
2660
  }
2560
2661
  }
@@ -3067,10 +3168,10 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
3067
3168
  if (!specialTypes.has(assignedName)) {
3068
3169
  return false;
3069
3170
  }
3070
- const symbol = this._bindNameToScope(this._currentScope, assignedName);
3171
+ const symbol = this._bindNameToScope(this._currentScope, annotationNode.valueExpression);
3071
3172
  if (symbol) {
3072
3173
  symbol.addDeclaration({
3073
- type: 5 /* SpecialBuiltInClass */,
3174
+ type: 7 /* SpecialBuiltInClass */,
3074
3175
  node: annotationNode,
3075
3176
  path: this._fileInfo.filePath,
3076
3177
  range: (0, positionUtils_1.convertOffsetsToRange)(annotationNode.start, textRange_2.TextRange.getEnd(annotationNode), this._fileInfo.lines),
@@ -3087,6 +3188,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
3087
3188
  this._deferredBindingTasks.push({
3088
3189
  scope: this._currentScope,
3089
3190
  codeFlowExpressions: this._currentScopeCodeFlowExpressions,
3191
+ activeTypeParams: new Map(this._activeTypeParams),
3090
3192
  callback,
3091
3193
  });
3092
3194
  }
@@ -3096,6 +3198,7 @@ class Binder extends parseTreeWalker_1.ParseTreeWalker {
3096
3198
  // Reset the state
3097
3199
  this._currentScope = nextItem.scope;
3098
3200
  this._currentScopeCodeFlowExpressions = nextItem.codeFlowExpressions;
3201
+ this._activeTypeParams = nextItem.activeTypeParams;
3099
3202
  nextItem.callback();
3100
3203
  }
3101
3204
  }