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

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 (191) 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 +40 -14
  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/constraintSolver.js +5 -0
  8. package/dist/analyzer/constraintSolver.js.map +1 -1
  9. package/dist/analyzer/constructors.js +16 -7
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/declarationUtils.js +2 -0
  12. package/dist/analyzer/declarationUtils.js.map +1 -1
  13. package/dist/analyzer/decorators.js +16 -1
  14. package/dist/analyzer/decorators.js.map +1 -1
  15. package/dist/analyzer/deprecatedSymbols.js +13 -2
  16. package/dist/analyzer/deprecatedSymbols.js.map +1 -1
  17. package/dist/analyzer/importResolver.d.ts +6 -4
  18. package/dist/analyzer/importResolver.js +20 -18
  19. package/dist/analyzer/importResolver.js.map +1 -1
  20. package/dist/analyzer/namedTuples.js +1 -1
  21. package/dist/analyzer/namedTuples.js.map +1 -1
  22. package/dist/analyzer/packageTypeVerifier.d.ts +3 -3
  23. package/dist/analyzer/packageTypeVerifier.js +8 -11
  24. package/dist/analyzer/packageTypeVerifier.js.map +1 -1
  25. package/dist/analyzer/parentDirectoryCache.js +1 -1
  26. package/dist/analyzer/parentDirectoryCache.js.map +1 -1
  27. package/dist/analyzer/program.d.ts +9 -22
  28. package/dist/analyzer/program.js +117 -105
  29. package/dist/analyzer/program.js.map +1 -1
  30. package/dist/analyzer/protocols.js +3 -1
  31. package/dist/analyzer/protocols.js.map +1 -1
  32. package/dist/analyzer/pythonPathUtils.js +10 -8
  33. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  34. package/dist/analyzer/service.d.ts +6 -3
  35. package/dist/analyzer/service.js +40 -20
  36. package/dist/analyzer/service.js.map +1 -1
  37. package/dist/analyzer/sourceFile.d.ts +6 -4
  38. package/dist/analyzer/sourceFile.js +9 -16
  39. package/dist/analyzer/sourceFile.js.map +1 -1
  40. package/dist/analyzer/sourceFileInfo.d.ts +62 -0
  41. package/dist/analyzer/sourceFileInfo.js +145 -0
  42. package/dist/analyzer/sourceFileInfo.js.map +1 -0
  43. package/dist/analyzer/sourceMapper.d.ts +1 -1
  44. package/dist/analyzer/typeDocStringUtils.js +1 -1
  45. package/dist/analyzer/typeEvaluator.js +361 -262
  46. package/dist/analyzer/typeEvaluator.js.map +1 -1
  47. package/dist/analyzer/typeEvaluatorTypes.d.ts +10 -8
  48. package/dist/analyzer/typeEvaluatorTypes.js +11 -8
  49. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  50. package/dist/analyzer/typeGuards.js +116 -20
  51. package/dist/analyzer/typeGuards.js.map +1 -1
  52. package/dist/analyzer/typeUtils.d.ts +6 -4
  53. package/dist/analyzer/typeUtils.js +104 -63
  54. package/dist/analyzer/typeUtils.js.map +1 -1
  55. package/dist/analyzer/typeWalker.js +1 -1
  56. package/dist/analyzer/typeWalker.js.map +1 -1
  57. package/dist/analyzer/types.d.ts +1 -0
  58. package/dist/analyzer/types.js +8 -0
  59. package/dist/analyzer/types.js.map +1 -1
  60. package/dist/backgroundAnalysis.d.ts +1 -2
  61. package/dist/backgroundAnalysis.js +2 -2
  62. package/dist/backgroundAnalysis.js.map +1 -1
  63. package/dist/backgroundAnalysisBase.d.ts +1 -2
  64. package/dist/backgroundAnalysisBase.js +4 -4
  65. package/dist/backgroundAnalysisBase.js.map +1 -1
  66. package/dist/backgroundThreadBase.d.ts +1 -1
  67. package/dist/backgroundThreadBase.js +1 -0
  68. package/dist/backgroundThreadBase.js.map +1 -1
  69. package/dist/common/commandLineOptions.d.ts +1 -0
  70. package/dist/common/commandLineOptions.js.map +1 -1
  71. package/dist/common/configOptions.d.ts +4 -1
  72. package/dist/common/configOptions.js +18 -5
  73. package/dist/common/configOptions.js.map +1 -1
  74. package/dist/common/console.d.ts +3 -0
  75. package/dist/common/console.js +8 -1
  76. package/dist/common/console.js.map +1 -1
  77. package/dist/common/extensibility.d.ts +10 -1
  78. package/dist/common/extensibility.js.map +1 -1
  79. package/dist/common/fileSystem.d.ts +3 -0
  80. package/dist/common/fileSystem.js +8 -1
  81. package/dist/common/fileSystem.js.map +1 -1
  82. package/dist/common/pathUtils.d.ts +2 -15
  83. package/dist/common/pathUtils.js +9 -84
  84. package/dist/common/pathUtils.js.map +1 -1
  85. package/dist/common/realFileSystem.js +22 -13
  86. package/dist/common/realFileSystem.js.map +1 -1
  87. package/dist/common/serviceProvider.d.ts +1 -4
  88. package/dist/common/serviceProvider.js +4 -4
  89. package/dist/common/serviceProvider.js.map +1 -1
  90. package/dist/common/serviceProviderExtensions.d.ts +10 -4
  91. package/dist/common/serviceProviderExtensions.js +43 -1
  92. package/dist/common/serviceProviderExtensions.js.map +1 -1
  93. package/dist/languageServerBase.d.ts +9 -9
  94. package/dist/languageServerBase.js +5 -4
  95. package/dist/languageServerBase.js.map +1 -1
  96. package/dist/languageService/analyzerServiceExecutor.js +3 -2
  97. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  98. package/dist/languageService/completionProvider.d.ts +7 -5
  99. package/dist/languageService/completionProvider.js +190 -176
  100. package/dist/languageService/completionProvider.js.map +1 -1
  101. package/dist/languageService/completionProviderUtils.d.ts +1 -1
  102. package/dist/languageService/completionProviderUtils.js +1 -1
  103. package/dist/languageService/completionProviderUtils.js.map +1 -1
  104. package/dist/localization/localize.d.ts +14 -0
  105. package/dist/localization/localize.js +8 -0
  106. package/dist/localization/localize.js.map +1 -1
  107. package/dist/localization/package.nls.cs.json +26 -17
  108. package/dist/localization/package.nls.de.json +26 -17
  109. package/dist/localization/package.nls.en-us.json +9 -2
  110. package/dist/localization/package.nls.es.json +26 -17
  111. package/dist/localization/package.nls.fr.json +26 -17
  112. package/dist/localization/package.nls.it.json +26 -17
  113. package/dist/localization/package.nls.ja.json +26 -17
  114. package/dist/localization/package.nls.ko.json +26 -17
  115. package/dist/localization/package.nls.pl.json +26 -17
  116. package/dist/localization/package.nls.pt-br.json +26 -17
  117. package/dist/localization/package.nls.qps-ploc.json +14 -5
  118. package/dist/localization/package.nls.ru.json +26 -17
  119. package/dist/localization/package.nls.tr.json +26 -17
  120. package/dist/localization/package.nls.zh-cn.json +26 -17
  121. package/dist/localization/package.nls.zh-tw.json +26 -17
  122. package/dist/pyright.js +6 -4
  123. package/dist/pyright.js.map +1 -1
  124. package/dist/server.d.ts +2 -2
  125. package/dist/server.js +8 -10
  126. package/dist/server.js.map +1 -1
  127. package/dist/tests/chainedSourceFiles.test.js +4 -1
  128. package/dist/tests/chainedSourceFiles.test.js.map +1 -1
  129. package/dist/tests/checker.test.js +11 -11
  130. package/dist/tests/checker.test.js.map +1 -1
  131. package/dist/tests/completions.test.js +57 -0
  132. package/dist/tests/completions.test.js.map +1 -1
  133. package/dist/tests/config.test.js +28 -22
  134. package/dist/tests/config.test.js.map +1 -1
  135. package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +5 -5
  136. package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -1
  137. package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +11 -9
  138. package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
  139. package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +14 -14
  140. package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
  141. package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +12 -12
  142. package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -1
  143. package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +9 -9
  144. package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
  145. package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +3 -3
  146. package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -1
  147. package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +3 -3
  148. package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
  149. package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +4 -4
  150. package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
  151. package/dist/tests/fourslash/fourslash.d.ts +1 -0
  152. package/dist/tests/fourslash/missingModuleSource.fourslash.js +4 -1
  153. package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
  154. package/dist/tests/harness/fourslash/testLanguageService.js +4 -1
  155. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  156. package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
  157. package/dist/tests/harness/fourslash/testState.Consts.js +2 -0
  158. package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
  159. package/dist/tests/harness/fourslash/testState.d.ts +2 -0
  160. package/dist/tests/harness/fourslash/testState.js +9 -2
  161. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  162. package/dist/tests/harness/vfs/filesystem.js +10 -6
  163. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  164. package/dist/tests/importResolver.test.js +14 -9
  165. package/dist/tests/importResolver.test.js.map +1 -1
  166. package/dist/tests/localizer.test.js +1 -1
  167. package/dist/tests/localizer.test.js.map +1 -1
  168. package/dist/tests/pathUtils.test.js +13 -21
  169. package/dist/tests/pathUtils.test.js.map +1 -1
  170. package/dist/tests/service.test.js +55 -0
  171. package/dist/tests/service.test.js.map +1 -1
  172. package/dist/tests/sourceFile.test.js +4 -2
  173. package/dist/tests/sourceFile.test.js.map +1 -1
  174. package/dist/tests/testState.test.js +1 -1
  175. package/dist/tests/testState.test.js.map +1 -1
  176. package/dist/tests/testUtils.js +3 -5
  177. package/dist/tests/testUtils.js.map +1 -1
  178. package/dist/tests/typeEvaluator1.test.js +2 -2
  179. package/dist/tests/typeEvaluator2.test.js +5 -1
  180. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  181. package/dist/tests/typeEvaluator3.test.js +8 -4
  182. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  183. package/dist/tests/typeEvaluator4.test.js +4 -0
  184. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  185. package/dist/tests/typeEvaluator5.test.js +1 -1
  186. package/dist/tests/workspaceEditUtils.test.js +24 -20
  187. package/dist/tests/workspaceEditUtils.test.js.map +1 -1
  188. package/dist/workspaceFactory.d.ts +1 -0
  189. package/dist/workspaceFactory.js +7 -4
  190. package/dist/workspaceFactory.js.map +1 -1
  191. package/package.json +1 -1
