@zzzen/pyright-internal 1.2.0-dev.20230827 → 1.2.0-dev.20230903

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 (142) hide show
  1. package/dist/analyzer/binder.js +4 -1
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +1 -0
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +1 -2
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/deprecatedSymbols.js +13 -2
  8. package/dist/analyzer/deprecatedSymbols.js.map +1 -1
  9. package/dist/analyzer/importResolver.d.ts +6 -4
  10. package/dist/analyzer/importResolver.js +16 -11
  11. package/dist/analyzer/importResolver.js.map +1 -1
  12. package/dist/analyzer/namedTuples.js +1 -1
  13. package/dist/analyzer/namedTuples.js.map +1 -1
  14. package/dist/analyzer/packageTypeVerifier.d.ts +3 -3
  15. package/dist/analyzer/packageTypeVerifier.js +8 -11
  16. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  17. package/dist/analyzer/program.d.ts +7 -20
  18. package/dist/analyzer/program.js +89 -83
  19. package/dist/analyzer/program.js.map +1 -1
  20. package/dist/analyzer/protocols.js +3 -1
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/service.d.ts +6 -3
  23. package/dist/analyzer/service.js +26 -8
  24. package/dist/analyzer/service.js.map +1 -1
  25. package/dist/analyzer/sourceFile.d.ts +6 -4
  26. package/dist/analyzer/sourceFile.js +9 -16
  27. package/dist/analyzer/sourceFile.js.map +1 -1
  28. package/dist/analyzer/sourceFileInfo.d.ts +62 -0
  29. package/dist/analyzer/sourceFileInfo.js +145 -0
  30. package/dist/analyzer/sourceFileInfo.js.map +1 -0
  31. package/dist/analyzer/sourceMapper.d.ts +1 -1
  32. package/dist/analyzer/typeEvaluator.js +199 -160
  33. package/dist/analyzer/typeEvaluator.js.map +1 -1
  34. package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
  35. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  36. package/dist/analyzer/typeGuards.js +78 -14
  37. package/dist/analyzer/typeGuards.js.map +1 -1
  38. package/dist/analyzer/typeUtils.js +23 -9
  39. package/dist/analyzer/typeUtils.js.map +1 -1
  40. package/dist/analyzer/typeWalker.js +1 -1
  41. package/dist/analyzer/typeWalker.js.map +1 -1
  42. package/dist/backgroundAnalysis.d.ts +1 -2
  43. package/dist/backgroundAnalysis.js +2 -2
  44. package/dist/backgroundAnalysis.js.map +1 -1
  45. package/dist/backgroundAnalysisBase.d.ts +1 -2
  46. package/dist/backgroundAnalysisBase.js +4 -4
  47. package/dist/backgroundAnalysisBase.js.map +1 -1
  48. package/dist/backgroundThreadBase.d.ts +1 -1
  49. package/dist/backgroundThreadBase.js +1 -0
  50. package/dist/backgroundThreadBase.js.map +1 -1
  51. package/dist/common/commandLineOptions.d.ts +1 -0
  52. package/dist/common/commandLineOptions.js.map +1 -1
  53. package/dist/common/configOptions.d.ts +4 -1
  54. package/dist/common/configOptions.js +16 -3
  55. package/dist/common/configOptions.js.map +1 -1
  56. package/dist/common/console.d.ts +3 -0
  57. package/dist/common/console.js +8 -1
  58. package/dist/common/console.js.map +1 -1
  59. package/dist/common/extensibility.d.ts +4 -1
  60. package/dist/common/extensibility.js.map +1 -1
  61. package/dist/common/fileSystem.d.ts +3 -0
  62. package/dist/common/fileSystem.js +8 -1
  63. package/dist/common/fileSystem.js.map +1 -1
  64. package/dist/common/serviceProvider.d.ts +1 -4
  65. package/dist/common/serviceProvider.js +4 -4
  66. package/dist/common/serviceProvider.js.map +1 -1
  67. package/dist/common/serviceProviderExtensions.d.ts +10 -4
  68. package/dist/common/serviceProviderExtensions.js +43 -1
  69. package/dist/common/serviceProviderExtensions.js.map +1 -1
  70. package/dist/languageServerBase.d.ts +8 -8
  71. package/dist/languageServerBase.js +3 -2
  72. package/dist/languageServerBase.js.map +1 -1
  73. package/dist/languageService/analyzerServiceExecutor.js +3 -2
  74. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  75. package/dist/languageService/completionProvider.d.ts +4 -3
  76. package/dist/languageService/completionProvider.js +178 -170
  77. package/dist/languageService/completionProvider.js.map +1 -1
  78. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  79. package/dist/languageService/completionProviderUtils.js +1 -1
  80. package/dist/languageService/completionProviderUtils.js.map +1 -1
  81. package/dist/localization/localize.d.ts +5 -0
  82. package/dist/localization/localize.js +1 -0
  83. package/dist/localization/localize.js.map +1 -1
  84. package/dist/localization/package.nls.cs.json +18 -15
  85. package/dist/localization/package.nls.de.json +18 -15
  86. package/dist/localization/package.nls.en-us.json +4 -3
  87. package/dist/localization/package.nls.es.json +18 -15
  88. package/dist/localization/package.nls.fr.json +18 -15
  89. package/dist/localization/package.nls.it.json +18 -15
  90. package/dist/localization/package.nls.ja.json +18 -15
  91. package/dist/localization/package.nls.ko.json +18 -15
  92. package/dist/localization/package.nls.pl.json +18 -15
  93. package/dist/localization/package.nls.pt-br.json +18 -15
  94. package/dist/localization/package.nls.qps-ploc.json +6 -3
  95. package/dist/localization/package.nls.ru.json +18 -15
  96. package/dist/localization/package.nls.tr.json +18 -15
  97. package/dist/localization/package.nls.zh-cn.json +18 -15
  98. package/dist/localization/package.nls.zh-tw.json +18 -15
  99. package/dist/pyright.js +6 -4
  100. package/dist/pyright.js.map +1 -1
  101. package/dist/server.d.ts +2 -2
  102. package/dist/server.js +6 -9
  103. package/dist/server.js.map +1 -1
  104. package/dist/tests/chainedSourceFiles.test.js +4 -1
  105. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  106. package/dist/tests/checker.test.js +9 -9
  107. package/dist/tests/checker.test.js.map +1 -1
  108. package/dist/tests/completions.test.js +30 -0
  109. package/dist/tests/completions.test.js.map +1 -1
  110. package/dist/tests/config.test.js +23 -17
  111. package/dist/tests/config.test.js.map +1 -1
  112. package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +8 -8
  113. package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -1
  114. package/dist/tests/fourslash/importnotresolved.fourslash.js +2 -2
  115. package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -1
  116. package/dist/tests/fourslash/missingModuleSource.fourslash.js +4 -1
  117. package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
  118. package/dist/tests/harness/fourslash/testLanguageService.js +4 -1
  119. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  120. package/dist/tests/harness/fourslash/testState.d.ts +2 -0
  121. package/dist/tests/harness/fourslash/testState.js +5 -1
  122. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  123. package/dist/tests/importResolver.test.js +14 -9
  124. package/dist/tests/importResolver.test.js.map +1 -1
  125. package/dist/tests/localizer.test.js +1 -1
  126. package/dist/tests/localizer.test.js.map +1 -1
  127. package/dist/tests/service.test.js +55 -0
  128. package/dist/tests/service.test.js.map +1 -1
  129. package/dist/tests/sourceFile.test.js +4 -2
  130. package/dist/tests/sourceFile.test.js.map +1 -1
  131. package/dist/tests/testUtils.js +3 -5
  132. package/dist/tests/testUtils.js.map +1 -1
  133. package/dist/tests/typeEvaluator1.test.js +2 -2
  134. package/dist/tests/typeEvaluator2.test.js +5 -1
  135. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  136. package/dist/tests/typeEvaluator3.test.js +3 -3
  137. package/dist/tests/workspaceEditUtils.test.js +24 -20
  138. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  139. package/dist/workspaceFactory.d.ts +1 -0
  140. package/dist/workspaceFactory.js +12 -3
  141. package/dist/workspaceFactory.js.map +1 -1
  142. package/package.json +1 -1
