@zzzen/pyright-internal 1.2.0-dev.20230129 → 1.2.0-dev.20230205

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 (209) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +3 -3
  2. package/dist/analyzer/backgroundAnalysisProgram.js +4 -2
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +15 -11
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/checker.d.ts +2 -1
  7. package/dist/analyzer/checker.js +27 -20
  8. package/dist/analyzer/checker.js.map +1 -1
  9. package/dist/analyzer/codeFlowEngine.js +3 -2
  10. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  11. package/dist/analyzer/dataClasses.js +4 -3
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/declaration.d.ts +2 -0
  14. package/dist/analyzer/declaration.js.map +1 -1
  15. package/dist/analyzer/importResolver.d.ts +1 -1
  16. package/dist/analyzer/importResolver.js +6 -3
  17. package/dist/analyzer/importResolver.js.map +1 -1
  18. package/dist/analyzer/parseTreeUtils.d.ts +2 -1
  19. package/dist/analyzer/parseTreeUtils.js +23 -1
  20. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  21. package/dist/analyzer/program.d.ts +6 -3
  22. package/dist/analyzer/program.js +78 -19
  23. package/dist/analyzer/program.js.map +1 -1
  24. package/dist/analyzer/service.d.ts +0 -2
  25. package/dist/analyzer/service.js +8 -8
  26. package/dist/analyzer/service.js.map +1 -1
  27. package/dist/analyzer/sourceFile.d.ts +3 -7
  28. package/dist/analyzer/sourceFile.js +3 -19
  29. package/dist/analyzer/sourceFile.js.map +1 -1
  30. package/dist/analyzer/typeCacheUtils.d.ts +8 -2
  31. package/dist/analyzer/typeCacheUtils.js +4 -4
  32. package/dist/analyzer/typeCacheUtils.js.map +1 -1
  33. package/dist/analyzer/typeEvaluator.js +204 -104
  34. package/dist/analyzer/typeEvaluator.js.map +1 -1
  35. package/dist/analyzer/typeEvaluatorTypes.d.ts +12 -8
  36. package/dist/analyzer/typeGuards.js +0 -14
  37. package/dist/analyzer/typeGuards.js.map +1 -1
  38. package/dist/analyzer/typeUtils.d.ts +4 -3
  39. package/dist/analyzer/typeUtils.js +2 -2
  40. package/dist/analyzer/typeUtils.js.map +1 -1
  41. package/dist/analyzer/typeVarContext.d.ts +1 -5
  42. package/dist/analyzer/typeVarContext.js +17 -22
  43. package/dist/analyzer/typeVarContext.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.d.ts +1 -3
  45. package/dist/backgroundAnalysisBase.js +2 -3
  46. package/dist/backgroundAnalysisBase.js.map +1 -1
  47. package/dist/backgroundThreadBase.js +5 -1
  48. package/dist/backgroundThreadBase.js.map +1 -1
  49. package/dist/common/envVarUtils.d.ts +1 -1
  50. package/dist/common/envVarUtils.js +26 -16
  51. package/dist/common/envVarUtils.js.map +1 -1
  52. package/dist/common/extensibility.d.ts +44 -6
  53. package/dist/common/extensibility.js +26 -2
  54. package/dist/common/extensibility.js.map +1 -1
  55. package/dist/common/fullAccessHost.d.ts +2 -1
  56. package/dist/common/fullAccessHost.js +22 -0
  57. package/dist/common/fullAccessHost.js.map +1 -1
  58. package/dist/common/host.d.ts +6 -0
  59. package/dist/common/host.js +3 -0
  60. package/dist/common/host.js.map +1 -1
  61. package/dist/common/pathUtils.d.ts +2 -0
  62. package/dist/common/pathUtils.js +17 -3
  63. package/dist/common/pathUtils.js.map +1 -1
  64. package/dist/languageServerBase.d.ts +2 -4
  65. package/dist/languageServerBase.js +5 -6
  66. package/dist/languageServerBase.js.map +1 -1
  67. package/dist/languageService/callHierarchyProvider.js +1 -1
  68. package/dist/languageService/callHierarchyProvider.js.map +1 -1
  69. package/dist/languageService/completionProvider.d.ts +0 -1
  70. package/dist/languageService/completionProvider.js +20 -91
  71. package/dist/languageService/completionProvider.js.map +1 -1
  72. package/dist/languageService/completionProviderUtils.d.ts +34 -0
  73. package/dist/languageService/completionProviderUtils.js +102 -0
  74. package/dist/languageService/completionProviderUtils.js.map +1 -0
  75. package/dist/languageService/definitionProvider.d.ts +2 -1
  76. package/dist/languageService/definitionProvider.js +25 -9
  77. package/dist/languageService/definitionProvider.js.map +1 -1
  78. package/dist/languageService/documentSymbolCollector.d.ts +2 -1
  79. package/dist/languageService/documentSymbolCollector.js +27 -3
  80. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  81. package/dist/languageService/documentSymbolProvider.js +1 -1
  82. package/dist/languageService/documentSymbolProvider.js.map +1 -1
  83. package/dist/languageService/hoverProvider.d.ts +1 -0
  84. package/dist/languageService/hoverProvider.js +44 -10
  85. package/dist/languageService/hoverProvider.js.map +1 -1
  86. package/dist/languageService/referencesProvider.d.ts +2 -1
  87. package/dist/languageService/referencesProvider.js +4 -3
  88. package/dist/languageService/referencesProvider.js.map +1 -1
  89. package/dist/languageService/tooltipUtils.d.ts +3 -1
  90. package/dist/languageService/tooltipUtils.js +29 -9
  91. package/dist/languageService/tooltipUtils.js.map +1 -1
  92. package/dist/localization/localize.d.ts +7 -0
  93. package/dist/localization/localize.js +9 -9
  94. package/dist/localization/localize.js.map +1 -1
  95. package/dist/localization/package.nls.en-us.json +2 -2
  96. package/dist/parser/stringTokenUtils.js +10 -0
  97. package/dist/parser/stringTokenUtils.js.map +1 -1
  98. package/dist/pyright.js +17 -9
  99. package/dist/pyright.js.map +1 -1
  100. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js +1 -1
  101. package/dist/tests/fourslash/completions.autoimport.shadow.fourslash.js.map +1 -1
  102. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js +5 -5
  103. package/dist/tests/fourslash/completions.builtinDocstrings.fourslash.js.map +1 -1
  104. package/dist/tests/fourslash/completions.fourslash.js +2 -2
  105. package/dist/tests/fourslash/completions.fourslash.js.map +1 -1
  106. package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js +1 -1
  107. package/dist/tests/fourslash/completions.inherited.overload.docFromScrWithStub.fourslash.js.map +1 -1
  108. package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js +1 -1
  109. package/dist/tests/fourslash/completions.inherited.overload.docFromStub.fourslash.js.map +1 -1
  110. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js +1 -1
  111. package/dist/tests/fourslash/completions.libCodeAndStub.fourslash.js.map +1 -1
  112. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js +1 -1
  113. package/dist/tests/fourslash/completions.libCodeNoStub.fourslash.js.map +1 -1
  114. package/dist/tests/fourslash/completions.libStub.fourslash.js +1 -1
  115. package/dist/tests/fourslash/completions.libStub.fourslash.js.map +1 -1
  116. package/dist/tests/fourslash/completions.localCode.fourslash.js +2 -2
  117. package/dist/tests/fourslash/completions.localCode.fourslash.js.map +1 -1
  118. package/dist/tests/fourslash/completions.overloads.fourslash.js +1 -1
  119. package/dist/tests/fourslash/completions.overloads.fourslash.js.map +1 -1
  120. package/dist/tests/fourslash/completions.plainText.fourslash.js +2 -2
  121. package/dist/tests/fourslash/completions.plainText.fourslash.js.map +1 -1
  122. package/dist/tests/fourslash/completions.self.fourslash.js +2 -2
  123. package/dist/tests/fourslash/completions.self.fourslash.js.map +1 -1
  124. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +1 -1
  125. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
  126. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js +7 -7
  127. package/dist/tests/fourslash/hover.builtinDocstrings.fourslash.js.map +1 -1
  128. package/dist/tests/fourslash/hover.class.docString.fourslash.js +1 -1
  129. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -1
  130. package/dist/tests/fourslash/hover.classNoInit.fourslash.js +1 -1
  131. package/dist/tests/fourslash/hover.classNoInit.fourslash.js.map +1 -1
  132. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +7 -7
  133. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
  134. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js +1 -1
  135. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module1.fourslash.js.map +1 -1
  136. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js +1 -1
  137. package/dist/tests/fourslash/hover.docFromSrc.pkg-vs-module2.fourslash.js.map +1 -1
  138. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js +1 -1
  139. package/dist/tests/fourslash/hover.docFromSrc.relativeImport1.fourslash.js.map +1 -1
  140. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js +1 -1
  141. package/dist/tests/fourslash/hover.docFromSrc.relativeImport2.fourslash.js.map +1 -1
  142. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js +1 -1
  143. package/dist/tests/fourslash/hover.docFromSrc.relativeImport3.fourslash.js.map +1 -1
  144. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js +2 -2
  145. package/dist/tests/fourslash/hover.docFromSrc.stubs-package.fourslash.js.map +1 -1
  146. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js +1 -1
  147. package/dist/tests/fourslash/hover.docFromSrc.typeshed.fourslash.js.map +1 -1
  148. package/dist/tests/fourslash/hover.docstring.links.fourslash.js +1 -1
  149. package/dist/tests/fourslash/hover.docstring.links.fourslash.js.map +1 -1
  150. package/dist/tests/fourslash/hover.docstring.split.fourslash.js +3 -3
  151. package/dist/tests/fourslash/hover.docstring.split.fourslash.js.map +1 -1
  152. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js +1 -1
  153. package/dist/tests/fourslash/hover.dunderNew.basic.fourslash.js.map +1 -1
  154. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js +1 -1
  155. package/dist/tests/fourslash/hover.dunderNew.inheritance.fourslash.js.map +1 -1
  156. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js +1 -1
  157. package/dist/tests/fourslash/hover.dunderNew.inheritance2.fourslash.js.map +1 -1
  158. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js +1 -1
  159. package/dist/tests/fourslash/hover.dunderNew.overloads.fourslash.js.map +1 -1
  160. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js +1 -1
  161. package/dist/tests/fourslash/hover.dunderNew.withInit.fourslash.js.map +1 -1
  162. package/dist/tests/fourslash/hover.formatted.fourslash.js +6 -6
  163. package/dist/tests/fourslash/hover.formatted.fourslash.js.map +1 -1
  164. package/dist/tests/fourslash/hover.fourslash.js +1 -1
  165. package/dist/tests/fourslash/hover.fourslash.js.map +1 -1
  166. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js +6 -6
  167. package/dist/tests/fourslash/hover.inherited.docFromSrc.fourslash.js.map +1 -1
  168. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js +5 -5
  169. package/dist/tests/fourslash/hover.inherited.docFromSrcWithStub.fourslash.js.map +1 -1
  170. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js +4 -4
  171. package/dist/tests/fourslash/hover.inherited.docFromStub.fourslash.js.map +1 -1
  172. package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js +2 -2
  173. package/dist/tests/fourslash/hover.inherited.overload.docFromSrcWithStub.fourslash.js.map +1 -1
  174. package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js +2 -2
  175. package/dist/tests/fourslash/hover.inherited.overload.docFromStub.fourslash.js.map +1 -1
  176. package/dist/tests/fourslash/hover.init.fourslash.js +4 -4
  177. package/dist/tests/fourslash/hover.init.fourslash.js.map +1 -1
  178. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js +2 -2
  179. package/dist/tests/fourslash/hover.libCodeAndStub.fourslash.js.map +1 -1
  180. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js +2 -2
  181. package/dist/tests/fourslash/hover.libCodeNoStub.fourslash.js.map +1 -1
  182. package/dist/tests/fourslash/hover.libStub.fourslash.js +2 -2
  183. package/dist/tests/fourslash/hover.libStub.fourslash.js.map +1 -1
  184. package/dist/tests/fourslash/hover.overloadedFunction.fourslash.js +2 -2
  185. package/dist/tests/fourslash/hover.overloadedFunction.fourslash.js.map +1 -1
  186. package/dist/tests/fourslash/hover.plainText.fourslash.js +1 -1
  187. package/dist/tests/fourslash/hover.plainText.fourslash.js.map +1 -1
  188. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +1 -1
  189. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
  190. package/dist/tests/fourslash/import.multipart.fourslash.js +1 -1
  191. package/dist/tests/fourslash/import.multipart.fourslash.js.map +1 -1
  192. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js +1 -1
  193. package/dist/tests/fourslash/import.pytyped.typeCheckingBasic.fourslash.js.map +1 -1
  194. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js +1 -1
  195. package/dist/tests/fourslash/import.pytyped.typeCheckingOff.fourslash.js.map +1 -1
  196. package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
  197. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  198. package/dist/tests/pathUtils.test.js +24 -1
  199. package/dist/tests/pathUtils.test.js.map +1 -1
  200. package/dist/tests/typeEvaluator1.test.js +12 -0
  201. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  202. package/dist/tests/typeEvaluator2.test.js +4 -0
  203. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  204. package/dist/tests/typeEvaluator4.test.js +5 -1
  205. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  206. package/dist/workspaceMap.d.ts +4 -0
  207. package/dist/workspaceMap.js +67 -37
  208. package/dist/workspaceMap.js.map +1 -1
  209. package/package.json +1 -1