@@ -728,7 +728,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
728
728
  const isEmptyVariadic = (0, types_1.isClassInstance)(typeResult.type) &&
729
729
  types_1.ClassType.isTupleClass(typeResult.type) &&
730
730
  ((_a = typeResult.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 0;
731
- if (!isEmptyVariadic) {
731
+ const isEllipsis = (0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis');
732
+ if (!isEmptyVariadic && !isEllipsis) {
732
733
  addExpectedClassDiagnostic(typeResult.type, node);
733
734
  typeResult.type = types_1.UnknownType.create();
734
735
  typeResult.typeErrors = true;
@@ -886,13 +887,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
886
887
  function getTypeOfString(node) {
887
888
  const isBytes = (node.token.flags & 32 /* Bytes */) !== 0;
888
889
  let typeResult;
890
+ let isIncomplete = false;
889
891
  // Don't create a literal type if it's an f-string.
890
892
  if (node.nodeType === 27 /* FormatString */) {
891
893
  let isLiteralString = true;
892
894
  // If all of the format expressions are of type LiteralString, then
893
895
  // the resulting formatted string is also LiteralString.
894
896
  node.fieldExpressions.forEach((expr) => {
895
- const exprType = getTypeOfExpression(expr).type;
897
+ const exprTypeResult = getTypeOfExpression(expr);
898
+ const exprType = exprTypeResult.type;
899
+ if (exprTypeResult.isIncomplete) {
900
+ isIncomplete = true;
901
+ }
896
902
  (0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
897
903
  if (!(0, types_1.isClassInstance)(exprSubtype)) {
898
904
  isLiteralString = false;
@@ -910,18 +916,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
910
916
  if (!isBytes && isLiteralString) {
911
917
  const literalStringType = getTypingType(node, 'LiteralString');
912
918
  if (literalStringType && (0, types_1.isInstantiableClass)(literalStringType)) {
913
- typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType) };
919
+ typeResult = { type: types_1.ClassType.cloneAsInstance(literalStringType), isIncomplete };
914
920
  }
915
921
  }
916
922
  if (!typeResult) {
917
923
  typeResult = {
918
924
  type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
925
+ isIncomplete,
919
926
  };
920
927
  }
921
928
  }
922
929
  else {
923
930
  typeResult = {
924
931
  type: cloneBuiltinObjectWithLiteral(node, isBytes ? 'bytes' : 'str', node.value),
932
+ isIncomplete,
925
933
  };
926
934
  }
927
935
  return typeResult;
@@ -1236,8 +1244,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1236
1244
  // to handle the case where we're fetching the object member from a
1237
1245
  // metaclass but binding to the class.
1238
1246
  function getTypeOfObjectMember(errorNode, objectType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
1239
- const memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstantiable(objectType),
1240
- /* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 8 /* DisallowClassVarWrites */, bindToType);
1247
+ let memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstantiable(objectType),
1248
+ /* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 16 /* DisallowClassVarWrites */, bindToType);
1249
+ if (!memberInfo) {
1250
+ const metaclass = objectType.details.effectiveMetaclass;
1251
+ if (metaclass &&
1252
+ (0, types_1.isInstantiableClass)(metaclass) &&
1253
+ !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1254
+ !types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
1255
+ memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1256
+ /* isAccessedThroughObject */ false, memberName, usage,
1257
+ /* diag */ undefined, memberAccessFlags | 2 /* AccessInstanceMembersOnly */, types_1.ClassType.cloneAsInstantiable(objectType));
1258
+ }
1259
+ }
1241
1260
  if (memberInfo) {
1242
1261
  return {
1243
1262
  type: memberInfo.type,
@@ -1254,7 +1273,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1254
1273
  let memberInfo;
1255
1274
  const classDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1256
1275
  const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1257
- let considerMetaclassOnly = (memberAccessFlags & 32 /* ConsiderMetaclassOnly */) !== 0;
1276
+ let considerMetaclassOnly = (memberAccessFlags & 64 /* ConsiderMetaclassOnly */) !== 0;
1258
1277
  if (types_1.ClassType.isPartiallyEvaluated(classType)) {
1259
1278
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
1260
1279
  return { type: types_1.UnknownType.create() };
@@ -1482,7 +1501,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1482
1501
  const classTypeInfo = getTypeOfClass(enclosingClass);
1483
1502
  if (classTypeInfo) {
1484
1503
  const classMemberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, expression.value, 8 /* SkipInstanceVariables */ |
1485
- 16 /* DeclaredTypesOnly */);
1504
+ 32 /* DeclaredTypesOnly */);
1486
1505
  if (classMemberInfo) {
1487
1506
  symbol = classMemberInfo.symbol;
1488
1507
  }
@@ -1499,7 +1518,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1499
1518
  const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
1500
1519
  let classMemberInfo;
1501
1520
  if ((0, types_1.isClassInstance)(baseType)) {
1502
- classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 16 /* DeclaredTypesOnly */);
1521
+ classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 32 /* DeclaredTypesOnly */);
1503
1522
  classOrObjectBase = baseType;
1504
1523
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1505
1524
  // If this is an instance member (e.g. a dataclass field), don't
@@ -1510,7 +1529,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1510
1529
  useDescriptorSetterType = true;
1511
1530
  }
1512
1531
  else if ((0, types_1.isInstantiableClass)(baseType)) {
1513
- classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ | 16 /* DeclaredTypesOnly */);
1532
+ classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ | 32 /* DeclaredTypesOnly */);
1514
1533
  classOrObjectBase = baseType;
1515
1534
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1516
1535
  }
@@ -2205,7 +2224,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2205
2224
  }
2206
2225
  }
2207
2226
  // Look up the member info again, now that we've potentially updated it.
2208
- memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 16 /* DeclaredTypesOnly */);
2227
+ memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 32 /* DeclaredTypesOnly */);
2209
2228
  if (!memberInfo && srcExprNode && !isTypeIncomplete) {
2210
2229
  reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, srcType, node,
2211
2230
  /* ignoreEmptyContainers */ true);