@@ -886,13 +886,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
886
886
  function getTypeOfString(node) {
887
887
  const isBytes = (node.token.flags & 32 /* Bytes */) !== 0;
888
888
  let typeResult;
889
+ let isIncomplete = false;
889
890
  // Don't create a literal type if it's an f-string.
890
891
  if (node.nodeType === 27 /* FormatString */) {
891
892
  let isLiteralString = true;
892
893
  // If all of the format expressions are of type LiteralString, then
893
894
  // the resulting formatted string is also LiteralString.
894
895
  node.fieldExpressions.forEach((expr) => {
895
- const exprType = getTypeOfExpression(expr).type;
896
+ const exprTypeResult = getTypeOfExpression(expr);
897
+ const exprType = exprTypeResult.type;
898
+ if (exprTypeResult.isIncomplete) {
899
+ isIncomplete = true;
900
+ }
896
901
  (0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
897
902
  if (!(0, types_1.isClassInstance)(exprSubtype)) {
898
903
  isLiteralString = false;
@@ -910,18 +915,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
910
915
  if (!isBytes && isLiteralString) {
911
916
  const literalStringType = getTypingType(node, 'LiteralString');
912
917
  if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
913
- typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType) };
918
+ typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType), isIncomplete };
914
919
  }
915
920
  }
916
921
  if (!typeResult) {
917
922
  typeResult = {
918
923
  type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
924
+ isIncomplete,
919
925
  };
920
926
  }
921
927
  }