@@ -254,6 +254,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
254
254
  let dictClassType;
255
255
  let typedDictClassType;
256
256
  let printExpressionSpaceCount = 0;
257
+ let incompleteGenerationCount = 0;
257
258
  const returnTypeInferenceContextStack = [];
258
259
  let returnTypeInferenceTypeCache;
259
260
  function runWithCancellationToken(token, callback) {
@@ -333,14 +334,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
333
334
  const typeCacheToUse = returnTypeInferenceTypeCache && isNodeInReturnTypeInferenceContext(node)
334
335
  ? returnTypeInferenceTypeCache
335
336
  : typeCache;
336
- typeCacheToUse.set(node.id, { typeResult, flags });
337
+ if (!typeResult.isIncomplete) {
338
+ incompleteGenerationCount++;
339
+ }
340
+ else {
341
+ const oldValue = typeCacheToUse.get(node.id);
342
+ if (oldValue !== undefined && !(0, types_1.isTypeSame)(typeResult.type, oldValue.typeResult.type)) {
343
+ incompleteGenerationCount++;
344
+ }
345
+ }
346
+ typeCacheToUse.set(node.id, { typeResult, flags, incompleteGenerationCount: incompleteGenerationCount });
337
347
  // If the entry is located within a part of the parse tree that is currently being
338
348
  // "speculatively" evaluated, track it so we delete the cached entry when we leave
339
349
  // this speculative context.
340
350
  if (speculativeTypeTracker.isSpeculative(node)) {
341
351
  speculativeTypeTracker.trackEntry(typeCacheToUse, node.id);
342
- if (allowSpeculativeCaching && !typeResult.isIncomplete) {
343
- speculativeTypeTracker.addSpeculativeType(node, typeResult, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
352
+ if (allowSpeculativeCaching) {
353
+ speculativeTypeTracker.addSpeculativeType(node, typeResult, incompleteGenerationCount, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
344
354
  }
345
355
  }
346
356
  }
@@ -494,7 +504,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
494
504
  var _a, _b;
495
505
  // Is this type already cached?
496
506
  const cacheEntry = readTypeCacheEntry(node);
497
- if (cacheEntry && !cacheEntry.typeResult.isIncomplete) {
507
+ if (cacheEntry &&
508
+ (!cacheEntry.typeResult.isIncomplete || cacheEntry.incompleteGenerationCount === incompleteGenerationCount)) {
498
509
  if (printExpressionTypes) {
499
510
  console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Cached ${printType(cacheEntry.typeResult.type)} ${cacheEntry.typeResult.typeErrors ? ' Errors' : ''}`);
500
511
  }
@@ -502,12 +513,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
502
513
  }
503
514
  else {
504
515
  // Is it cached in the speculative type cache?
505
- const cachedTypeResult = speculativeTypeTracker.getSpeculativeType(node, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
506
- if (cachedTypeResult) {
516
+ const cacheEntry = speculativeTypeTracker.getSpeculativeType(node, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
517
+ if (cacheEntry &&
518
+ (!cacheEntry.typeResult.isIncomplete ||
519
+ cacheEntry.incompleteGenerationCount === incompleteGenerationCount)) {
507
520
  if (printExpressionTypes) {
508
- console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(cachedTypeResult.type)}`);
521
+ console.log(`${getPrintExpressionTypesSpaces()}${ParseTreeUtils.printExpression(node)} (${getLineNum(node)}): Speculative ${printType(cacheEntry.typeResult.type)}`);
509
522
  }
510
- return cachedTypeResult;
523
+ return cacheEntry.typeResult;
511
524
  }
512
525
  }
513
526
  if (printExpressionTypes) {
@@ -614,16 +627,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
614
627
  }
615
628
  case 3 /* Assignment */: {
616
629
  typeResult = getTypeOfExpression(node.rightExpression);
617
- assignTypeToExpression(node.leftExpression, typeResult.type,
618
- /* isTypeIncomplete */ false, node.rightExpression,
630
+ assignTypeToExpression(node.leftExpression, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
619
631
  /* ignoreEmptyContainers */ true,
620
632
  /* allowAssignmentToFinalVar */ true);
621
633
  break;
622
634
  }
623
635
  case 4 /* AssignmentExpression */: {
624
636
  typeResult = getTypeOfExpression(node.rightExpression);
625
- assignTypeToExpression(node.name, typeResult.type,
626
- /* isTypeIncomplete */ false, node.rightExpression,
637
+ assignTypeToExpression(node.name, typeResult.type, !!typeResult.isIncomplete, node.rightExpression,
627
638
  /* ignoreEmptyContainers */ true);
628
639
  break;
629
640
  }
@@ -1218,6 +1229,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1218
1229
  if (types_1.ClassType.isBuiltIn(concreteSubtype, 'bool')) {
1219
1230
  return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ false);
1220
1231
  }
1232
+ // If the object is an int, str or bytes, narrow to a literal type.
1233
+ // This is slightly unsafe in that someone could subclass `int`, `str`
1234
+ // or `bytes` and override the `__bool__` method to change its behavior,
1235
+ // but this is extremely unlikely (and ill advised).
1236
+ if (types_1.ClassType.isBuiltIn(concreteSubtype, 'int')) {
1237
+ return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ 0);
1238
+ }
1239
+ else if (types_1.ClassType.isBuiltIn(concreteSubtype, ['str', 'bytes'])) {
1240
+ return types_1.ClassType.cloneWithLiteral(concreteSubtype, /* value */ '');
1241
+ }
1221
1242
  }
1222
1243
  // If it's possible for the type to be falsy, include it.
1223
1244
  if (canBeFalsy(subtype)) {
@@ -1389,7 +1410,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1389
1410
  function addOneFunctionToSignature(type) {
1390
1411
  let callResult;
1391
1412
  useSpeculativeMode(callNode, () => {
1392
- callResult = validateFunctionArguments(exprNode, argList, type, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1413
+ callResult = validateFunctionArguments(exprNode, argList, { type }, new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(type)),
1393
1414
  /* skipUnknownArgCheck */ true);
1394
1415
  });
1395
1416
  signatures.push({
@@ -2741,7 +2762,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2741
2762
  if (methodType) {
2742
2763
  if ((0, types_1.isOverloadedFunction)(methodType)) {
2743
2764
  if (errorNode) {
2744
- const bestOverload = getBestOverloadForArguments(errorNode, methodType, argList);
2765
+ const bestOverload = getBestOverloadForArguments(errorNode, { type: methodType, isIncomplete: memberTypeResult.isIncomplete }, argList);
2745
2766
  if (bestOverload) {
2746
2767
  return getFunctionEffectiveReturnType(bestOverload);
2747
2768
  }
@@ -2941,11 +2962,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2941
2962
  // Handles the case where a variable or parameter is defined in an outer
2942
2963
  // scope and captured by an inner scope (either a function or a lambda).
2943
2964
  function getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType) {
2944
- // This function applies only to variables and parameters, not to other
2965
+ // This function applies only to variables, parameters, and imports, not to other
2945
2966
  // types of symbols.
2946
2967
  if (!symbolWithScope.symbol
2947
2968
  .getDeclarations()
2948
- .every((decl) => decl.type === 1 /* Variable */ || decl.type === 2 /* Parameter */)) {
2969
+ .every((decl) => decl.type === 1 /* Variable */ ||
2970
+ decl.type === 2 /* Parameter */ ||
2971
+ decl.type === 8 /* Alias */)) {
2949
2972
  return undefined;
2950
2973
  }
2951
2974
  // If the symbol is a variable captured by an inner function
@@ -2972,6 +2995,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2972
2995
  if (decl.type === 2 /* Parameter */) {
2973
2996
  return true;
2974
2997
  }
2998
+ // Assume alias declarations are also always safe to narrow.
2999
+ if (decl.type === 8 /* Alias */) {
3000
+ return true;
3001
+ }
2975
3002
  const declCodeFlowNode = AnalyzerNodeInfo.getFlowNode(decl.node);
2976
3003
  if (!declCodeFlowNode) {
2977
3004
  return false;
@@ -3349,7 +3376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3349
3376
  const getTypeOfNoneBase = (subtype) => {
3350
3377
  if (noneType && (0, types_1.isInstantiableClass)(noneType)) {
3351
3378
  if (types_1.TypeBase.isInstance(subtype)) {
3352
- return getTypeOfObjectMember(node.memberName, noneType, memberName, usage, diag);
3379
+ return getTypeOfObjectMember(node.memberName, types_1.ClassType.cloneAsInstance(noneType), memberName, usage, diag);
3353
3380
  }
3354
3381
  else {
3355
3382
  return getTypeOfClassMember(node.memberName, noneType, memberName, usage, diag);
@@ -5412,17 +5439,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5412
5439
  // (one for each argument) will be undefined. On subsequent calls, this
5413
5440
  // list will grow to include union expansions.
5414
5441
  function validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, argParamMatches, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5415
- var _a;
5442
+ var _a, _b;
5416
5443
  const returnTypes = [];
5417
5444
  const matchedOverloads = [];
5418
5445
  let isTypeIncomplete = false;
5419
- const overloadsUsedForCall = [];
5446
+ let overloadsUsedForCall = [];
5420
5447
  let isDefinitiveMatchFound = false;
5421
5448
  for (let expandedTypesIndex = 0; expandedTypesIndex < expandedArgTypes.length; expandedTypesIndex++) {
5422
5449
  let matchedOverload;
5423
5450
  const argTypeOverride = expandedArgTypes[expandedTypesIndex];
5424
5451
  const hasArgTypeOverride = argTypeOverride.some((a) => a !== undefined);
5425
- const possibleMatchResults = [];
5452
+ let possibleMatchResults = [];
5426
5453
  isDefinitiveMatchFound = false;
5427
5454
  for (let overloadIndex = 0; overloadIndex < argParamMatches.length; overloadIndex++) {
5428
5455
  const overload = argParamMatches[overloadIndex].overload;
@@ -5459,13 +5486,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5459
5486
  if (!callResult.argumentErrors && callResult.returnType) {
5460
5487
  overloadsUsedForCall.push(overload);
5461
5488
  matchedOverload = overload;
5462
- matchedOverloads.push({
5489
+ const matchedOverloadInfo = {
5463
5490
  overload: matchedOverload,
5464
5491
  matchResults,
5465
5492
  typeVarContext: effectiveTypeVarContext,
5466
- });
5493
+ returnType: callResult.returnType,
5494
+ argResults: (_b = callResult.argResults) !== null && _b !== void 0 ? _b : [],
5495
+ };
5496
+ matchedOverloads.push(matchedOverloadInfo);
5467
5497
  if (callResult.isArgumentAnyOrUnknown) {
5468
- possibleMatchResults.push(callResult.returnType);
5498
+ possibleMatchResults.push(matchedOverloadInfo);
5469
5499
  }
5470
5500
  else {
5471
5501
  returnTypes.push(callResult.returnType);
@@ -5480,27 +5510,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5480
5510
  // Unknown, but include the "possible types" to allow for completion
5481
5511
  // suggestions.
5482
5512
  if (!isDefinitiveMatchFound) {
5483
- // Eliminate any return types that are subsumed by other return types.
5484
- let dedupedMatchResults = [];
5485
- possibleMatchResults.forEach((subtype) => {
5486
- let isSubtypeSubsumed = false;
5487
- for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
5488
- if (assignType(dedupedMatchResults[dedupedIndex], subtype)) {
5489
- isSubtypeSubsumed = true;
5490
- break;
5513
+ possibleMatchResults = filterOverloadMatchesForAnyArgs(possibleMatchResults);
5514
+ // Did the filtering produce a single result? If so, we're done.
5515
+ if (possibleMatchResults.length === 1) {
5516
+ overloadsUsedForCall = [possibleMatchResults[0].overload];
5517
+ returnTypes.push(possibleMatchResults[0].returnType);
5518
+ }
5519
+ else {
5520
+ // Eliminate any return types that are subsumed by other return types.
5521
+ let dedupedMatchResults = [];
5522
+ possibleMatchResults.forEach((result) => {
5523
+ let isSubtypeSubsumed = false;
5524
+ for (let dedupedIndex = 0; dedupedIndex < dedupedMatchResults.length; dedupedIndex++) {
5525
+ if (assignType(dedupedMatchResults[dedupedIndex], result.returnType)) {
5526
+ isSubtypeSubsumed = true;
5527
+ break;
5528
+ }
5529
+ else if (assignType(result.returnType, dedupedMatchResults[dedupedIndex])) {
5530
+ dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5531
+ break;
5532
+ }
5491
5533
  }
5492
- else if (assignType(subtype, dedupedMatchResults[dedupedIndex])) {
5493
- dedupedMatchResults[dedupedIndex] = types_1.NeverType.createNever();
5494
- break;
5534
+ if (!isSubtypeSubsumed) {
5535
+ dedupedMatchResults.push(result.returnType);
5495
5536
  }
5496
- }
5497
- if (!isSubtypeSubsumed) {
5498
- dedupedMatchResults.push(subtype);
5499
- }
5500
- });
5501
- dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
5502
- const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
5503
- returnTypes.push(dedupedMatchResults.length > 1 ? types_1.UnknownType.createPossibleType(combinedTypes) : combinedTypes);
5537
+ });
5538
+ dedupedMatchResults = dedupedMatchResults.filter((t) => !(0, types_1.isNever)(t));
5539
+ const combinedTypes = (0, types_1.combineTypes)(dedupedMatchResults);
5540
+ returnTypes.push(dedupedMatchResults.length > 1 ? types_1.UnknownType.createPossibleType(combinedTypes) : combinedTypes);
5541
+ }
5504
5542
  }
5505
5543
  if (!matchedOverload) {
5506
5544
  return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall };
@@ -5531,13 +5569,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5531
5569
  overloadsUsedForCall,
5532
5570
  };
5533
5571
  }
5534
- function getBestOverloadForArguments(errorNode, type, argList) {
5572
+ // This function determines whether multiple incompatible overloads match
5573
+ // due to an Any or Unknown argument type.
5574
+ function filterOverloadMatchesForAnyArgs(matches) {
5575
+ if (matches.length < 2) {
5576
+ return matches;
5577
+ }
5578
+ // If all of the return types match, select the first one.
5579
+ if ((0, typeUtils_1.areTypesSame)(matches.map((match) => match.returnType), { treatAnySameAsUnknown: true })) {
5580
+ return [matches[0]];
5581
+ }
5582
+ const firstArgResults = matches[0].argResults;
5583
+ if (!firstArgResults) {
5584
+ return matches;
5585
+ }
5586
+ for (let i = 0; i < firstArgResults.length; i++) {
5587
+ // If the arg is Any or Unknown, see if the corresponding
5588
+ // parameter types differ in any way.
5589
+ if ((0, types_1.isAnyOrUnknown)(firstArgResults[i].argType)) {
5590
+ const paramTypes = matches.map((match) => i < match.matchResults.argParams.length
5591
+ ? match.matchResults.argParams[i].paramType
5592
+ : types_1.UnknownType.create());
5593
+ if (!(0, typeUtils_1.areTypesSame)(paramTypes, { treatAnySameAsUnknown: true })) {
5594
+ return matches;
5595
+ }
5596
+ }
5597
+ }
5598
+ return [matches[0]];
5599
+ }
5600
+ function getBestOverloadForArguments(errorNode, typeResult, argList) {
5535
5601
  let overloadIndex = 0;
5536
5602
  let matches = [];
5537
5603
  // Create a list of potential overload matches based on arguments.
5538
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
5604
+ types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
5539
5605
  useSpeculativeMode(errorNode, () => {
5540
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
5606
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
5541
5607
  if (!matchResults.argumentErrors) {
5542
5608
  matches.push(matchResults);
5543
5609
  }
@@ -5568,7 +5634,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5568
5634
  return a.overloadIndex - b.overloadIndex;
5569
5635
  });
5570
5636
  }
5571
- function validateOverloadedFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5637
+ function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
5572
5638
  let filteredMatchResults = [];
5573
5639
  let contextFreeArgTypes;
5574
5640
  // Start by evaluating the types of the arguments without any expected
@@ -5578,11 +5644,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5578
5644
  // cache or record any diagnostics at this stage.
5579
5645
  useSpeculativeMode(errorNode, () => {
5580
5646
  let overloadIndex = 0;
5581
- types_1.OverloadedFunctionType.getOverloads(type).forEach((overload) => {
5647
+ types_1.OverloadedFunctionType.getOverloads(typeResult.type).forEach((overload) => {
5582
5648
  // Consider only the functions that have the @overload decorator,
5583
5649
  // not the final function that omits the overload. This is the
5584
5650
  // intended behavior according to PEP 484.
5585
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, overload, overloadIndex);
5651
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
5586
5652
  if (!matchResults.argumentErrors) {
5587
5653
  filteredMatchResults.push(matchResults);
5588
5654
  }
@@ -5596,7 +5662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5596
5662
  // Skip the error message if we're in speculative mode because it's very
5597
5663
  // expensive, and we're going to suppress the diagnostic anyway.
5598
5664
  if (!isDiagnosticSuppressedForNode(errorNode)) {
5599
- const functionName = type.overloads[0].details.name || '<anonymous function>';
5665
+ const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
5600
5666
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
5601
5667
  const argTypes = argList.map((t) => printType(getTypeOfArgument(t).type));
5602
5668
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
@@ -5624,7 +5690,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5624
5690
  return evaluateUsingLastMatchingOverload(/* skipUnknownArgCheck */ false);
5625
5691
  }
5626
5692
  let expandedArgTypes = [argList.map((arg) => undefined)];
5627
- let isTypeIncomplete = false;
5693
+ let isTypeIncomplete = !!typeResult.isIncomplete;
5628
5694
  while (true) {
5629
5695
  const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
5630
5696
  if (callResult.isTypeIncomplete) {
@@ -6085,7 +6151,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6085
6151
  effectiveTypeVarContext.addSolveForScope(types_1.WildcardTypeVarScopeId);
6086
6152
  }
6087
6153
  }
6088
- const functionResult = validateFunctionArguments(errorNode, argList, expandedSubtype, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6154
+ const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6089
6155
  if (functionResult.isTypeIncomplete) {
6090
6156
  isTypeIncomplete = true;
6091
6157
  }
@@ -6134,7 +6200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6134
6200
  }
6135
6201
  return (0, typeUtils_1.convertToInstance)(castToType);
6136
6202
  }
6137
- const functionResult = validateOverloadedFunctionArguments(errorNode, argList, expandedSubtype, typeVarContext, skipUnknownArgCheck, inferenceContext);
6203
+ const functionResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
6138
6204
  overloadsUsedForCall.push(...functionResult.overloadsUsedForCall);
6139
6205
  if (functionResult.isTypeIncomplete) {
6140
6206
  isTypeIncomplete = true;
@@ -6411,13 +6477,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6411
6477
  // function. This matching is done based on positions and keywords. Type evaluation and
6412
6478
  // validation is left to the caller.
6413
6479
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
6414
- function matchFunctionArgumentsToParameters(errorNode, argList, type, overloadIndex) {
6480
+ function matchFunctionArgumentsToParameters(errorNode, argList, typeResult, overloadIndex) {
6415
6481
  var _a, _b, _c, _d, _e;
6416
- const paramDetails = (0, typeUtils_1.getParameterListDetails)(type);
6482
+ const paramDetails = (0, typeUtils_1.getParameterListDetails)(typeResult.type);
6417
6483
  let argIndex = 0;
6418
6484
  let matchedUnpackedListOfUnknownLength = false;
6419
6485
  let reportedArgError = false;
6420
- let isTypeIncomplete = false;
6486
+ let isTypeIncomplete = !!typeResult.isIncomplete;
6421
6487
  let isVariadicTypeVarFullyMatched = false;
6422
6488
  // Expand any unpacked tuples in the arg list.
6423
6489
  argList = expandArgList(argList);
@@ -6457,8 +6523,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6457
6523
  // Does this function define the param spec, or is it an inner
6458
6524
  // function nested within another function that defines the param
6459
6525
  // spec? We need to handle these two cases differently.
6460
- if (varArgListParam.type.scopeId === type.details.typeVarScopeId ||
6461
- varArgListParam.type.scopeId === type.details.constructorTypeVarScopeId) {
6526
+ if (varArgListParam.type.scopeId === typeResult.type.details.typeVarScopeId ||
6527
+ varArgListParam.type.scopeId === typeResult.type.details.constructorTypeVarScopeId) {
6462
6528
  paramSpecArgList = [];
6463
6529
  paramSpecTarget = types_1.TypeVarType.cloneForParamSpecAccess(varArgListParam.type, /* access */ undefined);
6464
6530
  }
@@ -6516,7 +6582,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6516
6582
  const remainingArgCount = positionalArgCount - argIndex;
6517
6583
  const remainingParamCount = positionParamLimitIndex - paramIndex - 1;
6518
6584
  if (paramIndex >= positionParamLimitIndex) {
6519
- if (!type.details.paramSpec) {
6585
+ if (!typeResult.type.details.paramSpec) {
6520
6586
  let tooManyPositionals = false;
6521
6587
  if (foundUnpackedListArg && argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6522
6588
  // If this is an unpacked iterable, we will conservatively assume that it
@@ -6562,7 +6628,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6562
6628
  // with a ParamSpec and a Concatenate operator. PEP 612 indicates that
6563
6629
  // all positional parameters specified in the Concatenate must be
6564
6630
  // filled explicitly.
6565
- if (type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6631
+ if (typeResult.type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6566
6632
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6567
6633
  ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6568
6634
  : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
@@ -6848,10 +6914,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6848
6914
  }
6849
6915
  else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'kwargs') {
6850
6916
  unpackedDictionaryArgType = types_1.AnyType.create();
6851
- if (type.details.paramSpec) {
6917
+ if (typeResult.type.details.paramSpec) {
6852
6918
  validateArgTypeParams.push({
6853
6919
  paramCategory: 2 /* VarArgDictionary */,
6854
- paramType: type.details.paramSpec,
6920
+ paramType: typeResult.type.details.paramSpec,
6855
6921
  requiresTypeVarMatching: false,
6856
6922
  argument: argList[argIndex],
6857
6923
  errorNode: argList[argIndex].valueExpression || errorNode,
@@ -6967,7 +7033,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6967
7033
  else if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
6968
7034
  // Handle the case where a *args: P.args is passed as an argument to
6969
7035
  // a function that accepts a ParamSpec.
6970
- if (type.details.paramSpec) {
7036
+ if (typeResult.type.details.paramSpec) {
6971
7037
  const argTypeResult = getTypeOfArgument(argList[argIndex]);
6972
7038
  const argType = argTypeResult.type;
6973
7039
  if (argTypeResult.isIncomplete) {
@@ -6976,7 +7042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6976
7042
  if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
6977
7043
  validateArgTypeParams.push({
6978
7044
  paramCategory: 1 /* VarArgList */,
6979
- paramType: type.details.paramSpec,
7045
+ paramType: typeResult.type.details.paramSpec,
6980
7046
  requiresTypeVarMatching: false,
6981
7047
  argument: argList[argIndex],
6982
7048
  errorNode: argList[argIndex].valueExpression || errorNode,
@@ -7023,7 +7089,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7023
7089
  // but have not yet received them. If we received a dictionary argument
7024
7090
  // (i.e. an arg starting with a "**"), we will assume that all parameters
7025
7091
  // are matched.
7026
- if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(type)) {
7092
+ if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(typeResult.type)) {
7027
7093
  const unassignedParams = [...paramMap.keys()].filter((name) => {
7028
7094
  const entry = paramMap.get(name);
7029
7095
  return !entry || entry.argsReceived < entry.argsNeeded;
@@ -7147,12 +7213,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7147
7213
  relevance--;
7148
7214
  }
7149
7215
  // Special-case the builtin isinstance and issubclass functions.
7150
- if (['isinstance', 'issubclass'].some((name) => name === type.details.builtInName) &&
7216
+ if (['isinstance', 'issubclass'].some((name) => name === typeResult.type.details.builtInName) &&
7151
7217
  validateArgTypeParams.length === 2) {
7152
7218
  validateArgTypeParams[1].expectingType = true;
7153
7219
  }
7154
7220
  return {
7155
- overload: type,
7221
+ overload: typeResult.type,
7156
7222
  overloadIndex,
7157
7223
  argumentErrors: reportedArgError,
7158
7224
  isTypeIncomplete,
@@ -7294,7 +7360,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7294
7360
  // Set useNarrowBoundOnly to true the first time through
7295
7361
  // the loop if we're going to go through the loop multiple
7296
7362
  // times.
7297
- const argResult = validateArgType(argParam, typeVarContext, type, skipUnknownArgCheck,
7363
+ const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7298
7364
  /* skipOverloadArg */ i === 0,
7299
7365
  /* useNarrowBoundOnly */ passCount > 1 && i === 0, typeCondition);
7300
7366
  if (argResult.isTypeIncomplete) {
@@ -7317,11 +7383,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7317
7383
  let sawParamSpecArgs = false;
7318
7384
  let sawParamSpecKwargs = false;
7319
7385
  let condition = [];
7386
+ const argResults = [];
7320
7387
  matchResults.argParams.forEach((argParam) => {
7321
7388
  var _a;
7322
- const argResult = validateArgType(argParam, typeVarContext, type, skipUnknownArgCheck,
7389
+ const argResult = validateArgType(argParam, typeVarContext, { type, isIncomplete: matchResults.isTypeIncomplete }, skipUnknownArgCheck,
7323
7390
  /* skipOverloadArg */ false,
7324
7391
  /* useNarrowBoundOnly */ false, typeCondition);
7392
+ argResults.push(argResult);
7325
7393
  if (!argResult.isCompatible) {
7326
7394
  argumentErrors = true;
7327
7395
  }
@@ -7432,6 +7500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7432
7500
  }
7433
7501
  return {
7434
7502
  argumentErrors,
7503
+ argResults,
7435
7504
  isArgumentAnyOrUnknown,
7436
7505
  returnType: specializedReturnType,
7437
7506
  isTypeIncomplete,
@@ -7457,8 +7526,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7457
7526
  // Tries to assign the call arguments to the function parameter
7458
7527
  // list and reports any mismatches in types or counts. Returns the
7459
7528
  // specialized return type of the call.
7460
- function validateFunctionArguments(errorNode, argList, type, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7461
- const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, type, 0);
7529
+ function validateFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
7530
+ const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, typeResult, 0);
7462
7531
  if (matchResults.argumentErrors) {
7463
7532
  // Evaluate types of all args. This will ensure that referenced symbols are
7464
7533
  // not reported as unaccessed.
@@ -7582,13 +7651,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7582
7651
  }
7583
7652
  return !reportedArgError;
7584
7653
  }
7585
- function validateArgType(argParam, typeVarContext, functionType, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7654
+ function validateArgType(argParam, typeVarContext, typeResult, skipUnknownCheck, skipOverloadArg, useNarrowBoundOnly, conditionFilter) {
7586
7655
  var _a;
7587
7656
  let argType;
7588
7657
  let expectedTypeDiag;
7589
- let isTypeIncomplete = false;
7658
+ let isTypeIncomplete = !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete);
7590
7659
  let isCompatible = true;
7591
- const functionName = functionType === null || functionType === void 0 ? void 0 : functionType.details.name;
7660
+ const functionName = typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.name;
7592
7661
  if (argParam.argument.valueExpression) {
7593
7662
  // If the param type is a "bare" TypeVar, don't use it as an expected
7594
7663
  // type. This causes problems for cases where the the call expression
@@ -7598,7 +7667,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7598
7667
  // a wide bound on a TypeVar (if a narrow bound has not yet been established)
7599
7668
  // will unnecessarily constrain the expected type.
7600
7669
  let expectedType;
7601
- if (!(0, types_1.isTypeVar)(argParam.paramType) || argParam.paramType.scopeId !== (functionType === null || functionType === void 0 ? void 0 : functionType.details.typeVarScopeId)) {
7670
+ if (!(0, types_1.isTypeVar)(argParam.paramType) ||
7671
+ argParam.paramType.scopeId !== (typeResult === null || typeResult === void 0 ? void 0 : typeResult.type.details.typeVarScopeId)) {
7602
7672
  expectedType = (0, typeUtils_1.applySolvedTypeVars)(argParam.paramType, typeVarContext, { useNarrowBoundOnly });
7603
7673
  }
7604
7674
  // If the expected type is unknown, don't use an expected type. Instead,
@@ -7616,7 +7686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7616
7686
  32 /* DisallowParamSpec */ |
7617
7687
  64 /* DisallowTypeVarTuple */
7618
7688
  : 0 /* None */;
7619
- const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext));
7689
+ const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, typeVarContext, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete)));
7620
7690
  argType = exprTypeResult.type;
7621
7691
  if (exprTypeResult.isIncomplete) {
7622
7692
  isTypeIncomplete = true;
@@ -8870,6 +8940,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8870
8940
  /* typeVarContext */ undefined,
8871
8941
  /* skipUnknownArgCheck */ true, inferenceContext);
8872
8942
  });
8943
+ // If there were errors with the expected type, try
8944
+ // to evaluate without the expected type.
8945
+ if (callResult.argumentErrors && inferenceContext) {
8946
+ useSpeculativeMode(errorNode, () => {
8947
+ callResult = validateCallArguments(errorNode, functionArgs, { type: magicMethodType },
8948
+ /* typeVarContext */ undefined,
8949
+ /* skipUnknownArgCheck */ true);
8950
+ });
8951
+ }
8873
8952
  if (callResult.argumentErrors) {
8874
8953
  magicMethodSupported = false;
8875
8954
  }
@@ -9496,7 +9575,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9496
9575
  return { type: returnedType || types_1.UnknownType.create() };
9497
9576
  }
9498
9577
  function getTypeOfLambda(node, inferenceContext) {
9499
- let isIncomplete = false;
9578
+ let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
9500
9579
  const functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* PartiallyEvaluated */);
9501
9580
  functionType.details.typeVarScopeId = getScopeIdForNode(node);
9502
9581
  // Pre-cache the incomplete function type in case the evaluation of the
@@ -9601,7 +9680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9601
9680
  isIncomplete = true;
9602
9681
  }
9603
9682
  };
9604
- if (speculativeTypeTracker.isSpeculative(node)) {
9683
+ if (speculativeTypeTracker.isSpeculative(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)) {
9605
9684
  // We need to set allowCacheRetention to false because we don't want to
9606
9685
  // cache the type of the lambda return expression because it depends on
9607
9686
  // the parameter types that we set above, and the speculative type cache
@@ -10997,14 +11076,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10997
11076
  }
10998
11077
  node.arguments.forEach((arg) => {
10999
11078
  // Ignore unpacked arguments.
11000
- if (arg.argumentCategory !== 0 /* Simple */) {
11079
+ if (arg.argumentCategory === 2 /* UnpackedDictionary */) {
11001
11080
  // Evaluate the expression's type so symbols are marked accessed
11002
11081
  // and errors are reported.
11003
11082
  getTypeOfExpression(arg.valueExpression);
11004
11083
  return;
11005
11084
  }
11006
11085
  if (!arg.name) {
11007
- let argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
11086
+ let argType;
11087
+ if (arg.argumentCategory === 1 /* UnpackedList */) {
11088
+ getTypeOfExpression(arg.valueExpression);
11089
+ argType = types_1.UnknownType.create();
11090
+ }
11091
+ else {
11092
+ argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
11093
+ }
11008
11094
  // In some stub files, classes are conditionally defined (e.g. based
11009
11095
  // on platform type). We'll assume that the conditional logic is correct
11010
11096
  // and strip off the "unbound" union.
@@ -11750,7 +11836,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11750
11836
  argument: arg,
11751
11837
  errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
11752
11838
  };
11753
- validateArgType(argParam, new typeVarContext_1.TypeVarContext(), newMethodType,
11839
+ validateArgType(argParam, new typeVarContext_1.TypeVarContext(), { type: newMethodType },
11754
11840
  /* skipUnknownCheck */ true,
11755
11841
  /* skipOverloadArg */ true,
11756
11842
  /* useNarrowBoundOnly */ false,
@@ -13177,6 +13263,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13177
13263
  getTypeOfClass(node.parent);
13178
13264
  return;
13179
13265
  }
13266
+ if (node.parent.nodeType === 23 /* ImportFromAs */) {
13267
+ evaluateTypesForImportFromAs(node.parent);
13268
+ return;
13269
+ }
13270
+ if (node.parent.nodeType === 21 /* ImportAs */) {
13271
+ evaluateTypesForImportAs(node.parent);
13272
+ return;
13273
+ }
13180
13274
  if (node.parent.nodeType === 77 /* TypeAlias */ && node.parent.name === node) {
13181
13275
  getTypeOfTypeAlias(node.parent);
13182
13276
  return;
@@ -14683,9 +14777,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14683
14777
  })) === null || _a === void 0 ? void 0 : _a.type;
14684
14778
  }
14685
14779
  if (resolvedDecl.type === 1 /* Variable */ && resolvedDecl.inferredTypeSource) {
14780
+ const isTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(resolvedDecl) || isPossibleTypeAliasOrTypedDict(resolvedDecl);
14686
14781
  // If this is a type alias, evaluate types for the entire assignment
14687
14782
  // statement rather than just the RHS of the assignment.
14688
- const typeSource = resolvedDecl.typeAliasName && resolvedDecl.inferredTypeSource.parent
14783
+ const typeSource = isTypeAlias && resolvedDecl.inferredTypeSource.parent
14689
14784
  ? resolvedDecl.inferredTypeSource.parent
14690
14785
  : resolvedDecl.inferredTypeSource;
14691
14786
  let inferredType = (_b = evaluateTypeForSubnode(resolvedDecl.node, () => {
@@ -14703,7 +14798,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14703
14798
  inferredType = enumMemberType;
14704
14799
  }
14705
14800
  }
14706
- if (inferredType && resolvedDecl.typeAliasName) {
14801
+ if (inferredType && isTypeAlias && resolvedDecl.typeAliasName) {
14707
14802
  // If this was a speculative type alias, it becomes a real type alias only
14708
14803
  // in the event that its inferred type is instantiable or explicitly Any
14709
14804
  // (but not an ellipsis).
@@ -14879,7 +14974,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14879
14974
  }
14880
14975
  let sawExplicitTypeAlias = false;
14881
14976
  decls.forEach((decl, index) => {
14882
- var _a, _b;
14977
+ var _a, _b, _c;
14883
14978
  let considerDecl = declIndexToConsider === undefined || index === declIndexToConsider;
14884
14979
  // If we have already seen an explicit type alias, do not consider
14885
14980
  // additional decls. This can happen if multiple TypeAlias declarations
@@ -14901,6 +14996,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14901
14996
  }
14902
14997
  }
14903
14998
  if (considerDecl) {
14999
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl,
15000
+ /* resolveLocalNames */ true,
15001
+ /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile)) !== null && _a !== void 0 ? _a : decl;
14904
15002
  const isExplicitTypeAlias = (0, declarationUtils_1.isExplicitTypeAliasDeclaration)(decl);
14905
15003
  const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(decl);
14906
15004
  if (isExplicitTypeAlias) {
@@ -14909,15 +15007,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14909
15007
  // If this is a type alias, evaluate it outside of the recursive symbol
14910
15008
  // resolution check so we can evaluate the full assignment statement.
14911
15009
  if (isTypeAlias &&
14912
- decl.type === 1 /* Variable */ &&
14913
- ((_b = (_a = decl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.nodeType) === 3 /* Assignment */) {
14914
- evaluateTypesForAssignmentStatement(decl.inferredTypeSource.parent);
14915
- if (decl.typeAliasAnnotation) {
15010
+ resolvedDecl.type === 1 /* Variable */ &&
15011
+ ((_c = (_b = resolvedDecl.inferredTypeSource) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
15012
+ evaluateTypesForAssignmentStatement(resolvedDecl.inferredTypeSource.parent);
15013
+ if (resolvedDecl.typeAliasAnnotation) {
14916
15014
  // Mark "TypeAlias" declaration as accessed.
14917
- getTypeOfAnnotation(decl.typeAliasAnnotation, {
15015
+ getTypeOfAnnotation(resolvedDecl.typeAliasAnnotation, {
14918
15016
  isVariableAnnotation: true,
14919
- allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(decl.node),
14920
- allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(decl.node),
15017
+ allowFinal: ParseTreeUtils.isFinalAllowedForAssignmentTarget(resolvedDecl.node),
15018
+ allowClassVar: ParseTreeUtils.isClassVarAllowedForAssignmentTarget(resolvedDecl.node),
14921
15019
  });
14922
15020
  }
14923
15021
  }
@@ -14928,14 +15026,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14928
15026
  isIncomplete = true;
14929
15027
  }
14930
15028
  if (type) {
14931
- if (decl.type === 1 /* Variable */) {
14932
- includesVariableDecl = true;
14933
- let isConstant = decl.type === 1 /* Variable */ && !!decl.isConstant;
15029
+ if (resolvedDecl.type === 1 /* Variable */) {
15030
+ // Exempt typing.pyi, which uses variables to define some
15031
+ // special forms like Any.
15032
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(resolvedDecl.node);
15033
+ if (!fileInfo.isTypingStubFile) {
15034
+ includesVariableDecl = true;
15035
+ }
15036
+ let isConstant = resolvedDecl.type === 1 /* Variable */ && !!resolvedDecl.isConstant;
14934
15037
  // Treat enum values declared within an enum class as though they are const even
14935
15038
  // though they may not be named as such.
14936
15039
  if ((0, types_1.isClassInstance)(type) &&
14937
15040
  types_1.ClassType.isEnumClass(type) &&
14938
- (0, enums_1.isDeclInEnumClass)(evaluatorInterface, decl)) {
15041
+ (0, enums_1.isDeclInEnumClass)(evaluatorInterface, resolvedDecl)) {
14939
15042
  isConstant = true;
14940
15043
  }
14941
15044
  // If the symbol is constant, we can retain the literal
@@ -14960,12 +15063,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14960
15063
  }
14961
15064
  }
14962
15065
  else {
14963
- // If this resolves to a class decl, we can use a partially-evaluated
14964
- // version of the class type.
14965
- const resolvedDecl = resolveAliasDeclaration(decl,
14966
- /* resolveLocalNames */ true,
14967
- /* allowExternallyHiddenAccess */ AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile);
14968
- if ((resolvedDecl === null || resolvedDecl === void 0 ? void 0 : resolvedDecl.type) === 6 /* Class */) {
15066
+ if (resolvedDecl.type === 6 /* Class */) {
14969
15067
  const classTypeInfo = getTypeOfClass(resolvedDecl.node);
14970
15068
  if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
14971
15069
  typesToCombine.push(classTypeInfo.decoratedType);
@@ -16265,10 +16363,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16265
16363
  }
16266
16364
  return true;
16267
16365
  }
16268
- if ((0, types_1.isClassInstance)(destType) && types_1.ClassType.isBuiltIn(destType, 'object')) {
16269
- if ((flags & 1 /* EnforceInvariance */) === 0) {
16270
- // All types (including None, Module, OverloadedFunction) derive from object.
16271
- return true;
16366
+ if ((0, types_1.isClass)(destType) && types_1.ClassType.isBuiltIn(destType, 'object')) {
16367
+ if (((0, types_1.isInstantiableClass)(destType) && types_1.TypeBase.isInstantiable(srcType)) || (0, types_1.isClassInstance)(destType)) {
16368
+ if ((flags & 1 /* EnforceInvariance */) === 0) {
16369
+ // All types (including None, Module, OverloadedFunction) derive from object.
16370
+ return true;
16371
+ }
16272
16372
  }
16273
16373
  }
16274
16374
  // Are we trying to assign None to a protocol?