@@ -2344,8 +2363,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2344
2363
  // If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
2345
2364
  // *tuple[*Ts].
2346
2365
  if ((0, types_1.isVariadicTypeVar)(subtype)) {
2366
+ // If it's in a union, convert to type or object.
2347
2367
  if (subtype.isVariadicInUnion) {
2348
- return subtype;
2368
+ if (types_1.TypeBase.isInstantiable(subtype)) {
2369
+ if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
2370
+ return typeClassType;
2371
+ }
2372
+ }
2373
+ else if (objectType) {
2374
+ return objectType;
2375
+ }
2376
+ return types_1.AnyType.create();
2349
2377
  }
2350
2378
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
2351
2379
  return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
@@ -3223,9 +3251,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3223
3251
  nestedClassCount++;
3224
3252
  }
3225
3253
  else if (curNode.nodeType === 28 /* Function */) {
3226
- const functionTypeInfo = getTypeOfFunction(curNode);
3227
- if (functionTypeInfo) {
3228
- const functionDetails = functionTypeInfo.functionType.details;
3254
+ const functionType = getTypeOfFunctionPredecorated(curNode);
3255
+ if (functionType) {
3256
+ const functionDetails = functionType.details;
3229
3257
  typeParametersForScope = functionDetails.typeParameters;
3230
3258
  // Was this type parameter "rescoped" to a callable found within the
3231
3259
  // return type annotation? If so, it is not available for use within
@@ -3689,20 +3717,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3689
3717
  if (flags & 1 /* AccessClassMembersOnly */) {
3690
3718
  classLookupFlags |= 8 /* SkipInstanceVariables */;
3691
3719
  }
3692
- if (flags & 2 /* SkipBaseClasses */) {
3720
+ if (flags & 2 /* AccessInstanceMembersOnly */) {
3721
+ classLookupFlags |= 16 /* SkipClassVariables */;
3722
+ }
3723
+ if (flags & 4 /* SkipBaseClasses */) {
3693
3724
  classLookupFlags |= 2 /* SkipBaseClasses */;
3694
3725
  }
3695
- if (flags & 4 /* SkipObjectBaseClass */) {
3726
+ if (flags & 8 /* SkipObjectBaseClass */) {
3696
3727
  classLookupFlags |= 4 /* SkipObjectBaseClass */;
3697
3728
  }
3698
- if (flags & 256 /* SkipTypeBaseClass */) {
3699
- classLookupFlags |= 32 /* SkipTypeBaseClass */;
3729
+ if (flags & 512 /* SkipTypeBaseClass */) {
3730
+ classLookupFlags |= 64 /* SkipTypeBaseClass */;
3700
3731
  }
3701
- if (flags & 128 /* SkipOriginalClass */) {
3732
+ if (flags & 256 /* SkipOriginalClass */) {
3702
3733
  classLookupFlags |= 1 /* SkipOriginalClass */;
3703
3734
  }
3704
3735
  // Always look for a member with a declared type first.
3705
- let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags | 16 /* DeclaredTypesOnly */);
3736
+ let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags | 32 /* DeclaredTypesOnly */);
3706
3737
  // If we couldn't find a symbol with a declared type, use
3707
3738
  // a symbol with an inferred type.
3708
3739
  if (!memberInfo) {
@@ -3739,7 +3770,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3739
3770
  if (typeResult) {
3740
3771
  if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
3741
3772
  type = typeResult.type;
3742
- flags &= 8 /* DisallowClassVarWrites */;
3773
+ flags &= 16 /* DisallowClassVarWrites */;
3743
3774
  }
3744
3775
  }
3745
3776
  }
@@ -3841,7 +3872,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3841
3872
  // No attribute of that name was found. If this is a member access
3842
3873
  // through an object, see if there's an attribute access override
3843
3874
  // method ("__getattr__", etc.).
3844
- if ((flags & (1 /* AccessClassMembersOnly */ | 64 /* SkipAttributeAccessOverride */)) ===
3875
+ if ((flags & (1 /* AccessClassMembersOnly */ | 128 /* SkipAttributeAccessOverride */)) ===
3845
3876
  0) {
3846
3877
  const generalAttrType = applyAttributeAccessOverride(classType, errorNode, usage, memberName);
3847
3878
  if (generalAttrType) {
@@ -3862,7 +3893,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3862
3893
  // if they apply. Also binds methods to the class/object through which it
3863
3894
  // is accessed.
3864
3895
  function applyDescriptorAccessMethod(type, memberInfo, baseTypeClass, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag) {
3865
- const treatConstructorAsClassMember = (flags & 16 /* TreatConstructorAsClassMethod */) !== 0;
3896
+ const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
3866
3897
  let isTypeValid = true;
3867
3898
  let isAsymmetricAccessor = false;
3868
3899
  type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
@@ -4104,7 +4135,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4104
4135
  }
4105
4136
  if (usage.method === 'set') {
4106
4137
  if (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.symbol.isClassVar()) {
4107
- if (flags & 8 /* DisallowClassVarWrites */) {
4138
+ if (flags & 16 /* DisallowClassVarWrites */) {
4108
4139
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberSetClassVar().format({ name: memberName }));
4109
4140
  isTypeValid = false;
4110
4141
  return undefined;
@@ -4241,7 +4272,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4241
4272
  // See if the class has a "__getattribute__" or "__getattr__" method.
4242
4273
  // If so, arbitrary members are supported.
4243
4274
  return (_a = getTypeOfClassMember(errorNode, classType, name, { method: 'get' },
4244
- /* diag */ undefined, 4 /* SkipObjectBaseClass */ | 64 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
4275
+ /* diag */ undefined, 8 /* SkipObjectBaseClass */ | 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
4245
4276
  };
4246
4277
  let accessMemberType;
4247
4278
  if (usage.method === 'get') {
@@ -4656,7 +4687,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4656
4687
  (flags & 128 /* ExpectingInstantiableType */) === 0) {
4657
4688
  const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
4658
4689
  /* usage */ undefined,
4659
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
4690
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */);
4660
4691
  if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
4661
4692
  // If the class doesn't derive from Generic, a type argument should not be allowed.
4662
4693
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsExpectingNone().format({
@@ -4892,10 +4923,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4892
4923
  const itemMethodType = (0, types_1.isClassInstance)(baseType)
4893
4924
  ? (_a = getTypeOfObjectMember(node, baseType, magicMethodName,
4894
4925
  /* usage */ undefined,
4895
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type
4926
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type
4896
4927
  : (_b = getTypeOfClassMember(node, baseType, magicMethodName,
4897
4928
  /* usage */ undefined,
4898
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
4929
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
4899
4930
  if (!itemMethodType) {
4900
4931
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
4901
4932
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
@@ -5262,7 +5293,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5262
5293
  matchingSubtype = subtype;
5263
5294
  }
5264
5295
  }
5265
- });
5296
+ },
5297
+ /* sortSubtypes */ true);
5266
5298
  effectiveExpectedType = matchingSubtype;
5267
5299
  }
5268
5300
  let expectedTypeDiagAddendum;
@@ -6099,7 +6131,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6099
6131
  if (!isDiagnosticSuppressedForNode(errorNode)) {
6100
6132
  const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
6101
6133
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
6102
- const argTypes = argList.map((t) => printType(getTypeOfArgument(t).type));
6134
+ const argTypes = argList.map((t) => {
6135
+ const typeString = printType(getTypeOfArgument(t).type);
6136
+ if (t.argumentCategory === 1 /* UnpackedList */) {
6137
+ return `*${typeString}`;
6138
+ }
6139
+ if (t.argumentCategory === 2 /* UnpackedDictionary */) {
6140
+ return `**${typeString}`;
6141
+ }
6142
+ return typeString;
6143
+ });
6103
6144
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
6104
6145
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }) + diagAddendum.getString(), errorNode);
6105
6146
  }
@@ -6603,7 +6644,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6603
6644
  var _a, _b;
6604
6645
  const memberType = (_a = getTypeOfObjectMember(errorNode, expandedCallType, '__call__',
6605
6646
  /* usage */ undefined,
6606
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
6647
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
6607
6648
  if (!memberType) {
6608
6649
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
6609
6650
  type: printType(expandedCallType),
@@ -7556,7 +7597,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7556
7597
  return subtype;
7557
7598
  }
7558
7599
  return undefined;
7559
- });
7600
+ },
7601
+ /* sortSubtypes */ true);
7560
7602
  if ((0, types_1.isClassInstance)(filteredType)) {
7561
7603
  effectiveExpectedType = filteredType;
7562
7604
  }
@@ -8242,15 +8284,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8242
8284
  }
8243
8285
  const condition = argType.condition;
8244
8286
  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 };
8287
+ if ((0, types_1.isParamSpec)(argParam.paramType)) {
8288
+ // Handle the case where we're assigning a *args or **kwargs argument
8289
+ // to a *P.args or **P.kwargs parameter.
8290
+ if (argParam.paramType.paramSpecAccess !== undefined) {
8291
+ return { isCompatible, argType, isTypeIncomplete, condition };
8292
+ }
8293
+ // Handle the case where we're assigning a *P.args or **P.kwargs argument
8294
+ // to a *P.args or **P.kwargs parameter.
8295
+ if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess !== undefined) {
8296
+ return { isCompatible, argType, isTypeIncomplete, condition };
8297
+ }
8254
8298
  }
8255
8299
  // If we are asked to skip overload arguments, determine whether the argument
8256
8300
  // is an explicit overload type, an overloaded class constructor, or a
@@ -8667,6 +8711,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8667
8711
  functionType.details.paramSpec = typeResult.type;
8668
8712
  return functionType;
8669
8713
  }
8714
+ if ((0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis')) {
8715
+ types_1.FunctionType.addDefaultParameters(functionType);
8716
+ return functionType;
8717
+ }
8670
8718
  }
8671
8719
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
8672
8720
  return undefined;
@@ -8924,12 +8972,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8924
8972
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
8925
8973
  magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, magicMethodName,
8926
8974
  /* usage */ undefined,
8927
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
8975
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
8928
8976
  }
8929
8977
  else if ((0, types_1.isInstantiableClass)(concreteSubtype)) {
8930
8978
  magicMethodType = (_b = getTypeOfClassMember(errorNode, concreteSubtype, magicMethodName,
8931
8979
  /* usage */ undefined,
8932
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
8980
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
8933
8981
  }
8934
8982
  if (magicMethodType) {
8935
8983
  const functionArgs = args.map((arg) => {
@@ -9018,7 +9066,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9018
9066
  matchingSubtypeResult = subtypeResult;
9019
9067
  }
9020
9068
  }
9021
- });
9069
+ },
9070
+ /* sortSubtypes */ true);
9022
9071
  effectiveExpectedType = matchingSubtype;