922
928
  else {
923
929
  typeResult = {
924
930
  type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.value),
931
+ isIncomplete,
925
932
  };
926
933
  }
927
934
  return typeResult;
@@ -8242,15 +8249,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8242
8249
  }
8243
8250
  const condition = argType.condition;
8244
8251
  let diag = new diagnostic_1.DiagnosticAddendum();
8245
- // Handle the case where we're assigning a *args or **kwargs argument
8246
- // to a *P.args or **P.kwargs parameter.
8247
- if ((0, types_1.isParamSpec)(argParam.paramType) && argParam.paramType.paramSpecAccess !== undefined) {
8248
- return { isCompatible, argType, isTypeIncomplete, condition };
8249
- }
8250
- // Handle the case where we're assigning a *P.args or **P.kwargs argument
8251
- // to a *P.args or **P.kwargs parameter.
8252
- if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess !== undefined) {
8253
- return { isCompatible, argType, isTypeIncomplete, condition };
8252
+ if ((0, types_1.isParamSpec)(argParam.paramType)) {
8253
+ // Handle the case where we're assigning a *args or **kwargs argument
8254
+ // to a *P.args or **P.kwargs parameter.
8255
+ if (argParam.paramType.paramSpecAccess !== undefined) {
8256
+ return { isCompatible, argType, isTypeIncomplete, condition };
8257
+ }
8258
+ // Handle the case where we're assigning a *P.args or **P.kwargs argument
8259
+ // to a *P.args or **P.kwargs parameter.
8260
+ if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess !== undefined) {
8261
+ return { isCompatible, argType, isTypeIncomplete, condition };
8262
+ }
8254
8263
  }
8255
8264
  // If we are asked to skip overload arguments, determine whether the argument
8256
8265
  // is an explicit overload type, an overloaded class constructor, or a
@@ -10141,7 +10150,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10141
10150
  }
10142
10151
  }
10143
10152
  if (!type) {
10144
- const exprType = getTypeOfExpression(itemExpr);
10153
+ const exprType = getTypeOfExpression(itemExpr, flags & 4 /* AllowForwardReferences */);
10145
10154
  // Is this an enum type?
10146
10155
  if ((0, types_1.isClassInstance)(exprType.type) &&
10147
10156
  types_1.ClassType.isEnumClass(exprType.type) &&
@@ -12852,6 +12861,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12852
12861
  setSymbolAccessed(fileInfo, symbolInScope.symbol, node);
12853
12862
  }
12854
12863
  }
12864
+ // If this is an import into a class scope, mark the symbol as accessed.
12865
+ const classNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
12866
+ if (classNode) {
12867
+ const symbolInScope = lookUpSymbolRecursive(node, aliasNode.value, /* honorCodeFlow */ true);
12868
+ if (symbolInScope) {
12869
+ setSymbolAccessed(fileInfo, symbolInScope.symbol, node);
12870
+ }
12871
+ }
12855
12872
  let symbolType = getAliasedSymbolTypeForName(node, aliasNode.value);
12856
12873
  if (!symbolType) {
12857
12874
  const parentNode = node.parent;
@@ -14844,6 +14861,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14844
14861
  isIncomplete,
14845
14862
  includesVariableDecl: typedDecls.some((decl) => decl.type === 1 /* Variable */),
14846
14863
  includesIllegalTypeAliasDecl: !typedDecls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
14864
+ includesSpeculativeResult: false,
14847
14865
  isRecursiveDefinition: !declaredType,
14848
14866
  };