9023
9072
  }
9024
9073
  let expectedTypeDiagAddendum = undefined;
@@ -9335,7 +9384,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9335
9384
  matchingSubtypeResult = subtypeResult;
9336
9385
  }
9337
9386
  }
9338
- });
9387
+ },
9388
+ /* sortSubtypes */ true);
9339
9389
  effectiveExpectedType = matchingSubtype;
9340
9390
  }
9341
9391
  let expectedTypeDiagAddendum;
@@ -10141,7 +10191,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10141
10191
  }
10142
10192
  }
10143
10193
  if (!type) {
10144
- const exprType = getTypeOfExpression(itemExpr);
10194
+ const exprType = getTypeOfExpression(itemExpr, flags & 4 /* AllowForwardReferences */);
10145
10195
  // Is this an enum type?
10146
10196
  if ((0, types_1.isClassInstance)(exprType.type) &&
10147
10197
  types_1.ClassType.isEnumClass(exprType.type) &&
@@ -11803,8 +11853,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11803
11853
  const initSubclassMethodInfo = getTypeOfClassMemberName(errorNode, classType,
11804
11854
  /* isAccessedThroughObject */ false, '__init_subclass__', { method: 'get' },
11805
11855
  /* diag */ undefined, 1 /* AccessClassMembersOnly */ |
11806
- 4 /* SkipObjectBaseClass */ |
11807
- 128 /* SkipOriginalClass */, classType);
11856
+ 8 /* SkipObjectBaseClass */ |
11857
+ 256 /* SkipOriginalClass */, classType);
11808
11858
  if (initSubclassMethodInfo) {
11809
11859
  const initSubclassMethodType = initSubclassMethodInfo.type;
11810
11860
  if (initSubclassMethodType) {
@@ -11815,7 +11865,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11815
11865
  }
11816
11866
  else if (classType.details.effectiveMetaclass && (0, types_1.isClass)(classType.details.effectiveMetaclass)) {
11817
11867
  // See if the metaclass has a `__new__` method that accepts keyword parameters.
11818
- const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 32 /* SkipTypeBaseClass */);
11868
+ const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 64 /* SkipTypeBaseClass */);
11819
11869
  if (newMethodMember) {
11820
11870
  const newMethodType = getTypeOfMember(newMethodMember);
11821
11871
  if ((0, types_1.isFunction)(newMethodType)) {
@@ -11878,20 +11928,72 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11878
11928
  });
11879
11929
  }
11880
11930
  function getTypeOfFunction(node) {
11881
- var _a, _b;
11882
- const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11883
- // Is this type already cached?
11884
- const cachedFunctionType = readTypeCache(node.name, 0 /* None */);
11885
- if (cachedFunctionType) {
11886
- if (!(0, types_1.isFunction)(cachedFunctionType)) {
11931
+ // Is this predecorated function type cached?
11932
+ let functionType = readTypeCache(node.name, 0 /* None */);
11933
+ if (functionType) {
11934
+ if (!(0, types_1.isFunction)(functionType)) {
11887
11935
  // This can happen in certain rare circumstances where the
11888
11936
  // function declaration falls within an unreachable code block.
11889
11937
  return undefined;
11890
11938
  }
11891
- return {
11892
- functionType: cachedFunctionType,
11893
- decoratedType: readTypeCache(node, 0 /* None */) || types_1.UnknownType.create(),
11894
- };
11939
+ }
11940
+ else {
11941
+ functionType = getTypeOfFunctionPredecorated(node);
11942
+ }
11943
+ // Is the decorated function type cached?
11944
+ let decoratedType = readTypeCache(node, 0 /* None */);
11945
+ if (decoratedType) {
11946
+ return { functionType, decoratedType };
11947
+ }
11948
+ // Populate the cache with a temporary value to handle recursion.
11949
+ writeTypeCache(node, { type: functionType }, /* flags */ undefined);
11950
+ // If it's an async function, wrap the return type in an Awaitable or Generator.
11951
+ // Set the "partially evaluated" flag around this logic to detect recursion.
11952
+ functionType.details.flags |= 131072 /* PartiallyEvaluated */;
11953
+ const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
11954
+ functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
11955
+ // Apply all of the decorators in reverse order.
11956
+ decoratedType = preDecoratedType;
11957
+ let foundUnknown = false;
11958
+ for (let i = node.decorators.length - 1; i >= 0; i--) {
11959
+ const decorator = node.decorators[i];
11960
+ const newDecoratedType = (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
11961
+ const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
11962
+ if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
11963
+ // Report this error only on the first unknown type.
11964
+ if (!foundUnknown) {
11965
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11966
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
11967
+ foundUnknown = true;
11968
+ }
11969
+ }
11970
+ else {
11971
+ // Apply the decorator only if the type is known.
11972
+ decoratedType = newDecoratedType;
11973
+ }
11974
+ }
11975
+ // See if there are any overloads provided by previous function declarations.
11976
+ if ((0, types_1.isFunction)(decoratedType)) {
11977
+ if (types_1.FunctionType.isOverloaded(decoratedType)) {
11978
+ // Mark all the parameters as accessed.
11979
+ node.parameters.forEach((param) => {
11980
+ markParamAccessed(param);
11981
+ });
11982
+ }
11983
+ decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
11984
+ }
11985
+ writeTypeCache(node, { type: decoratedType }, 0 /* None */);
11986
+ return { functionType, decoratedType };
11987
+ }
11988
+ // Evaluates the type of a "def" statement without applying an async
11989
+ // modifier or any decorators.
11990
+ function getTypeOfFunctionPredecorated(node) {
11991
+ var _a, _b, _c;
11992
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11993
+ // Is this type already cached?
11994
+ const cachedFunctionType = readTypeCache(node.name, 0 /* None */);
11995
+ if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
11996
+ return cachedFunctionType;
11895
11997
  }
11896
11998
  let functionDecl;
11897
11999
  const decl = AnalyzerNodeInfo.getDeclaration(node);
@@ -11903,11 +12005,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11903
12005
  const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
11904
12006
  let containingClassType;
11905
12007
  if (containingClassNode) {
11906
- const classInfo = getTypeOfClass(containingClassNode);
11907
- if (!classInfo) {
11908
- return undefined;
11909
- }
11910
- containingClassType = classInfo.classType;
12008
+ containingClassType = (_a = getTypeOfClass(containingClassNode)) === null || _a === void 0 ? void 0 : _a.classType;
11911
12009
  }
11912
12010
  let functionFlags = (0, decorators_1.getFunctionFlagsFromDecorators)(evaluatorInterface, node, !!containingClassNode);
11913
12011
  if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
@@ -11936,14 +12034,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11936
12034
  functionType.details.builtInName = node.name.value;
11937
12035
  }
11938
12036
  functionType.details.declaration = functionDecl;
11939
- // Allow recursion by registering the partially-constructed
11940
- // function type.
12037
+ // Allow recursion by caching and registering the partially-constructed function type.
11941
12038
  const scope = ScopeUtils.getScopeForNode(node);
11942
12039
  const functionSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(node.name.value);
11943
12040
  if (functionDecl && functionSymbol) {
11944
12041
  setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
11945
12042
  }
11946
- writeTypeCache(node, { type: functionType }, /* flags */ undefined);
11947
12043
  writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
11948
12044
  // Is this an "__init__" method within a pseudo-generic class? If so,
11949
12045
  // we'll add generic types to the constructor's parameters.
@@ -11983,14 +12079,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11983
12079
  else {
11984
12080
  functionType.details.typeParameters = typeParametersSeen;
11985
12081
  }
11986
- const markParamAccessed = (param) => {
11987
- if (param.name) {
11988
- const symbolWithScope = lookUpSymbolRecursive(param.name, param.name.value, /* honorCodeFlow */ false);
11989
- if (symbolWithScope) {
11990
- setSymbolAccessed(fileInfo, symbolWithScope.symbol, param.name);
11991
- }
11992
- }
11993
- };
11994
12082
  let paramsArePositionOnly = true;
11995
12083
  const isFirstParamClsOrSelf = containingClassType &&
11996
12084
  (types_1.FunctionType.isClassMethod(functionType) ||
@@ -12172,7 +12260,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12172
12260
  // If there was a defined return type, analyze that first so when we
12173
12261
  // walk the contents of the function, return statements can be
12174
12262
  // validated against this type.
12175
- const returnTypeAnnotationNode = (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : (_b = node.functionAnnotationComment) === null || _b === void 0 ? void 0 : _b.returnTypeAnnotation;
12263
+ const returnTypeAnnotationNode = (_b = node.returnTypeAnnotation) !== null && _b !== void 0 ? _b : (_c = node.functionAnnotationComment) === null || _c === void 0 ? void 0 : _c.returnTypeAnnotation;
12176
12264
  if (returnTypeAnnotationNode) {
12177
12265
  // Temporarily set the return type to unknown in case of recursion.
12178
12266
  functionType.details.declaredReturnType = types_1.UnknownType.create();
@@ -12225,43 +12313,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12225
12313
  }
12226
12314
  validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index));
12227
12315
  });
12228
- // If it's an async function, wrap the return type in an Awaitable or Generator.
12229
- const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
12230
12316
  // Clear the "partially evaluated" flag to indicate that the functionType
12231
12317
  // is fully evaluated.