14849
14867
  return result;
@@ -14862,12 +14880,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14862
14880
  }
14863
14881
  }
14864
14882
  // Infer the type.
14865
- const typesToCombine = [];
14866
14883
  const decls = symbol.getDeclarations();
14867
- let isIncomplete = false;
14868
- let sawPendingEvaluation = false;
14869
- let includesVariableDecl = false;
14870
- let includesSpeculativeResult = false;
14871
14884
  let declIndexToConsider;
14872
14885
  // Limit the number of declarations to explore.
14873
14886
  if (decls.length > maxDeclarationsToUseForInference) {
@@ -14876,6 +14889,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14876
14889
  isIncomplete: false,
14877
14890
  includesVariableDecl: false,
14878
14891
  includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
14892
+ includesSpeculativeResult: false,
14879
14893
  isRecursiveDefinition: false,
14880
14894
  };
14881
14895
  addToEffectiveTypeCache(result);
@@ -14902,22 +14916,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14902
14916
  }
14903
14917
  }
14904
14918
  }
14919
+ // Determine which declarations to use for inference.
14920
+ const declsToConsider = [];
14905
14921
  let sawExplicitTypeAlias = false;
14906
14922
  decls.forEach((decl, index) => {
14907
14923
  var _a, _b, _c;
14908
- let considerDecl = declIndexToConsider === undefined || index === declIndexToConsider;
14924
+ if (declIndexToConsider !== undefined && declIndexToConsider !== index) {
14925
+ return;
14926
+ }
14909
14927
  // If we have already seen an explicit type alias, do not consider
14910
14928
  // additional decls. This can happen if multiple TypeAlias declarations
14911
14929
  // are provided -- normally an error, but it can happen in stdlib stubs
14912
14930
  // if the user sets the pythonPlatform to "All".
14913
14931
  if (sawExplicitTypeAlias) {
14914
- considerDecl = false;
14932
+ return;
14915
14933
  }
14916
14934
  // If the symbol is explicitly marked as a ClassVar, consider only the
14917
14935
  // declarations that assign to it from within the class body, not through
14918
14936
  // a member access expression.
14919
14937
  if (symbol.isClassVar() && decl.type === 1 /* Variable */ && decl.isDefinedByMemberAccess) {
14920
- considerDecl = false;
14938
+ return;
14921
14939
  }
14922
14940
  if (usageNode !== undefined) {
14923
14941
  if (decl.type !== 8 /* Alias */) {
@@ -14926,122 +14944,133 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14926
14944
  const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
14927
14945
  if (usageScope === declScope) {
14928
14946
  if (!isFlowPathBetweenNodes(decl.node, usageNode)) {
14929
- considerDecl = false;
14947
+ return;
14930
14948
  }
14931
14949
  }
14932
14950
  }
14933
14951
  }
14934
- if (considerDecl) {
14935
- const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
14936
- allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
14937
- })) !== null && _a !== void 0 ? _a : decl;
14938
- const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
14939
- const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
14940
- if (isExplicitTypeAlias) {
14941
- sawExplicitTypeAlias = true;
14942
- }
14943
- // If this is a type alias, evaluate it outside of the recursive symbol
14944
- // resolution check so we can evaluate the full assignment statement.
14945
- if (isTypeAlias &&
14946
- resolvedDecl.type === 1 /* Variable */ &&
14947
- ((_c = (_b = resolvedDecl.inferredTypeSource) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
14948
- evaluateTypesForAssignmentStatement(resolvedDecl.inferredTypeSource.parent);
14949
- }
14950
- if (pushSymbolResolution(symbol, decl)) {
14951
- try {
14952
- let type = getInferredTypeOfDeclaration(symbol, decl);
14953
- if (!popSymbolResolution(symbol)) {
14954
- isIncomplete = true;
14955
- }
14956
- if (type) {
14957
- if (resolvedDecl.type === 1 /* Variable */) {
14958
- // Exempt typing.pyi, which uses variables to define some
14959
- // special forms like Any.
14960
- const fileInfo = AnalyzerNodeInfo.getFileInfo(resolvedDecl.node);
14961
- if (!fileInfo.isTypingStubFile) {
14962
- includesVariableDecl = true;
14963
- }
14964
- let isConstant = false;
14965
- if (resolvedDecl.type === 1 /* Variable */) {
14966
- if (resolvedDecl.isConstant || isFinalVariableDeclaration(resolvedDecl)) {
14967
- isConstant = true;
14968
- }
14969
- }
14970
- // Treat enum values declared within an enum class as though they are const even
14971
- // though they may not be named as such.
14972
- if ((0, types_1.isClassInstance)(type) &&
14973
- types_1.ClassType.isEnumClass(type) &&
14974
- (0, enums_1.isDeclInEnumClass)(evaluatorInterface, resolvedDecl)) {
14952
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
14953
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
14954
+ })) !== null && _a !== void 0 ? _a : decl;
14955
+ const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
14956
+ const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
14957
+ if (isExplicitTypeAlias) {
14958
+ sawExplicitTypeAlias = true;
14959
+ }
14960
+ // If this is a type alias, evaluate it outside of the recursive symbol
14961
+ // resolution check so we can evaluate the full assignment statement.
14962
+ if (isTypeAlias &&
14963
+ resolvedDecl.type === 1 /* Variable */ &&
14964
+ ((_c = (_b = resolvedDecl.inferredTypeSource) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
14965
+ evaluateTypesForAssignmentStatement(resolvedDecl.inferredTypeSource.parent);
14966
+ }
14967
+ declsToConsider.push(resolvedDecl);
14968
+ });
14969
+ const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
14970
+ const result = getTypeOfSymbolForDecls(symbol, declsToConsider, evaluationAttempts);
14971
+ // Add the result to the effective type cache if it doesn't include speculative results.
14972
+ if (!result.includesSpeculativeResult) {
14973
+ addToEffectiveTypeCache(result);
14974
+ }
14975
+ return result;
14976
+ function addToEffectiveTypeCache(result) {
14977
+ // Add the entry to the cache so we don't need to compute it next time.
14978
+ if (!cacheEntries) {
14979
+ cacheEntries = new Map();
14980
+ effectiveTypeCache.set(symbol.id, cacheEntries);
14981
+ }
14982
+ cacheEntries.set(effectiveTypeCacheKey, result);
14983
+ }
14984
+ }
14985
+ // Returns the type of a symbol based on a subset of its declarations.
14986
+ function getTypeOfSymbolForDecls(symbol, decls, evaluationAttempts) {
14987
+ const typesToCombine = [];
14988
+ let isIncomplete = false;
14989
+ let sawPendingEvaluation = false;
14990
+ let includesVariableDecl = false;
14991
+ let includesSpeculativeResult = false;
14992
+ decls.forEach((decl) => {
14993
+ if (pushSymbolResolution(symbol, decl)) {
14994
+ try {
14995
+ let type = getInferredTypeOfDeclaration(symbol, decl);
14996
+ if (!popSymbolResolution(symbol)) {
14997
+ isIncomplete = true;
14998
+ }
14999
+ if (type) {
15000
+ if (decl.type === 1 /* Variable */) {
15001
+ // Exempt typing.pyi, which uses variables to define some
15002
+ // special forms like Any.
15003
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(decl.node);
15004
+ if (!fileInfo.isTypingStubFile) {
15005
+ includesVariableDecl = true;
15006
+ }
15007
+ let isConstant = false;
15008
+ if (decl.type === 1 /* Variable */) {
15009
+ if (decl.isConstant || isFinalVariableDeclaration(decl)) {
14975
15010
  isConstant = true;
14976
15011
  }
14977
- // If the symbol is constant, we can retain the literal
14978
- // value. Otherwise, strip literal values to widen the type.
14979
- if (types_1.TypeBase.isInstance(type) && !isExplicitTypeAlias && !isConstant) {
14980
- type = stripLiteralValue(type);
14981
- }
14982
15012
  }
14983
- typesToCombine.push(type);
14984
- if (isSpeculativeModeInUse(decl.node)) {
14985
- includesSpeculativeResult = true;
15013
+ // Treat enum values declared within an enum class as though they are const even
15014
+ // though they may not be named as such.
15015
+ if ((0, types_1.isClassInstance)(type) &&
15016
+ types_1.ClassType.isEnumClass(type) &&
15017
+ (0, enums_1.isDeclInEnumClass)(evaluatorInterface, decl)) {
15018
+ isConstant = true;
15019
+ }
15020
+ // If the symbol is constant, we can retain the literal
15021
+ // value. Otherwise, strip literal values to widen the type.
15022
+ if (types_1.TypeBase.isInstance(type) && !isConstant && !isExplicitTypeAliasDeclaration(decl)) {
15023
+ type = stripLiteralValue(type);
14986
15024
  }
14987
15025
  }
14988
- else {
14989
- isIncomplete = true;
15026
+ typesToCombine.push(type);
15027
+ if (isSpeculativeModeInUse(decl.node)) {
15028
+ includesSpeculativeResult = true;
14990
15029
  }
14991
15030
  }
14992
- catch (e) {
14993
- // Clean up the stack before rethrowing.
14994
- popSymbolResolution(symbol);
14995
- throw e;
15031
+ else {
15032
+ isIncomplete = true;
14996
15033
  }
14997
15034
  }
14998
- else {
14999
- if (resolvedDecl.type === 6 /* Class */) {
15000
- const classTypeInfo = getTypeOfClass(resolvedDecl.node);
15001
- if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
15002
- typesToCombine.push(classTypeInfo.decoratedType);
15003
- }
15035
+ catch (e) {
15036
+ // Clean up the stack before rethrowing.
15037
+ popSymbolResolution(symbol);
15038
+ throw e;
15039
+ }
15040
+ }
15041
+ else {
15042
+ if (decl.type === 6 /* Class */) {
15043
+ const classTypeInfo = getTypeOfClass(decl.node);
15044
+ if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
15045
+ typesToCombine.push(classTypeInfo.decoratedType);
15004
15046
  }
15005
- isIncomplete = true;
15006
- // Note that at least one decl could not be evaluated because
15007
- // it was already in the process of being evaluated.
15008
- sawPendingEvaluation = true;
15009
15047
  }
15048
+ isIncomplete = true;
15049
+ // Note that at least one decl could not be evaluated because
15050
+ // it was already in the process of being evaluated.
15051
+ sawPendingEvaluation = true;
15010
15052
  }
15011
15053
  });
15012
- // How many times have we already attempted to evaluate this declaration already?
15013
- const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
15014
- let resultType;
15054
+ let type;
15015
15055
  if (typesToCombine.length > 0) {
15016
15056
  // Ignore the pending evaluation flag if we've already attempted the
15017
15057
  // type evaluation many times because this probably means there's a
15018
15058
  // cyclical dependency that cannot be broken.
15019
15059
  isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
15020
- resultType = (0, types_1.combineTypes)(typesToCombine);
15060
+ type = (0, types_1.combineTypes)(typesToCombine);
15021
15061
  }
15022
15062
  else {
15023
- resultType = types_1.UnboundType.create();
15063
+ type = types_1.UnboundType.create();
15024
15064
  }
15025
- const result = {
15026
- type: resultType,
15065
+ return {
15066
+ type,
15027
15067
  isIncomplete,
15028
15068
  includesVariableDecl,
15029
15069
  includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
15070
+ includesSpeculativeResult,
15030
15071
  isRecursiveDefinition: false,
15031
15072
  evaluationAttempts,
15032
15073
  };
15033
- if (!includesSpeculativeResult) {
15034
- addToEffectiveTypeCache(result);
15035
- }
15036
- return result;
15037
- function addToEffectiveTypeCache(result) {
15038
- // Add the entry to the cache so we don't need to compute it next time.
15039
- if (!cacheEntries) {
15040
- cacheEntries = new Map();
15041
- effectiveTypeCache.set(symbol.id, cacheEntries);
15042
- }
15043
- cacheEntries.set(effectiveTypeCacheKey, result);
15044
- }
15045
15074
  }
15046
15075
  // If a declaration has an explicit type (e.g. a variable with an annotation),
15047
15076
  // this function evaluates the type and returns it. If the symbol has no
@@ -15595,72 +15624,65 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15595
15624
  });
15596
15625
  return isAssignable;
15597
15626
  }
15598
- // Adjusts the source type arguments list to match the length of the
15599
- // dest type arguments list if the dest list contains an unbounded
15600
- // or variadic entry.
15601
- function adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs) {
15602
- const destVariadicIndex = destTypeArgs.findIndex((t) => (0, types_1.isVariadicTypeVar)(t.type));
15603
- const destUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
15627
+ // Adjusts the source and/or dest type arguments list to attempt to match
15628
+ // the length of the src type arguments list if the dest or source contain
15629
+ // entries with indeterminate length or variadic entries. It returns true
15630
+ // if the source is potentially compatible with the dest type, false otherwise.
15631
+ function adjustSrcTupleTypeArgs(destTypeArgs, srcTypeArgs) {
15632
+ const destUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isVariadicTypeVar)(t.type));
15604
15633
  const srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
15605
- // If the source is unbounded, expand the unbounded argument to try
15606
- // to make the source and dest arg counts match.
15634
+ // If the src contains an unbounded type but the dest does not, it's incompatible.
15635
+ if (srcUnboundedIndex >= 0 && destUnboundedIndex < 0) {
15636
+ return false;
15637
+ }
15607
15638
  if (srcUnboundedIndex >= 0) {
15639
+ // The source is unbounded, so expand the unbounded argument to try
15640
+ // to make the source and dest arg counts match.
15608
15641
  const typeToReplicate = srcTypeArgs.length > 0 ? srcTypeArgs[srcUnboundedIndex].type : types_1.AnyType.create();
15609
15642
  while (srcTypeArgs.length < destTypeArgs.length) {
15610
15643
  srcTypeArgs.splice(srcUnboundedIndex, 0, { type: typeToReplicate, isUnbounded: true });
15611
15644
  }
15612
15645
  }
15613
- // If the dest is unbounded or contains a variadic, determine which
15614
- // source args map to the unbounded or variadic arg.
15615
- if (destUnboundedIndex >= 0 || destVariadicIndex >= 0) {
15616
- // If there's a variadic within the destination, package up the corresponding
15617
- // source arguments into a tuple.
15618
- const srcArgsToCapture = srcTypeArgs.length - destTypeArgs.length + 1;
15619
- if (srcArgsToCapture >= 0) {
15620
- if (destVariadicIndex >= 0) {
15621
- if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
15622
- const removedArgs = srcTypeArgs.splice(destVariadicIndex, srcArgsToCapture);
15623
- // Package up the remaining type arguments into a tuple object.
15624
- const variadicTuple = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, removedArgs.map((typeArg) => {
15625
- return { type: typeArg.type, isUnbounded: typeArg.isUnbounded };
15626
- }),
15627
- /* isTypeArgumentExplicit */ true,
15628
- /* isUnpackedTuple */ true));
15629
- srcTypeArgs.splice(destVariadicIndex, 0, {
15630
- type: variadicTuple,
15631
- isUnbounded: false,
15632
- });
15633
- }
15634
- }
15635
- else {
15636
- const removedArgTypes = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture).map((t) => {
15637
- if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
15638
- return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
15639
- }
15640
- return t.type;
15641
- });
15646
+ const srcArgsToCapture = srcTypeArgs.length - destTypeArgs.length + 1;
15647
+ if (destUnboundedIndex >= 0 && srcArgsToCapture >= 0) {
15648
+ // If the dest contains a variadic element, determine which source
15649
+ // args map to this element and package them up into an unpacked tuple.
15650
+ if ((0, types_1.isVariadicTypeVar)(destTypeArgs[destUnboundedIndex].type)) {
15651
+ if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
15652
+ const removedArgs = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture);
15653
+ // Package up the remaining type arguments into a tuple object.
15654
+ const variadicTuple = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, removedArgs.map((typeArg) => {
15655
+ return { type: typeArg.type, isUnbounded: typeArg.isUnbounded };
15656
+ }),
15657
+ /* isTypeArgumentExplicit */ true,
15658
+ /* isUnpackedTuple */ true));
15642
15659
  srcTypeArgs.splice(destUnboundedIndex, 0, {
15643
- type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
15660
+ type: variadicTuple,
15644
15661
  isUnbounded: false,
15645
15662
  });