12232
12318
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
12233
- // Apply all of the decorators in reverse order.
12234
- let decoratedType = preDecoratedType;
12235
- let foundUnknown = false;
12236
- for (let i = node.decorators.length - 1; i >= 0; i--) {
12237
- const decorator = node.decorators[i];
12238
- const newDecoratedType = (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
12239
- const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
12240
- if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
12241
- // Report this error only on the first unknown type.
12242
- if (!foundUnknown) {
12243
- addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
12244
- foundUnknown = true;
12245
- }
12246
- }
12247
- else {
12248
- // Apply the decorator only if the type is known.
12249
- decoratedType = newDecoratedType;
12250
- }
12251
- }
12252
- // See if there are any overloads provided by previous function declarations.
12253
- if ((0, types_1.isFunction)(decoratedType)) {
12254
- if (types_1.FunctionType.isOverloaded(decoratedType)) {
12255
- // Mark all the parameters as accessed.
12256
- node.parameters.forEach((param) => {
12257
- markParamAccessed(param);
12258
- });
12319
+ writeTypeCache(node.name, { type: functionType }, 0 /* None */);
12320
+ return functionType;
12321
+ }
12322
+ function markParamAccessed(param) {
12323
+ if (param.name) {
12324
+ const symbolWithScope = lookUpSymbolRecursive(param.name, param.name.value, /* honorCodeFlow */ false);
12325
+ if (symbolWithScope) {
12326
+ setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(param), symbolWithScope.symbol, param.name);
12259
12327
  }
12260
- decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
12261
12328
  }
12262
- writeTypeCache(node.name, { type: functionType }, 0 /* None */);
12263
- writeTypeCache(node, { type: decoratedType }, 0 /* None */);
12264
- return { functionType, decoratedType };
12265
12329
  }
12266
12330
  // If the declared return type of a function contains type variables that
12267
12331
  // are found nowhere else in the signature and are contained within a
@@ -12852,6 +12916,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12852
12916
  setSymbolAccessed(fileInfo, symbolInScope.symbol, node);
12853
12917
  }
12854
12918
  }
12919
+ // If this is an import into a class scope, mark the symbol as accessed.
12920
+ const classNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
12921
+ if (classNode) {
12922
+ const symbolInScope = lookUpSymbolRecursive(node, aliasNode.value, /* honorCodeFlow */ true);
12923
+ if (symbolInScope) {
12924
+ setSymbolAccessed(fileInfo, symbolInScope.symbol, node);
12925
+ }
12926
+ }
12855
12927
  let symbolType = getAliasedSymbolTypeForName(node, aliasNode.value);
12856
12928
  if (!symbolType) {
12857
12929
  const parentNode = node.parent;
@@ -14211,7 +14283,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14211
14283
  if ((0, types_1.isInstantiableClass)(subtype)) {
14212
14284
  // Try to find a member that has a declared type. If so, that
14213
14285
  // overrides any inferred types.
14214
- let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 16 /* DeclaredTypesOnly */);
14286
+ let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
14215
14287
  if (!member) {
14216
14288
  member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName);
14217
14289
  }
@@ -14228,7 +14300,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14228
14300
  else if ((0, types_1.isClassInstance)(subtype)) {
14229
14301
  // Try to find a member that has a declared type. If so, that
14230
14302
  // overrides any inferred types.
14231
- let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 16 /* DeclaredTypesOnly */);
14303
+ let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
14232
14304
  if (!member) {
14233
14305
  member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName);
14234
14306
  }
@@ -14294,7 +14366,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14294
14366
  }
14295
14367
  else if ((0, types_1.isInstantiableClass)(baseType)) {
14296
14368
  const initMethodType = (_b = getTypeOfObjectMember(argNode.parent.leftExpression, types_1.ClassType.cloneAsInstance(baseType), '__init__', { method: 'get' },
14297
- /* diag */ undefined, 4 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
14369
+ /* diag */ undefined, 8 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
14298
14370
  if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
14299
14371
  const paramDecl = getDeclarationFromFunctionNamedParameter(initMethodType, paramName);
14300
14372
  if (paramDecl) {
@@ -14844,6 +14916,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14844
14916
  isIncomplete,
14845
14917
  includesVariableDecl: typedDecls.some((decl) => decl.type === 1 /* Variable */),
14846
14918
  includesIllegalTypeAliasDecl: !typedDecls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
14919
+ includesSpeculativeResult: false,
14847
14920
  isRecursiveDefinition: !declaredType,
14848
14921
  };
14849
14922
  return result;
@@ -14862,12 +14935,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14862
14935
  }
14863
14936
  }
14864
14937
  // Infer the type.
14865
- const typesToCombine = [];
14866
14938
  const decls = symbol.getDeclarations();
14867
- let isIncomplete = false;
14868
- let sawPendingEvaluation = false;
14869
- let includesVariableDecl = false;
14870
- let includesSpeculativeResult = false;
14871
14939
  let declIndexToConsider;
14872
14940
  // Limit the number of declarations to explore.
14873
14941
  if (decls.length > maxDeclarationsToUseForInference) {
@@ -14876,6 +14944,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14876
14944
  isIncomplete: false,
14877
14945
  includesVariableDecl: false,
14878
14946
  includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
14947
+ includesSpeculativeResult: false,
14879
14948
  isRecursiveDefinition: false,
14880
14949
  };
14881
14950
  addToEffectiveTypeCache(result);
@@ -14902,22 +14971,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14902
14971
  }
14903
14972
  }
14904
14973
  }
14974
+ // Determine which declarations to use for inference.
14975
+ const declsToConsider = [];
14905
14976
  let sawExplicitTypeAlias = false;
14906
14977
  decls.forEach((decl, index) => {
14907
14978
  var _a, _b, _c;
14908
- let considerDecl = declIndexToConsider === undefined || index === declIndexToConsider;
14979
+ if (declIndexToConsider !== undefined && declIndexToConsider !== index) {
14980
+ return;
14981
+ }
14909
14982
  // If we have already seen an explicit type alias, do not consider
14910
14983
  // additional decls. This can happen if multiple TypeAlias declarations
14911
14984
  // are provided -- normally an error, but it can happen in stdlib stubs
14912
14985
  // if the user sets the pythonPlatform to "All".
14913
14986
  if (sawExplicitTypeAlias) {
14914
- considerDecl = false;
14987
+ return;
14915
14988
  }
14916
14989
  // If the symbol is explicitly marked as a ClassVar, consider only the
14917
14990
  // declarations that assign to it from within the class body, not through
14918
14991
  // a member access expression.
14919
14992
  if (symbol.isClassVar() && decl.type === 1 /* Variable */ && decl.isDefinedByMemberAccess) {
14920
- considerDecl = false;
14993
+ return;
14921
14994
  }
14922
14995
  if (usageNode !== undefined) {
14923
14996
  if (decl.type !== 8 /* Alias */) {
@@ -14926,122 +14999,133 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14926
14999
  const declScope = ParseTreeUtils.getExecutionScopeNode(decl.node);
14927
15000
  if (usageScope === declScope) {
14928
15001
  if (!isFlowPathBetweenNodes(decl.node, usageNode)) {
14929
- considerDecl = false;
15002
+ return;
14930
15003
  }
14931
15004
  }
14932
15005
  }
14933
15006
  }
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)) {
15007
+ const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
15008
+ allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
15009
+ })) !== null && _a !== void 0 ? _a : decl;
15010
+ const isExplicitTypeAlias = isExplicitTypeAliasDeclaration(resolvedDecl);
15011
+ const isTypeAlias = isExplicitTypeAlias || isPossibleTypeAliasOrTypedDict(resolvedDecl);
15012
+ if (isExplicitTypeAlias) {
15013
+ sawExplicitTypeAlias = true;
15014
+ }
15015
+ // If this is a type alias, evaluate it outside of the recursive symbol
15016
+ // resolution check so we can evaluate the full assignment statement.
15017
+ if (isTypeAlias &&
15018
+ resolvedDecl.type === 1 /* Variable */ &&
15019
+ ((_c = (_b = resolvedDecl.inferredTypeSource) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.nodeType) === 3 /* Assignment */) {
15020
+ evaluateTypesForAssignmentStatement(resolvedDecl.inferredTypeSource.parent);
15021
+ }
15022
+ declsToConsider.push(resolvedDecl);
15023
+ });
15024
+ 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;
15025
+ const result = getTypeOfSymbolForDecls(symbol, declsToConsider, evaluationAttempts);
15026
+ // Add the result to the effective type cache if it doesn't include speculative results.
15027
+ if (!result.includesSpeculativeResult) {
15028
+ addToEffectiveTypeCache(result);
15029
+ }
15030
+ return result;
15031
+ function addToEffectiveTypeCache(result) {
15032
+ // Add the entry to the cache so we don't need to compute it next time.
15033
+ if (!cacheEntries) {
15034
+ cacheEntries = new Map();
15035
+ effectiveTypeCache.set(symbol.id, cacheEntries);
15036
+ }
15037
+ cacheEntries.set(effectiveTypeCacheKey, result);
15038
+ }
15039
+ }
15040
+ // Returns the type of a symbol based on a subset of its declarations.
15041
+ function getTypeOfSymbolForDecls(symbol, decls, evaluationAttempts) {
15042
+ const typesToCombine = [];
15043
+ let isIncomplete = false;
15044
+ let sawPendingEvaluation = false;
15045
+ let includesVariableDecl = false;
15046
+ let includesSpeculativeResult = false;
15047
+ decls.forEach((decl) => {
15048
+ if (pushSymbolResolution(symbol, decl)) {
15049
+ try {
15050
+ let type = getInferredTypeOfDeclaration(symbol, decl);
15051
+ if (!popSymbolResolution(symbol)) {
15052
+ isIncomplete = true;
15053
+ }
15054
+ if (type) {
15055
+ if (decl.type === 1 /* Variable */) {
15056
+ // Exempt typing.pyi, which uses variables to define some
15057
+ // special forms like Any.
15058
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(decl.node);
15059
+ if (!fileInfo.isTypingStubFile) {
15060
+ includesVariableDecl = true;
15061
+ }
15062
+ let isConstant = false;
15063
+ if (decl.type === 1 /* Variable */) {
15064
+ if (decl.isConstant || isFinalVariableDeclaration(decl)) {
14975
15065
  isConstant = true;
14976
15066
  }
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
15067
  }
14983
- typesToCombine.push(type);
14984
- if (isSpeculativeModeInUse(decl.node)) {
14985
- includesSpeculativeResult = true;
15068
+ // Treat enum values declared within an enum class as though they are const even
15069
+ // though they may not be named as such.
15070
+ if ((0, types_1.isClassInstance)(type) &&
15071
+ types_1.ClassType.isEnumClass(type) &&
15072
+ (0, enums_1.isDeclInEnumClass)(evaluatorInterface, decl)) {
15073
+ isConstant = true;
15074
+ }
15075
+ // If the symbol is constant, we can retain the literal
15076
+ // value. Otherwise, strip literal values to widen the type.
15077
+ if (types_1.TypeBase.isInstance(type) && !isConstant && !isExplicitTypeAliasDeclaration(decl)) {
15078
+ type = stripLiteralValue(type);
14986
15079
  }
14987
15080
  }
14988
- else {
14989
- isIncomplete = true;
15081
+ typesToCombine.push(type);
15082
+ if (isSpeculativeModeInUse(decl.node)) {
15083
+ includesSpeculativeResult = true;
14990
15084
  }
14991
15085
  }
14992
- catch (e) {
14993
- // Clean up the stack before rethrowing.
14994
- popSymbolResolution(symbol);
14995
- throw e;
15086
+ else {
15087
+ isIncomplete = true;
14996
15088
  }
14997
15089
  }
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
- }
15090
+ catch (e) {
15091
+ // Clean up the stack before rethrowing.
15092
+ popSymbolResolution(symbol);
15093
+ throw e;
15094
+ }
15095
+ }
15096
+ else {
15097
+ if (decl.type === 6 /* Class */) {
15098
+ const classTypeInfo = getTypeOfClass(decl.node);
15099
+ if (classTypeInfo === null || classTypeInfo === void 0 ? void 0 : classTypeInfo.decoratedType) {
15100
+ typesToCombine.push(classTypeInfo.decoratedType);
15004
15101
  }
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
15102
  }
15103
+ isIncomplete = true;
15104
+ // Note that at least one decl could not be evaluated because
15105
+ // it was already in the process of being evaluated.
15106
+ sawPendingEvaluation = true;
15010
15107
  }
15011
15108
  });
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;
15109
+ let type;
15015
15110
  if (typesToCombine.length > 0) {
15016
15111
  // Ignore the pending evaluation flag if we've already attempted the
15017
15112
  // type evaluation many times because this probably means there's a
15018
15113
  // cyclical dependency that cannot be broken.
15019
15114
  isIncomplete = sawPendingEvaluation && evaluationAttempts < maxEffectiveTypeEvaluationAttempts;
15020
- resultType = (0, types_1.combineTypes)(typesToCombine);
15115
+ type = (0, types_1.combineTypes)(typesToCombine);
15021
15116
  }
15022
15117
  else {
15023
- resultType = types_1.UnboundType.create();
15118
+ type = types_1.UnboundType.create();
15024
15119
  }
15025
- const result = {
15026
- type: resultType,
15120
+ return {
15121
+ type,
15027
15122
  isIncomplete,
15028
15123
  includesVariableDecl,
15029
15124
  includesIllegalTypeAliasDecl: !decls.every((decl) => isPossibleTypeAliasDeclaration(decl)),
15125
+ includesSpeculativeResult,
15030
15126
  isRecursiveDefinition: false,
15031
15127
  evaluationAttempts,
15032
15128
  };
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
15129
  }
15046
15130
  // If a declaration has an explicit type (e.g. a variable with an annotation),
15047
15131
  // this function evaluates the type and returns it. If the symbol has no
@@ -15595,72 +15679,65 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15595
15679
  });
15596
15680
  return isAssignable;
15597
15681
  }
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);
15682
+ // Adjusts the source and/or dest type arguments list to attempt to match
15683
+ // the length of the src type arguments list if the dest or source contain
15684
+ // entries with indeterminate length or variadic entries. It returns true
15685
+ // if the source is potentially compatible with the dest type, false otherwise.
15686
+ function adjustSrcTupleTypeArgs(destTypeArgs, srcTypeArgs) {
15687
+ const destUnboundedIndex = destTypeArgs.findIndex((t) => t.isUnbounded || (0, types_1.isVariadicTypeVar)(t.type));
15604
15688
  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.
15689
+ // If the src contains an unbounded type but the dest does not, it's incompatible.
15690
+ if (srcUnboundedIndex >= 0 && destUnboundedIndex < 0) {
15691
+ return false;
15692
+ }
15607
15693
  if (srcUnboundedIndex >= 0) {
15694
+ // The source is unbounded, so expand the unbounded argument to try
15695
+ // to make the source and dest arg counts match.
15608
15696
  const typeToReplicate = srcTypeArgs.length > 0 ? srcTypeArgs[srcUnboundedIndex].type : types_1.AnyType.create();
15609
15697
  while (srcTypeArgs.length < destTypeArgs.length) {
15610
15698
  srcTypeArgs.splice(srcUnboundedIndex, 0, { type: typeToReplicate, isUnbounded: true });
15611
15699
  }
15612
15700
  }
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
- });
15701
+ const srcArgsToCapture = srcTypeArgs.length - destTypeArgs.length + 1;
15702
+ if (destUnboundedIndex >= 0 && srcArgsToCapture >= 0) {
15703
+ // If the dest contains a variadic element, determine which source
15704
+ // args map to this element and package them up into an unpacked tuple.
15705
+ if ((0, types_1.isVariadicTypeVar)(destTypeArgs[destUnboundedIndex].type)) {
15706
+ if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
15707
+ const removedArgs = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture);
15708
+ // Package up the remaining type arguments into a tuple object.
15709
+ const variadicTuple = (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, removedArgs.map((typeArg) => {
15710
+ return { type: typeArg.type, isUnbounded: typeArg.isUnbounded };
15711
+ }),
15712
+ /* isTypeArgumentExplicit */ true,
15713
+ /* isUnpackedTuple */ true));
15642
15714
  srcTypeArgs.splice(destUnboundedIndex, 0, {
15643
- type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
15715
+ type: variadicTuple,
15644
15716
  isUnbounded: false,
15645
15717
  });