15646
15663
  }
15647
15664
  }
15665
+ else {
15666
+ const removedArgTypes = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture).map((t) => {
15667
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
15668
+ return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
15669
+ }
15670
+ return t.type;
15671
+ });
15672
+ srcTypeArgs.splice(destUnboundedIndex, 0, {
15673
+ type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
15674
+ isUnbounded: false,
15675
+ });
15676
+ }
15648
15677
  }
15678
+ return destTypeArgs.length === srcTypeArgs.length;
15649
15679
  }
15650
15680
  function assignTupleTypeArguments(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
15651
15681
  var _a, _b;
15652
15682
  const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
15653
15683
  const srcTypeArgs = [...((_b = srcType.tupleTypeArguments) !== null && _b !== void 0 ? _b : [])];
15654
- let srcUnboundedIndex;
15655
- if (flags & 2 /* ReverseTypeVarMatching */) {
15656
- adjustSourceTupleTypeArgs(srcTypeArgs, destTypeArgs);
15657
- srcUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded);
15658
- }
15659
- else {
15660
- adjustSourceTupleTypeArgs(destTypeArgs, srcTypeArgs);
15661
- srcUnboundedIndex = srcTypeArgs.findIndex((t) => t.isUnbounded);
15662
- }
15663
- if (srcTypeArgs.length === destTypeArgs.length) {
15684
+ const reverseMapping = (flags & 2 /* ReverseTypeVarMatching */) !== 0;
15685
+ if (adjustSrcTupleTypeArgs(reverseMapping ? srcTypeArgs : destTypeArgs, reverseMapping ? destTypeArgs : srcTypeArgs)) {
15664
15686
  for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
15665
15687
  const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
15666
15688
  if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
@@ -15674,13 +15696,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15674
15696
  }
15675
15697
  }