15646
15718
  }
15647
15719
  }
15720
+ else {
15721
+ const removedArgTypes = srcTypeArgs.splice(destUnboundedIndex, srcArgsToCapture).map((t) => {
15722
+ if ((0, types_1.isTypeVar)(t.type) && (0, types_1.isUnpackedVariadicTypeVar)(t.type) && !t.type.isVariadicInUnion) {
15723
+ return types_1.TypeVarType.cloneForUnpacked(t.type, /* isInUnion */ true);
15724
+ }
15725
+ return t.type;
15726
+ });
15727
+ srcTypeArgs.splice(destUnboundedIndex, 0, {
15728
+ type: removedArgTypes.length > 0 ? (0, types_1.combineTypes)(removedArgTypes) : types_1.AnyType.create(),
15729
+ isUnbounded: false,
15730
+ });
15731
+ }
15648
15732
  }
15733
+ return destTypeArgs.length === srcTypeArgs.length;
15649
15734
  }
15650
15735
  function assignTupleTypeArguments(destType, srcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount) {
15651
15736
  var _a, _b;
15652
15737
  const destTypeArgs = [...((_a = destType.tupleTypeArguments) !== null && _a !== void 0 ? _a : [])];
15653
15738
  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) {
15739
+ const reverseMapping = (flags & 2 /* ReverseTypeVarMatching */) !== 0;
15740
+ if (adjustSrcTupleTypeArgs(reverseMapping ? srcTypeArgs : destTypeArgs, reverseMapping ? destTypeArgs : srcTypeArgs)) {
15664
15741
  for (let argIndex = 0; argIndex < srcTypeArgs.length; argIndex++) {
15665
15742
  const entryDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
15666
15743
  if (!assignType(destTypeArgs[argIndex].type, srcTypeArgs[argIndex].type, entryDiag === null || entryDiag === void 0 ? void 0 : entryDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
@@ -15674,13 +15751,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15674
15751
  }
15675
15752
  }
15676
15753
  else {
15677
- if (srcUnboundedIndex < 0) {
15754
+ if (srcTypeArgs.find((t) => t.isUnbounded)) {
15755
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleSizeIndeterminate().format({
15756
+ expected: destTypeArgs.length,
15757
+ }));
15758
+ }
15759
+ else {
15678
15760
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.tupleSizeMismatch().format({
15679
15761
  expected: destTypeArgs.length,
15680
15762
  received: srcTypeArgs.length,
15681
15763
  }));
15682
- return false;
15683
15764
  }
15765
+ return false;
15684
15766
  }
15685
15767
  return true;
15686
15768
  }
@@ -15751,7 +15833,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15751
15833
  if (destType.typeArguments) {
15752
15834
  // If the dest type is specialized, make sure the specialized source
15753
15835
  // type arguments are assignable to the dest type arguments.
15754
- return assignTypeArguments(destType, curSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
15836
+ return assignTypeArguments(destType, curSrcType,
15837
+ // Don't emit a diag addendum if we're in an invariant context. It's
15838
+ // sufficient to simply indicate that the types are not the same
15839
+ // in this case. Adding more information is unnecessary and confusing.
15840
+ (flags & 1 /* EnforceInvariance */) === 0 ? diag : undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
15755
15841
  }
15756
15842
  if (destTypeVarContext && curSrcType.typeArguments && !destTypeVarContext.isLocked()) {
15757
15843
  // Populate the typeVar map with type arguments of the source.
@@ -15939,7 +16025,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15939
16025
  if ((0, types_1.isTypeVar)(destType)) {
15940
16026
  if ((0, typeUtils_1.isTypeVarSame)(destType, srcType)) {
15941
16027
  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);
16028
+ // If the dest TypeVar has no current value bound to it, bind itself.
16029
+ if (!destTypeVarContext.getPrimarySignature().getTypeVar(destType)) {
16030
+ return (0, constraintSolver_1.assignTypeToTypeVar)(evaluatorInterface, destType, srcType, diag, destTypeVarContext, flags, recursionCount);
16031
+ }
15943
16032
  }
15944
16033
  return true;
15945
16034
  }
@@ -16040,6 +16129,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16040
16129
  destType.details.parameters.length <= 2) {
16041
16130
  return true;
16042
16131
  }
16132
+ // If the source is an unpacked TypeVarTuple and the dest is a
16133
+ // *tuple[Any, ...], we'll treat it as compatible.
16134
+ if ((0, types_1.isUnpackedVariadicTypeVar)(srcType) &&
16135
+ (0, types_1.isClassInstance)(destType) &&
16136
+ (0, types_1.isUnpackedClass)(destType) &&
16137
+ destType.tupleTypeArguments &&
16138
+ destType.tupleTypeArguments.length === 1 &&
16139
+ destType.tupleTypeArguments[0].isUnbounded &&
16140
+ (0, types_1.isAnyOrUnknown)(destType.tupleTypeArguments[0].type)) {
16141
+ return true;
16142
+ }
16043
16143
  if (!(0, types_1.isUnion)(destType)) {
16044
16144
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
16045
16145
  return false;
@@ -16146,9 +16246,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16146
16246
  }
16147
16247
  if ((0, types_1.isInstantiableClass)(destType)) {
16148
16248
  if ((0, types_1.isInstantiableClass)(expandedSrcType)) {
16149
- // PEP 544 says that if the dest type is a Type[Proto] class,
16249
+ // PEP 544 says that if the dest type is a type[Proto] class,
16150
16250
  // the source must be a "concrete" (non-protocol) class.
16151
- if (types_1.ClassType.isProtocolClass(destType)) {
16251
+ if (types_1.ClassType.isProtocolClass(destType) &&
16252
+ (flags & 4096 /* IgnoreProtocolAssignmentCheck */) === 0) {
16152
16253
  if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
16153
16254
  (0, types_1.isInstantiableClass)(srcType) &&
16154
16255
  !srcType.includeSubclasses) {
@@ -17770,8 +17871,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17770
17871
  if (!targetParamType) {
17771
17872
  targetParamType = overrideParamDetails.params[overrideParamDetails.kwargsIndex].type;
17772
17873
  }
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 */)) {
17874
+ 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
17875
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamKeywordType().format({
17776
17876
  name: (_b = paramInfo.param.name) !== null && _b !== void 0 ? _b : '?',
17777
17877
  baseType: printType(paramInfo.type),
@@ -17829,8 +17929,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17829
17929
  // Now check the return type.
17830
17930
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
17831
17931
  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 */)) {
17932
+ 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
17933
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideReturnType().format({
17835
17934
  baseType: printType(baseReturnType),
17836
17935
  overrideType: printType(overrideReturnType),