15676
15698
  else {
15677
- if (srcUnboundedIndex < 0) {
15699
+ if (srcTypeArgs.find((t) => t.isUnbounded)) {
15700
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleSizeIndeterminate().format({
15701
+ expected: destTypeArgs.length,
15702
+ }));
15703
+ }
15704
+ else {
15678
15705
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleSizeMismatch().format({
15679
15706
  expected: destTypeArgs.length,
15680
15707
  received: srcTypeArgs.length,
15681
15708
  }));
15682
- return false;
15683
15709
  }
15710
+ return false;
15684
15711
  }
15685
15712
  return true;
15686
15713
  }
@@ -15939,7 +15966,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15939
15966
  if ((0, types_1.isTypeVar)(destType)) {
15940
15967
  if ((0, typeUtils_1.isTypeVarSame)(destType, srcType)) {
15941
15968
  if (destType.scopeId && (destTypeVarContext === null || destTypeVarContext === void 0 ? void 0 : destTypeVarContext.hasSolveForScope(destType.scopeId))) {
15942
- return (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount);
15969
+ // If the dest TypeVar has no current value bound to it, bind itself.
15970
+ if (!destTypeVarContext.getPrimarySignature().getTypeVar(destType)) {
15971
+ return (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount);
15972
+ }
15943
15973
  }
15944
15974
  return true;
15945
15975
  }
@@ -16040,6 +16070,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16040
16070
  destType.details.parameters.length <= 2) {
16041
16071
  return true;
16042
16072
  }
16073
+ // If the source is an unpacked TypeVarTuple and the dest is a
16074
+ // *tuple[Any, ...], we'll treat it as compatible.
16075
+ if ((0, types_1.isUnpackedVariadicTypeVar)(srcType) &&
16076
+ (0, types_1.isClassInstance)(destType) &&
16077
+ (0, types_1.isUnpackedClass)(destType) &&
16078
+ destType.tupleTypeArguments &&
16079
+ destType.tupleTypeArguments.length === 1 &&
16080
+ destType.tupleTypeArguments[0].isUnbounded &&
16081
+ (0, types_1.isAnyOrUnknown)(destType.tupleTypeArguments[0].type)) {
16082
+ return true;
16083
+ }
16043
16084
  if (!(0, types_1.isUnion)(destType)) {
16044
16085
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16045
16086
  return false;
@@ -17770,8 +17811,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17770
17811
  if (!targetParamType) {
17771
17812
  targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
17772
17813
  }
17773
- if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)),
17774
- /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
17814
+ if (!assignType(targetParamType, paramInfo.type, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), 8 /* SkipSolveTypeVars */)) {
17775
17815
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
17776
17816
  name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
17777
17817
  baseType: printType(paramInfo.type),
@@ -17829,8 +17869,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17829
17869
  // Now check the return type.
17830
17870
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
17831
17871
  const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
17832
- if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)),
17833
- /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
17872
+ if (!assignType(baseReturnType, overrideReturnType, diag === null || diag === void 0 ? void 0 : diag.createAddendum(), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(baseMethod)), new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(overrideMethod)), 8 /* SkipSolveTypeVars */)) {
17834
17873
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideReturnType().format({
17835
17874
  baseType: printType(baseReturnType),
17836
17875
  overrideType: printType(overrideReturnType),