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

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 (139) hide show
  1. package/dist/analyzer/binder.d.ts +1 -0
  2. package/dist/analyzer/binder.js +8 -4
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +81 -43
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/constraintSolver.js +6 -0
  7. package/dist/analyzer/constraintSolver.js.map +1 -1
  8. package/dist/analyzer/constructors.js +16 -7
  9. package/dist/analyzer/constructors.js.map +1 -1
  10. package/dist/analyzer/dataClasses.js +1 -1
  11. package/dist/analyzer/dataClasses.js.map +1 -1
  12. package/dist/analyzer/declarationUtils.js +14 -2
  13. package/dist/analyzer/declarationUtils.js.map +1 -1
  14. package/dist/analyzer/decorators.js +25 -3
  15. package/dist/analyzer/decorators.js.map +1 -1
  16. package/dist/analyzer/importResolver.js +4 -7
  17. package/dist/analyzer/importResolver.js.map +1 -1
  18. package/dist/analyzer/namedTuples.js +2 -2
  19. package/dist/analyzer/namedTuples.js.map +1 -1
  20. package/dist/analyzer/parameterUtils.d.ts +2 -0
  21. package/dist/analyzer/parameterUtils.js +53 -1
  22. package/dist/analyzer/parameterUtils.js.map +1 -1
  23. package/dist/analyzer/parentDirectoryCache.js +1 -1
  24. package/dist/analyzer/parentDirectoryCache.js.map +1 -1
  25. package/dist/analyzer/parseTreeUtils.d.ts +1 -0
  26. package/dist/analyzer/parseTreeUtils.js +16 -2
  27. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  28. package/dist/analyzer/patternMatching.js +39 -22
  29. package/dist/analyzer/patternMatching.js.map +1 -1
  30. package/dist/analyzer/program.d.ts +2 -2
  31. package/dist/analyzer/program.js +30 -24
  32. package/dist/analyzer/program.js.map +1 -1
  33. package/dist/analyzer/pythonPathUtils.js +10 -8
  34. package/dist/analyzer/pythonPathUtils.js.map +1 -1
  35. package/dist/analyzer/service.js +14 -12
  36. package/dist/analyzer/service.js.map +1 -1
  37. package/dist/analyzer/typeDocStringUtils.js +1 -1
  38. package/dist/analyzer/typeEvaluator.js +223 -163
  39. package/dist/analyzer/typeEvaluator.js.map +1 -1
  40. package/dist/analyzer/typeEvaluatorTypes.d.ts +12 -10
  41. package/dist/analyzer/typeEvaluatorTypes.js +11 -8
  42. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  43. package/dist/analyzer/typeGuards.d.ts +9 -0
  44. package/dist/analyzer/typeGuards.js +60 -7
  45. package/dist/analyzer/typeGuards.js.map +1 -1
  46. package/dist/analyzer/typePrinter.js +3 -2
  47. package/dist/analyzer/typePrinter.js.map +1 -1
  48. package/dist/analyzer/typeUtils.d.ts +6 -4
  49. package/dist/analyzer/typeUtils.js +98 -58
  50. package/dist/analyzer/typeUtils.js.map +1 -1
  51. package/dist/analyzer/typedDicts.js +5 -5
  52. package/dist/analyzer/typedDicts.js.map +1 -1
  53. package/dist/analyzer/types.d.ts +1 -0
  54. package/dist/analyzer/types.js +11 -0
  55. package/dist/analyzer/types.js.map +1 -1
  56. package/dist/common/configOptions.js +2 -2
  57. package/dist/common/configOptions.js.map +1 -1
  58. package/dist/common/extensibility.d.ts +6 -0
  59. package/dist/common/extensibility.js.map +1 -1
  60. package/dist/common/pathUtils.d.ts +2 -15
  61. package/dist/common/pathUtils.js +9 -84
  62. package/dist/common/pathUtils.js.map +1 -1
  63. package/dist/common/realFileSystem.js +26 -12
  64. package/dist/common/realFileSystem.js.map +1 -1
  65. package/dist/languageServerBase.d.ts +1 -1
  66. package/dist/languageServerBase.js +2 -2
  67. package/dist/languageServerBase.js.map +1 -1
  68. package/dist/languageService/completionProvider.d.ts +3 -2
  69. package/dist/languageService/completionProvider.js +12 -6
  70. package/dist/languageService/completionProvider.js.map +1 -1
  71. package/dist/localization/localize.d.ts +17 -4
  72. package/dist/localization/localize.js +10 -2
  73. package/dist/localization/localize.js.map +1 -1
  74. package/dist/localization/package.nls.cs.json +8 -4
  75. package/dist/localization/package.nls.de.json +8 -4
  76. package/dist/localization/package.nls.en-us.json +12 -5
  77. package/dist/localization/package.nls.es.json +8 -4
  78. package/dist/localization/package.nls.fr.json +8 -4
  79. package/dist/localization/package.nls.it.json +8 -4
  80. package/dist/localization/package.nls.ja.json +8 -4
  81. package/dist/localization/package.nls.ko.json +8 -4
  82. package/dist/localization/package.nls.pl.json +8 -4
  83. package/dist/localization/package.nls.pt-br.json +8 -4
  84. package/dist/localization/package.nls.qps-ploc.json +8 -4
  85. package/dist/localization/package.nls.ru.json +8 -4
  86. package/dist/localization/package.nls.tr.json +8 -4
  87. package/dist/localization/package.nls.zh-cn.json +8 -4
  88. package/dist/localization/package.nls.zh-tw.json +8 -4
  89. package/dist/server.js +2 -1
  90. package/dist/server.js.map +1 -1
  91. package/dist/tests/checker.test.js +2 -2
  92. package/dist/tests/checker.test.js.map +1 -1
  93. package/dist/tests/completions.test.js +27 -0
  94. package/dist/tests/completions.test.js.map +1 -1
  95. package/dist/tests/config.test.js +5 -5
  96. package/dist/tests/config.test.js.map +1 -1
  97. package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js +5 -5
  98. package/dist/tests/fourslash/completions.dictionary.keys.complex.fourslash.js.map +1 -1
  99. package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js +11 -9
  100. package/dist/tests/fourslash/completions.dictionary.keys.expression.fourslash.js.map +1 -1
  101. package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js +14 -14
  102. package/dist/tests/fourslash/completions.dictionary.keys.literalTypes.fourslash.js.map +1 -1
  103. package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js +12 -12
  104. package/dist/tests/fourslash/completions.dictionary.keys.simple.fourslash.js.map +1 -1
  105. package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js +9 -9
  106. package/dist/tests/fourslash/completions.dictionary.keys.stringLiterals.fourslash.js.map +1 -1
  107. package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js +3 -3
  108. package/dist/tests/fourslash/completions.dictionary.keys.symbols.fourslash.js.map +1 -1
  109. package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js +3 -3
  110. package/dist/tests/fourslash/completions.fstring.stringLiteral.fourslash.js.map +1 -1
  111. package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js +4 -4
  112. package/dist/tests/fourslash/completions.indexer.keys.getitem.fourslash.js.map +1 -1
  113. package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js +8 -8
  114. package/dist/tests/fourslash/diagnostics.missingModuleSource.fourslash.js.map +1 -1
  115. package/dist/tests/fourslash/fourslash.d.ts +1 -0
  116. package/dist/tests/fourslash/importnotresolved.fourslash.js +2 -2
  117. package/dist/tests/fourslash/importnotresolved.fourslash.js.map +1 -1
  118. package/dist/tests/fourslash/missingModuleSource.fourslash.js +1 -1
  119. package/dist/tests/fourslash/missingModuleSource.fourslash.js.map +1 -1
  120. package/dist/tests/harness/fourslash/testState.Consts.d.ts +1 -0
  121. package/dist/tests/harness/fourslash/testState.Consts.js +2 -0
  122. package/dist/tests/harness/fourslash/testState.Consts.js.map +1 -1
  123. package/dist/tests/harness/fourslash/testState.js +4 -1
  124. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  125. package/dist/tests/harness/vfs/filesystem.js +10 -6
  126. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  127. package/dist/tests/pathUtils.test.js +13 -21
  128. package/dist/tests/pathUtils.test.js.map +1 -1
  129. package/dist/tests/testState.test.js +1 -1
  130. package/dist/tests/testState.test.js.map +1 -1
  131. package/dist/tests/typeEvaluator2.test.js +1 -1
  132. package/dist/tests/typeEvaluator3.test.js +6 -2
  133. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  134. package/dist/tests/typeEvaluator4.test.js +8 -4
  135. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  136. package/dist/tests/typeEvaluator5.test.js +1 -1
  137. package/dist/workspaceFactory.js +8 -14
  138. package/dist/workspaceFactory.js.map +1 -1
  139. package/package.json +1 -1
@@ -294,8 +294,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
294
294
  }
295
295
  }
296
296
  }
297
- function setTypeForNode(node, type = types_1.UnknownType.create(), flags = 0 /* None */) {
298
- writeTypeCache(node, { type }, flags);
297
+ function setTypeResultForNode(node, typeResult, flags = 0 /* None */) {
298
+ writeTypeCache(node, typeResult, flags);
299
299
  }
300
300
  function setAsymmetricDescriptorAssignment(node) {
301
301
  if (isSpeculativeModeInUse(/* node */ undefined)) {
@@ -399,6 +399,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
399
399
  evaluateTypesForExpressionInContext(node);
400
400
  });
401
401
  }
402
+ function getTypeResultForDecorator(node) {
403
+ return evaluateTypeForSubnode(node, () => {
404
+ evaluateTypesForExpressionInContext(node.expression);
405
+ });
406
+ }
402
407
  // Reads the type of the node from the cache.
403
408
  function getCachedType(node) {
404
409
  return readTypeCache(node, 0 /* None */);
@@ -728,7 +733,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
728
733
  const isEmptyVariadic = (0, types_1.isClassInstance)(typeResult.type) &&
729
734
  types_1.ClassType.isTupleClass(typeResult.type) &&
730
735
  ((_a = typeResult.type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.length) === 0;
731
- if (!isEmptyVariadic) {
736
+ const isEllipsis = (0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis');
737
+ if (!isEmptyVariadic && !isEllipsis) {
732
738
  addExpectedClassDiagnostic(typeResult.type, node);
733
739
  typeResult.type = types_1.UnknownType.create();
734
740
  typeResult.typeErrors = true;
@@ -1243,8 +1249,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1243
1249
  // to handle the case where we're fetching the object member from a
1244
1250
  // metaclass but binding to the class.
1245
1251
  function getTypeOfObjectMember(errorNode, objectType, memberName, usage = { method: 'get' }, diag = undefined, memberAccessFlags = 0 /* None */, bindToType) {
1246
- const memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstantiable(objectType),
1247
- /* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 8 /* DisallowClassVarWrites */, bindToType);
1252
+ let memberInfo = getTypeOfClassMemberName(errorNode, types_1.ClassType.cloneAsInstantiable(objectType),
1253
+ /* isAccessedThroughObject */ true, memberName, usage, diag, memberAccessFlags | 16 /* DisallowClassVarWrites */, bindToType);
1254
+ if (!memberInfo) {
1255
+ const metaclass = objectType.details.effectiveMetaclass;
1256
+ if (metaclass &&
1257
+ (0, types_1.isInstantiableClass)(metaclass) &&
1258
+ !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1259
+ !types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
1260
+ memberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1261
+ /* isAccessedThroughObject */ false, memberName, usage,
1262
+ /* diag */ undefined, memberAccessFlags | 2 /* AccessInstanceMembersOnly */, types_1.ClassType.cloneAsInstantiable(objectType));
1263
+ }
1264
+ }
1248
1265
  if (memberInfo) {
1249
1266
  return {
1250
1267
  type: memberInfo.type,
@@ -1261,7 +1278,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1261
1278
  let memberInfo;
1262
1279
  const classDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1263
1280
  const metaclassDiag = diag ? new diagnostic_1.DiagnosticAddendum() : undefined;
1264
- let considerMetaclassOnly = (memberAccessFlags & 32 /* ConsiderMetaclassOnly */) !== 0;
1281
+ let considerMetaclassOnly = (memberAccessFlags & 64 /* ConsiderMetaclassOnly */) !== 0;
1265
1282
  if (types_1.ClassType.isPartiallyEvaluated(classType)) {
1266
1283
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.classDefinitionCycle().format({ name: classType.details.name }), errorNode);
1267
1284
  return { type: types_1.UnknownType.create() };
@@ -1489,7 +1506,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1489
1506
  const classTypeInfo = getTypeOfClass(enclosingClass);
1490
1507
  if (classTypeInfo) {
1491
1508
  const classMemberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, expression.value, 8 /* SkipInstanceVariables */ |
1492
- 16 /* DeclaredTypesOnly */);
1509
+ 32 /* DeclaredTypesOnly */);
1493
1510
  if (classMemberInfo) {
1494
1511
  symbol = classMemberInfo.symbol;
1495
1512
  }
@@ -1506,7 +1523,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1506
1523
  const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
1507
1524
  let classMemberInfo;
1508
1525
  if ((0, types_1.isClassInstance)(baseType)) {
1509
- classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 16 /* DeclaredTypesOnly */);
1526
+ classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 32 /* DeclaredTypesOnly */);
1510
1527
  classOrObjectBase = baseType;
1511
1528
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1512
1529
  // If this is an instance member (e.g. a dataclass field), don't
@@ -1517,7 +1534,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1517
1534
  useDescriptorSetterType = true;
1518
1535
  }
1519
1536
  else if ((0, types_1.isInstantiableClass)(baseType)) {
1520
- classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ | 16 /* DeclaredTypesOnly */);
1537
+ classMemberInfo = (0, typeUtils_1.lookUpClassMember)(baseType, expression.memberName.value, 8 /* SkipInstanceVariables */ | 32 /* DeclaredTypesOnly */);
1521
1538
  classOrObjectBase = baseType;
1522
1539
  memberAccessClass = classMemberInfo === null || classMemberInfo === void 0 ? void 0 : classMemberInfo.classType;
1523
1540
  }
@@ -2212,7 +2229,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2212
2229
  }
2213
2230
  }
2214
2231
  // Look up the member info again, now that we've potentially updated it.
2215
- memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 16 /* DeclaredTypesOnly */);
2232
+ memberInfo = (0, typeUtils_1.lookUpClassMember)(classTypeInfo.classType, memberName, 32 /* DeclaredTypesOnly */);
2216
2233
  if (!memberInfo && srcExprNode && !isTypeIncomplete) {
2217
2234
  reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownMemberType, diagnosticRules_1.DiagnosticRule.reportUnknownMemberType, node.memberName, srcType, node,
2218
2235
  /* ignoreEmptyContainers */ true);
@@ -2351,8 +2368,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2351
2368
  // If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
2352
2369
  // *tuple[*Ts].
2353
2370
  if ((0, types_1.isVariadicTypeVar)(subtype)) {
2371
+ // If it's in a union, convert to type or object.
2354
2372
  if (subtype.isVariadicInUnion) {
2355
- return subtype;
2373
+ if (types_1.TypeBase.isInstantiable(subtype)) {
2374
+ if (typeClassType && (0, types_1.isInstantiableClass)(typeClassType)) {
2375
+ return typeClassType;
2376
+ }
2377
+ }
2378
+ else if (objectType) {
2379
+ return objectType;
2380
+ }
2381
+ return types_1.AnyType.create();
2356
2382
  }
2357
2383
  if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
2358
2384
  return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
@@ -3230,9 +3256,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3230
3256
  nestedClassCount++;
3231
3257
  }
3232
3258
  else if (curNode.nodeType === 28 /* Function */) {
3233
- const functionTypeInfo = getTypeOfFunction(curNode);
3234
- if (functionTypeInfo) {
3235
- const functionDetails = functionTypeInfo.functionType.details;
3259
+ const functionType = getTypeOfFunctionPredecorated(curNode);
3260
+ if (functionType) {
3261
+ const functionDetails = functionType.details;
3236
3262
  typeParametersForScope = functionDetails.typeParameters;
3237
3263
  // Was this type parameter "rescoped" to a callable found within the
3238
3264
  // return type annotation? If so, it is not available for use within
@@ -3696,20 +3722,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3696
3722
  if (flags & 1 /* AccessClassMembersOnly */) {
3697
3723
  classLookupFlags |= 8 /* SkipInstanceVariables */;
3698
3724
  }
3699
- if (flags & 2 /* SkipBaseClasses */) {
3725
+ if (flags & 2 /* AccessInstanceMembersOnly */) {
3726
+ classLookupFlags |= 16 /* SkipClassVariables */;
3727
+ }
3728
+ if (flags & 4 /* SkipBaseClasses */) {
3700
3729
  classLookupFlags |= 2 /* SkipBaseClasses */;
3701
3730
  }
3702
- if (flags & 4 /* SkipObjectBaseClass */) {
3731
+ if (flags & 8 /* SkipObjectBaseClass */) {
3703
3732
  classLookupFlags |= 4 /* SkipObjectBaseClass */;
3704
3733
  }
3705
- if (flags & 256 /* SkipTypeBaseClass */) {
3706
- classLookupFlags |= 32 /* SkipTypeBaseClass */;
3734
+ if (flags & 512 /* SkipTypeBaseClass */) {
3735
+ classLookupFlags |= 64 /* SkipTypeBaseClass */;
3707
3736
  }
3708
- if (flags & 128 /* SkipOriginalClass */) {
3737
+ if (flags & 256 /* SkipOriginalClass */) {
3709
3738
  classLookupFlags |= 1 /* SkipOriginalClass */;
3710
3739
  }
3711
3740
  // Always look for a member with a declared type first.
3712
- let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags | 16 /* DeclaredTypesOnly */);
3741
+ let memberInfo = (0, typeUtils_1.lookUpClassMember)(classType, memberName, classLookupFlags | 32 /* DeclaredTypesOnly */);
3713
3742
  // If we couldn't find a symbol with a declared type, use
3714
3743
  // a symbol with an inferred type.
3715
3744
  if (!memberInfo) {
@@ -3746,7 +3775,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3746
3775
  if (typeResult) {
3747
3776
  if ((0, typeUtils_1.isDescriptorInstance)(typeResult.type, /* requireSetter */ true)) {
3748
3777
  type = typeResult.type;
3749
- flags &= 8 /* DisallowClassVarWrites */;
3778
+ flags &= 16 /* DisallowClassVarWrites */;
3750
3779
  }
3751
3780
  }
3752
3781
  }
@@ -3848,7 +3877,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3848
3877
  // No attribute of that name was found. If this is a member access
3849
3878
  // through an object, see if there's an attribute access override
3850
3879
  // method ("__getattr__", etc.).
3851
- if ((flags & (1 /* AccessClassMembersOnly */ | 64 /* SkipAttributeAccessOverride */)) ===
3880
+ if ((flags & (1 /* AccessClassMembersOnly */ | 128 /* SkipAttributeAccessOverride */)) ===
3852
3881
  0) {
3853
3882
  const generalAttrType = applyAttributeAccessOverride(classType, errorNode, usage, memberName);
3854
3883
  if (generalAttrType) {
@@ -3869,7 +3898,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3869
3898
  // if they apply. Also binds methods to the class/object through which it
3870
3899
  // is accessed.
3871
3900
  function applyDescriptorAccessMethod(type, memberInfo, baseTypeClass, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag) {
3872
- const treatConstructorAsClassMember = (flags & 16 /* TreatConstructorAsClassMethod */) !== 0;
3901
+ const treatConstructorAsClassMember = (flags & 32 /* TreatConstructorAsClassMethod */) !== 0;
3873
3902
  let isTypeValid = true;
3874
3903
  let isAsymmetricAccessor = false;
3875
3904
  type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
@@ -4111,7 +4140,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4111
4140
  }
4112
4141
  if (usage.method === 'set') {
4113
4142
  if (memberInfo === null || memberInfo === void 0 ? void 0 : memberInfo.symbol.isClassVar()) {
4114
- if (flags & 8 /* DisallowClassVarWrites */) {
4143
+ if (flags & 16 /* DisallowClassVarWrites */) {
4115
4144
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.memberSetClassVar().format({ name: memberName }));
4116
4145
  isTypeValid = false;
4117
4146
  return undefined;
@@ -4248,7 +4277,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4248
4277
  // See if the class has a "__getattribute__" or "__getattr__" method.
4249
4278
  // If so, arbitrary members are supported.
4250
4279
  return (_a = getTypeOfClassMember(errorNode, classType, name, { method: 'get' },
4251
- /* diag */ undefined, 4 /* SkipObjectBaseClass */ | 64 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
4280
+ /* diag */ undefined, 8 /* SkipObjectBaseClass */ | 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type;
4252
4281
  };
4253
4282
  let accessMemberType;
4254
4283
  if (usage.method === 'get') {
@@ -4663,7 +4692,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4663
4692
  (flags & 128 /* ExpectingInstantiableType */) === 0) {
4664
4693
  const itemMethodType = getTypeOfClassMember(node, concreteSubtype, getIndexAccessMagicMethodName(usage),
4665
4694
  /* usage */ undefined,
4666
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */);
4695
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */);
4667
4696
  if ((flags & 256 /* ExpectingTypeAnnotation */) !== 0) {
4668
4697
  // If the class doesn't derive from Generic, a type argument should not be allowed.
4669
4698
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeArgsExpectingNone().format({
@@ -4899,10 +4928,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4899
4928
  const itemMethodType = (0, types_1.isClassInstance)(baseType)
4900
4929
  ? (_a = getTypeOfObjectMember(node, baseType, magicMethodName,
4901
4930
  /* usage */ undefined,
4902
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type
4931
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */)) === null || _a === void 0 ? void 0 : _a.type
4903
4932
  : (_b = getTypeOfClassMember(node, baseType, magicMethodName,
4904
4933
  /* usage */ undefined,
4905
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
4934
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
4906
4935
  if (!itemMethodType) {
4907
4936
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
4908
4937
  addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.methodNotDefinedOnType().format({
@@ -5160,7 +5189,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5160
5189
  typeArgs.push(getTypeArgTypeResult(item, index));
5161
5190
  });
5162
5191
  // Set the node's type so it isn't reevaluated later.
5163
- setTypeForNode(node.items[0].valueExpression, types_1.UnknownType.create());
5192
+ setTypeResultForNode(node.items[0].valueExpression, { type: types_1.UnknownType.create() });
5164
5193
  }
5165
5194
  else {
5166
5195
  node.items.forEach((arg, index) => {
@@ -5204,7 +5233,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5204
5233
  node,
5205
5234
  };
5206
5235
  // Set the node's type so it isn't reevaluated later.
5207
- setTypeForNode(node, types_1.UnknownType.create());
5236
+ setTypeResultForNode(node, { type: types_1.UnknownType.create() });
5208
5237
  }
5209
5238
  else if (node.nodeType === 15 /* Dictionary */ && supportsDictExpression) {
5210
5239
  const inlinedTypeDict = typedDictClassType && (0, types_1.isInstantiableClass)(typedDictClassType)
@@ -5269,7 +5298,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5269
5298
  matchingSubtype = subtype;
5270
5299
  }
5271
5300
  }
5272
- });
5301
+ },
5302
+ /* sortSubtypes */ true);
5273
5303
  effectiveExpectedType = matchingSubtype;
5274
5304
  }
5275
5305
  let expectedTypeDiagAddendum;
@@ -6106,7 +6136,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6106
6136
  if (!isDiagnosticSuppressedForNode(errorNode)) {
6107
6137
  const functionName = typeResult.type.overloads[0].details.name || '<anonymous function>';
6108
6138
  const diagAddendum = new diagnostic_1.DiagnosticAddendum();
6109
- const argTypes = argList.map((t) => printType(getTypeOfArgument(t).type));
6139
+ const argTypes = argList.map((t) => {
6140
+ const typeString = printType(getTypeOfArgument(t).type);
6141
+ if (t.argumentCategory === 1 /* UnpackedList */) {
6142
+ return `*${typeString}`;
6143
+ }
6144
+ if (t.argumentCategory === 2 /* UnpackedDictionary */) {
6145
+ return `**${typeString}`;
6146
+ }
6147
+ return typeString;
6148
+ });
6110
6149
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
6111
6150
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }) + diagAddendum.getString(), errorNode);
6112
6151
  }
@@ -6610,7 +6649,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6610
6649
  var _a, _b;
6611
6650
  const memberType = (_a = getTypeOfObjectMember(errorNode, expandedCallType, '__call__',
6612
6651
  /* usage */ undefined,
6613
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
6652
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
6614
6653
  if (!memberType) {
6615
6654
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.objectNotCallable().format({
6616
6655
  type: printType(expandedCallType),
@@ -6866,14 +6905,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6866
6905
  // all positional parameters specified in the Concatenate must be
6867
6906
  // filled explicitly.
6868
6907
  if (typeResult.type.details.paramSpec && paramIndex < positionParamLimitIndex) {
6869
- if (!isDiagnosticSuppressedForNode(errorNode)) {
6870
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6871
- ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6872
- : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
6873
- expected: positionParamLimitIndex,
6874
- }), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
6908
+ if ((0, types_1.isTypeVar)(argTypeResult.type) && argTypeResult.type.paramSpecAccess === 'args') {
6909
+ if (!isDiagnosticSuppressedForNode(errorNode)) {
6910
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, positionParamLimitIndex === 1
6911
+ ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
6912
+ : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
6913
+ expected: positionParamLimitIndex,
6914
+ }), (_c = argList[argIndex].valueExpression) !== null && _c !== void 0 ? _c : errorNode);
6915
+ }
6916
+ reportedArgError = true;
6875
6917
  }
6876
- reportedArgError = true;
6877
6918
  }
6878
6919
  const argType = argTypeResult.type;
6879
6920
  if (isParamVariadic && (0, types_1.isUnpackedVariadicTypeVar)(argType)) {
@@ -7159,17 +7200,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7159
7200
  reportedArgError = true;
7160
7201
  }
7161
7202
  }
7162
- else if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'kwargs') {
7203
+ else if (typeResult.type.details.paramSpec &&
7204
+ (0, parameterUtils_1.isParamSpecKwargsArgument)(typeResult.type.details.paramSpec, argType)) {
7163
7205
  unpackedDictionaryArgType = types_1.AnyType.create();
7164
- if (typeResult.type.details.paramSpec) {
7165
- validateArgTypeParams.push({
7166
- paramCategory: 2 /* KwargsDict */,
7167
- paramType: typeResult.type.details.paramSpec,
7168
- requiresTypeVarMatching: false,
7169
- argument: argList[argIndex],
7170
- errorNode: argList[argIndex].valueExpression || errorNode,
7171
- });
7172
- }
7206
+ validateArgTypeParams.push({
7207
+ paramCategory: 2 /* KwargsDict */,
7208
+ paramType: typeResult.type.details.paramSpec,
7209
+ requiresTypeVarMatching: false,
7210
+ argument: argList[argIndex],
7211
+ argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
7212
+ errorNode: argList[argIndex].valueExpression || errorNode,
7213
+ });
7173
7214
  }
7174
7215
  else {
7175
7216
  const strObjType = getBuiltInObject(errorNode, 'str');
@@ -7297,20 +7338,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7297
7338
  }
7298
7339
  }
7299
7340
  else if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
7300
- // Handle the case where a *args: P.args is passed as an argument to
7301
- // a function that accepts a ParamSpec.
7341
+ // Handle the case where a *args: P.args (or *args: Any) is passed as an
7342
+ // argument to a function that accepts a ParamSpec.
7302
7343
  if (typeResult.type.details.paramSpec) {
7303
7344
  const argTypeResult = getTypeOfArgument(argList[argIndex]);
7304
7345
  const argType = argTypeResult.type;
7305
7346
  if (argTypeResult.isIncomplete) {
7306
7347
  isTypeIncomplete = true;
7307
7348
  }
7308
- if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
7349
+ if ((0, parameterUtils_1.isParamSpecArgsArgument)(typeResult.type.details.paramSpec, argType)) {
7309
7350
  validateArgTypeParams.push({
7310
7351
  paramCategory: 1 /* ArgsList */,
7311
7352
  paramType: typeResult.type.details.paramSpec,
7312
7353
  requiresTypeVarMatching: false,
7313
7354
  argument: argList[argIndex],
7355
+ argType: (0, types_1.isParamSpec)(argType) ? undefined : types_1.AnyType.create(),
7314
7356
  errorNode: (_j = argList[argIndex].valueExpression) !== null && _j !== void 0 ? _j : errorNode,
7315
7357
  });
7316
7358
  }
@@ -7563,7 +7605,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7563
7605
  return subtype;
7564
7606
  }
7565
7607
  return undefined;
7566
- });
7608
+ },
7609
+ /* sortSubtypes */ true);
7567
7610
  if ((0, types_1.isClassInstance)(filteredType)) {
7568
7611
  effectiveExpectedType = filteredType;
7569
7612
  }
@@ -7729,12 +7772,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7729
7772
  }
7730
7773
  if (type.details.paramSpec) {
7731
7774
  if (argParam.argument.argumentCategory === 1 /* UnpackedList */) {
7732
- if ((0, types_1.isParamSpec)(argResult.argType) && argResult.argType.paramSpecAccess === 'args') {
7775
+ if ((0, parameterUtils_1.isParamSpecArgsArgument)(type.details.paramSpec, argResult.argType)) {
7733
7776
  sawParamSpecArgs = true;
7734
7777
  }
7735
7778
  }
7736
7779
  if (argParam.argument.argumentCategory === 2 /* UnpackedDictionary */) {
7737
- if ((0, types_1.isParamSpec)(argResult.argType) && argResult.argType.paramSpecAccess === 'kwargs') {
7780
+ if ((0, parameterUtils_1.isParamSpecKwargsArgument)(type.details.paramSpec, argResult.argType)) {
7738
7781
  sawParamSpecKwargs = true;
7739
7782
  }
7740
7783
  }
@@ -8676,6 +8719,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8676
8719
  functionType.details.paramSpec = typeResult.type;
8677
8720
  return functionType;
8678
8721
  }
8722
+ if ((0, types_1.isClassInstance)(typeResult.type) && types_1.ClassType.isBuiltIn(typeResult.type, 'ellipsis')) {
8723
+ types_1.FunctionType.addDefaultParameters(functionType);
8724
+ return functionType;
8725
+ }
8679
8726
  }
8680
8727
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecDefaultNotTuple(), node);
8681
8728
  return undefined;
@@ -8933,12 +8980,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8933
8980
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
8934
8981
  magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, magicMethodName,
8935
8982
  /* usage */ undefined,
8936
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
8983
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
8937
8984
  }
8938
8985
  else if ((0, types_1.isInstantiableClass)(concreteSubtype)) {
8939
8986
  magicMethodType = (_b = getTypeOfClassMember(errorNode, concreteSubtype, magicMethodName,
8940
8987
  /* usage */ undefined,
8941
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 32 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
8988
+ /* diag */ undefined, 128 /* SkipAttributeAccessOverride */ | 64 /* ConsiderMetaclassOnly */)) === null || _b === void 0 ? void 0 : _b.type;
8942
8989
  }
8943
8990
  if (magicMethodType) {
8944
8991
  const functionArgs = args.map((arg) => {
@@ -9027,7 +9074,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9027
9074
  matchingSubtypeResult = subtypeResult;
9028
9075
  }
9029
9076
  }
9030
- });
9077
+ },
9078
+ /* sortSubtypes */ true);
9031
9079
  effectiveExpectedType = matchingSubtype;
9032
9080
  }
9033
9081
  let expectedTypeDiagAddendum = undefined;
@@ -9344,7 +9392,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9344
9392
  matchingSubtypeResult = subtypeResult;
9345
9393
  }
9346
9394
  }
9347
- });
9395
+ },
9396
+ /* sortSubtypes */ true);
9348
9397
  effectiveExpectedType = matchingSubtype;
9349
9398
  }
9350
9399
  let expectedTypeDiagAddendum;
@@ -10644,6 +10693,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10644
10693
  }
10645
10694
  return (0, typeUtils_1.convertToInstance)(typeVar);
10646
10695
  });
10696
+ const typeAliasScopeId = ParseTreeUtils.getScopeIdForNode(name);
10647
10697
  // Validate the default types for all type parameters.
10648
10698
  typeParameters.forEach((typeParam, index) => {
10649
10699
  var _a;
@@ -10651,7 +10701,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10651
10701
  if (typeParamNodes && index < typeParamNodes.length) {
10652
10702
  bestErrorNode = (_a = typeParamNodes[index].defaultExpression) !== null && _a !== void 0 ? _a : typeParamNodes[index].name;
10653
10703
  }
10654
- validateTypeParameterDefault(bestErrorNode, typeParam, typeParameters.slice(0, index));
10704
+ validateTypeParameterDefault(bestErrorNode, typeParam, typeParameters.slice(0, index), typeAliasScopeId);
10655
10705
  });
10656
10706
  // Verify that we have at most one variadic type variable.
10657
10707
  const variadics = typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
@@ -10661,7 +10711,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10661
10711
  }), errorNode);
10662
10712
  }
10663
10713
  const fileInfo = AnalyzerNodeInfo.getFileInfo(name);
10664
- const typeAliasScopeId = ParseTreeUtils.getScopeIdForNode(name);
10665
10714
  const boundTypeVars = typeParameters.filter((typeVar) => typeVar.scopeId !== typeAliasScopeId && typeVar.scopeType === 0 /* Class */);
10666
10715
  if (boundTypeVars.length > 0) {
10667
10716
  addError(localize_1.Localizer.Diagnostic.genericTypeAliasBoundTypeVar().format({
@@ -11203,14 +11252,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11203
11252
  if (types_1.ClassType.isBuiltIn(argType, 'TypedDict') || types_1.ClassType.isTypedDictClass(argType)) {
11204
11253
  classType.details.flags |= 128 /* TypedDictClass */;
11205
11254
  }
11206
- else if (types_1.ClassType.isTypedDictClass(classType) && !types_1.ClassType.isTypedDictClass(argType)) {
11207
- // Exempt Generic from this test. As of Python 3.11, generic TypedDict
11208
- // classes are supported.
11209
- if (!(0, types_1.isInstantiableClass)(argType) || !types_1.ClassType.isBuiltIn(argType, 'Generic')) {
11210
- // TypedDict classes must derive only from other TypedDict classes.
11211
- addError(localize_1.Localizer.Diagnostic.typedDictBaseClass(), arg);
11212
- }
11213
- }
11214
11255
  // Validate that the class isn't deriving from itself, creating a
11215
11256
  // circular dependency.
11216
11257
  if ((0, typeUtils_1.derivesFromClassRecursive)(argType, classType, /* ignoreUnknown */ true)) {
@@ -11371,7 +11412,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11371
11412
  const typeParamNode = node.typeParameters.parameters[index];
11372
11413
  bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
11373
11414
  }
11374
- validateTypeParameterDefault(bestErrorNode, typeParam, classType.details.typeParameters.slice(0, index));
11415
+ validateTypeParameterDefault(bestErrorNode, typeParam, classType.details.typeParameters.slice(0, index), classType.details.typeVarScopeId);
11375
11416
  });
11376
11417
  if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
11377
11418
  addError(localize_1.Localizer.Diagnostic.methodOrdering(), node.name);
@@ -11507,6 +11548,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11507
11548
  registerDeferredClassCompletion(node, /* dependsUpon */ undefined);
11508
11549
  // Synthesize TypedDict methods.
11509
11550
  if (types_1.ClassType.isTypedDictClass(classType)) {
11551
+ // TypedDict classes must derive only from other TypedDict classes.
11552
+ let foundInvalidBaseClass = false;
11553
+ const diag = new diagnostic_1.DiagnosticAddendum();
11554
+ classType.details.baseClasses.forEach((baseClass) => {
11555
+ if ((0, types_1.isClass)(baseClass) &&
11556
+ !types_1.ClassType.isTypedDictClass(baseClass) &&
11557
+ !types_1.ClassType.isBuiltIn(baseClass, ['_TypedDict', 'Generic'])) {
11558
+ foundInvalidBaseClass = true;
11559
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.typedDictBaseClass().format({ type: baseClass.details.name }));
11560
+ }
11561
+ });
11562
+ if (foundInvalidBaseClass) {
11563
+ addError(localize_1.Localizer.Diagnostic.typedDictBaseClass() + diag.getString(), node.name);
11564
+ }
11510
11565
  (0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType, (0, types_1.isClass)(decoratedType) && types_1.ClassType.isFinal(decoratedType));
11511
11566
  }
11512
11567
  // Synthesize dataclass methods.
@@ -11523,7 +11578,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11523
11578
  }
11524
11579
  let skipSynthesizeHash = false;
11525
11580
  const hashSymbol = (0, typeUtils_1.lookUpClassMember)(classType, '__hash__', 2 /* SkipBaseClasses */);
11526
- if (hashSymbol) {
11581
+ // If there is a hash symbol defined in the class (i.e. one that we didn't
11582
+ // synthesize above), then we shouldn't synthesize a new one for the dataclass.
11583
+ if (hashSymbol && !hashSymbol.symbol.getSynthesizedType()) {
11527
11584
  skipSynthesizeHash = true;
11528
11585
  }
11529
11586
  (0, dataClasses_1.synthesizeDataClassMethods)(evaluatorInterface, node, classType, skipSynthesizedInit, hasExistingInitMethod, skipSynthesizeHash);
@@ -11573,11 +11630,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11573
11630
  // type parameter. If so, validates that it is in the list of "live" type
11574
11631
  // parameters and updates the scope of the type parameter referred to in the
11575
11632
  // default type expression.
11576
- function validateTypeParameterDefault(errorNode, typeParam, otherLiveTypeParams) {
11633
+ function validateTypeParameterDefault(errorNode, typeParam, otherLiveTypeParams, scopeId) {
11577
11634
  if (!typeParam.details.defaultType &&
11578
11635
  !typeParam.details.isSynthesized &&
11579
11636
  !typeParam.details.isSynthesizedSelf) {
11580
- const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.defaultType);
11637
+ const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.defaultType && param.scopeId === scopeId);
11581
11638
  if (typeVarWithDefault) {
11582
11639
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarWithoutDefault().format({
11583
11640
  name: typeParam.details.name,
@@ -11812,8 +11869,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11812
11869
  const initSubclassMethodInfo = getTypeOfClassMemberName(errorNode, classType,
11813
11870
  /* isAccessedThroughObject */ false, '__init_subclass__', { method: 'get' },
11814
11871
  /* diag */ undefined, 1 /* AccessClassMembersOnly */ |
11815
- 4 /* SkipObjectBaseClass */ |
11816
- 128 /* SkipOriginalClass */, classType);
11872
+ 8 /* SkipObjectBaseClass */ |
11873
+ 256 /* SkipOriginalClass */, classType);
11817
11874
  if (initSubclassMethodInfo) {
11818
11875
  const initSubclassMethodType = initSubclassMethodInfo.type;
11819
11876
  if (initSubclassMethodType) {
@@ -11824,7 +11881,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11824
11881
  }
11825
11882
  else if (classType.details.effectiveMetaclass && (0, types_1.isClass)(classType.details.effectiveMetaclass)) {
11826
11883
  // See if the metaclass has a `__new__` method that accepts keyword parameters.
11827
- const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 32 /* SkipTypeBaseClass */);
11884
+ const newMethodMember = (0, typeUtils_1.lookUpClassMember)(classType.details.effectiveMetaclass, '__new__', 64 /* SkipTypeBaseClass */);
11828
11885
  if (newMethodMember) {
11829
11886
  const newMethodType = getTypeOfMember(newMethodMember);
11830
11887
  if ((0, types_1.isFunction)(newMethodType)) {
@@ -11887,20 +11944,72 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11887
11944
  });
11888
11945
  }
11889
11946
  function getTypeOfFunction(node) {
11890
- var _a, _b;
11891
- const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11892
- // Is this type already cached?
11893
- const cachedFunctionType = readTypeCache(node.name, 0 /* None */);
11894
- if (cachedFunctionType) {
11895
- if (!(0, types_1.isFunction)(cachedFunctionType)) {
11947
+ // Is this predecorated function type cached?
11948
+ let functionType = readTypeCache(node.name, 0 /* None */);
11949
+ if (functionType) {
11950
+ if (!(0, types_1.isFunction)(functionType)) {
11896
11951
  // This can happen in certain rare circumstances where the
11897
11952
  // function declaration falls within an unreachable code block.
11898
11953
  return undefined;
11899
11954
  }
11900
- return {
11901
- functionType: cachedFunctionType,
11902
- decoratedType: readTypeCache(node, 0 /* None */) || types_1.UnknownType.create(),
11903
- };
11955
+ }
11956
+ else {
11957
+ functionType = getTypeOfFunctionPredecorated(node);
11958
+ }
11959
+ // Is the decorated function type cached?
11960
+ let decoratedType = readTypeCache(node, 0 /* None */);
11961
+ if (decoratedType) {
11962
+ return { functionType, decoratedType };
11963
+ }
11964
+ // Populate the cache with a temporary value to handle recursion.
11965
+ writeTypeCache(node, { type: functionType }, /* flags */ undefined);
11966
+ // If it's an async function, wrap the return type in an Awaitable or Generator.
11967
+ // Set the "partially evaluated" flag around this logic to detect recursion.
11968
+ functionType.details.flags |= 131072 /* PartiallyEvaluated */;
11969
+ const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
11970
+ functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
11971
+ // Apply all of the decorators in reverse order.
11972
+ decoratedType = preDecoratedType;
11973
+ let foundUnknown = false;
11974
+ for (let i = node.decorators.length - 1; i >= 0; i--) {
11975
+ const decorator = node.decorators[i];
11976
+ const newDecoratedType = (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
11977
+ const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
11978
+ if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
11979
+ // Report this error only on the first unknown type.
11980
+ if (!foundUnknown) {
11981
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11982
+ addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
11983
+ foundUnknown = true;
11984
+ }
11985
+ }
11986
+ else {
11987
+ // Apply the decorator only if the type is known.
11988
+ decoratedType = newDecoratedType;
11989
+ }
11990
+ }
11991
+ // See if there are any overloads provided by previous function declarations.
11992
+ if ((0, types_1.isFunction)(decoratedType)) {
11993
+ if (types_1.FunctionType.isOverloaded(decoratedType)) {
11994
+ // Mark all the parameters as accessed.
11995
+ node.parameters.forEach((param) => {
11996
+ markParamAccessed(param);
11997
+ });
11998
+ }
11999
+ decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
12000
+ }
12001
+ writeTypeCache(node, { type: decoratedType }, 0 /* None */);
12002
+ return { functionType, decoratedType };
12003
+ }
12004
+ // Evaluates the type of a "def" statement without applying an async
12005
+ // modifier or any decorators.
12006
+ function getTypeOfFunctionPredecorated(node) {
12007
+ var _a, _b, _c;
12008
+ const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
12009
+ // Is this type already cached?
12010
+ const cachedFunctionType = readTypeCache(node.name, 0 /* None */);
12011
+ if (cachedFunctionType && (0, types_1.isFunction)(cachedFunctionType)) {
12012
+ return cachedFunctionType;
11904
12013
  }
11905
12014
  let functionDecl;
11906
12015
  const decl = AnalyzerNodeInfo.getDeclaration(node);
@@ -11912,11 +12021,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11912
12021
  const containingClassNode = ParseTreeUtils.getEnclosingClass(node, /* stopAtFunction */ true);
11913
12022
  let containingClassType;
11914
12023
  if (containingClassNode) {
11915
- const classInfo = getTypeOfClass(containingClassNode);
11916
- if (!classInfo) {
11917
- return undefined;
11918
- }
11919
- containingClassType = classInfo.classType;
12024
+ containingClassType = (_a = getTypeOfClass(containingClassNode)) === null || _a === void 0 ? void 0 : _a.classType;
11920
12025
  }
11921
12026
  let functionFlags = (0, decorators_1.getFunctionFlagsFromDecorators)(evaluatorInterface, node, !!containingClassNode);
11922
12027
  if (functionDecl === null || functionDecl === void 0 ? void 0 : functionDecl.isGenerator) {
@@ -11945,14 +12050,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11945
12050
  functionType.details.builtInName = node.name.value;
11946
12051
  }
11947
12052
  functionType.details.declaration = functionDecl;
11948
- // Allow recursion by registering the partially-constructed
11949
- // function type.
12053
+ // Allow recursion by caching and registering the partially-constructed function type.
11950
12054
  const scope = ScopeUtils.getScopeForNode(node);
11951
12055
  const functionSymbol = scope === null || scope === void 0 ? void 0 : scope.lookUpSymbolRecursive(node.name.value);
11952
12056
  if (functionDecl && functionSymbol) {
11953
12057
  setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
11954
12058
  }
11955
- writeTypeCache(node, { type: functionType }, /* flags */ undefined);
11956
12059
  writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
11957
12060
  // Is this an "__init__" method within a pseudo-generic class? If so,
11958
12061
  // we'll add generic types to the constructor's parameters.
@@ -11992,14 +12095,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11992
12095
  else {
11993
12096
  functionType.details.typeParameters = typeParametersSeen;
11994
12097
  }
11995
- const markParamAccessed = (param) => {
11996
- if (param.name) {
11997
- const symbolWithScope = lookUpSymbolRecursive(param.name, param.name.value, /* honorCodeFlow */ false);
11998
- if (symbolWithScope) {
11999
- setSymbolAccessed(fileInfo, symbolWithScope.symbol, param.name);
12000
- }
12001
- }
12002
- };
12003
12098
  let paramsArePositionOnly = true;
12004
12099
  const isFirstParamClsOrSelf = containingClassType &&
12005
12100
  (types_1.FunctionType.isClassMethod(functionType) ||
@@ -12181,7 +12276,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12181
12276
  // If there was a defined return type, analyze that first so when we
12182
12277
  // walk the contents of the function, return statements can be
12183
12278
  // validated against this type.
12184
- const returnTypeAnnotationNode = (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : (_b = node.functionAnnotationComment) === null || _b === void 0 ? void 0 : _b.returnTypeAnnotation;
12279
+ const returnTypeAnnotationNode = (_b = node.returnTypeAnnotation) !== null && _b !== void 0 ? _b : (_c = node.functionAnnotationComment) === null || _c === void 0 ? void 0 : _c.returnTypeAnnotation;
12185
12280
  if (returnTypeAnnotationNode) {
12186
12281
  // Temporarily set the return type to unknown in case of recursion.
12187
12282
  functionType.details.declaredReturnType = types_1.UnknownType.create();
@@ -12232,45 +12327,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12232
12327
  const typeParamNode = node.typeParameters.parameters[index];
12233
12328
  bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12234
12329
  }
12235
- validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index));
12330
+ validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12236
12331
  });
12237
- // If it's an async function, wrap the return type in an Awaitable or Generator.
12238
- const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
12239
12332
  // Clear the "partially evaluated" flag to indicate that the functionType
12240
12333
  // is fully evaluated.
12241
12334
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
12242
- // Apply all of the decorators in reverse order.
12243
- let decoratedType = preDecoratedType;
12244
- let foundUnknown = false;
12245
- for (let i = node.decorators.length - 1; i >= 0; i--) {
12246
- const decorator = node.decorators[i];
12247
- const newDecoratedType = (0, decorators_1.applyFunctionDecorator)(evaluatorInterface, decoratedType, functionType, decorator, node);
12248
- const unknownOrAny = (0, typeUtils_1.containsAnyOrUnknown)(newDecoratedType, /* recurse */ false);
12249
- if (unknownOrAny && (0, types_1.isUnknown)(unknownOrAny)) {
12250
- // Report this error only on the first unknown type.
12251
- if (!foundUnknown) {
12252
- addDiagnostic(fileInfo.diagnosticRuleSet.reportUntypedFunctionDecorator, diagnosticRules_1.DiagnosticRule.reportUntypedFunctionDecorator, localize_1.Localizer.Diagnostic.functionDecoratorTypeUnknown(), node.decorators[i].expression);
12253
- foundUnknown = true;
12254
- }
12255
- }
12256
- else {
12257
- // Apply the decorator only if the type is known.
12258
- decoratedType = newDecoratedType;
12259
- }
12260
- }
12261
- // See if there are any overloads provided by previous function declarations.
12262
- if ((0, types_1.isFunction)(decoratedType)) {
12263
- if (types_1.FunctionType.isOverloaded(decoratedType)) {
12264
- // Mark all the parameters as accessed.
12265
- node.parameters.forEach((param) => {
12266
- markParamAccessed(param);
12267
- });
12335
+ writeTypeCache(node.name, { type: functionType }, 0 /* None */);
12336
+ return functionType;
12337
+ }
12338
+ function markParamAccessed(param) {
12339
+ if (param.name) {
12340
+ const symbolWithScope = lookUpSymbolRecursive(param.name, param.name.value, /* honorCodeFlow */ false);
12341
+ if (symbolWithScope) {
12342
+ setSymbolAccessed(AnalyzerNodeInfo.getFileInfo(param), symbolWithScope.symbol, param.name);
12268
12343
  }
12269
- decoratedType = (0, decorators_1.addOverloadsToFunctionType)(evaluatorInterface, node, decoratedType);
12270
12344
  }
12271
- writeTypeCache(node.name, { type: functionType }, 0 /* None */);
12272
- writeTypeCache(node, { type: decoratedType }, 0 /* None */);
12273
- return { functionType, decoratedType };
12274
12345
  }
12275
12346
  // If the declared return type of a function contains type variables that
12276
12347
  // are found nowhere else in the signature and are contained within a
@@ -14228,7 +14299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14228
14299
  if ((0, types_1.isInstantiableClass)(subtype)) {
14229
14300
  // Try to find a member that has a declared type. If so, that
14230
14301
  // overrides any inferred types.
14231
- let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 16 /* DeclaredTypesOnly */);
14302
+ let member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
14232
14303
  if (!member) {
14233
14304
  member = (0, typeUtils_1.lookUpClassMember)(subtype, memberName);
14234
14305
  }
@@ -14245,7 +14316,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14245
14316
  else if ((0, types_1.isClassInstance)(subtype)) {
14246
14317
  // Try to find a member that has a declared type. If so, that
14247
14318
  // overrides any inferred types.
14248
- let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 16 /* DeclaredTypesOnly */);
14319
+ let member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName, 32 /* DeclaredTypesOnly */);
14249
14320
  if (!member) {
14250
14321
  member = (0, typeUtils_1.lookUpObjectMember)(subtype, memberName);
14251
14322
  }
@@ -14311,7 +14382,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14311
14382
  }
14312
14383
  else if ((0, types_1.isInstantiableClass)(baseType)) {
14313
14384
  const initMethodType = (_b = getTypeOfObjectMember(argNode.parent.leftExpression, types_1.ClassType.cloneAsInstance(baseType), '__init__', { method: 'get' },
14314
- /* diag */ undefined, 4 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
14385
+ /* diag */ undefined, 8 /* SkipObjectBaseClass */)) === null || _b === void 0 ? void 0 : _b.type;
14315
14386
  if (initMethodType && (0, types_1.isFunction)(initMethodType)) {
14316
14387
  const paramDecl = getDeclarationFromFunctionNamedParameter(initMethodType, paramName);
14317
14388
  if (paramDecl) {
@@ -14625,25 +14696,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14625
14696
  if (resolvedDecl.type === 8 /* Alias */) {
14626
14697
  // Build a module type that corresponds to the declaration and
14627
14698
  // its associated loader actions.
14628
- let moduleName = resolvedDecl.moduleName;
14629
- if (decl.type === 8 /* Alias */) {
14630
- if (decl.symbolName) {
14631
- moduleName += '.' + decl.symbolName;
14632
- }
14633
- // If the module name is relative to the current file, use that
14634
- // file's module name as a reference.
14635
- if (moduleName.startsWith('.')) {
14636
- const fileInfo = AnalyzerNodeInfo.getFileInfo(decl.node);
14637
- const nameParts = fileInfo.moduleName.split('.');
14638
- moduleName = moduleName.substr(1);
14639
- while (moduleName.startsWith('.') && nameParts.length > 0) {
14640
- moduleName = moduleName.substr(1);
14641
- nameParts.pop();
14642
- }
14643
- moduleName = nameParts.join('.') + '.' + moduleName;
14644
- }
14645
- }
14646
- const moduleType = types_1.ModuleType.create(moduleName, resolvedDecl.path);
14699
+ const moduleType = types_1.ModuleType.create(resolvedDecl.moduleName, resolvedDecl.path);
14647
14700
  if (resolvedDecl.symbolName && resolvedDecl.submoduleFallback) {
14648
14701
  return applyLoaderActionsToModuleType(moduleType, resolvedDecl.submoduleFallback, importLookup);
14649
14702
  }
@@ -15778,7 +15831,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15778
15831
  if (destType.typeArguments) {
15779
15832
  // If the dest type is specialized, make sure the specialized source
15780
15833
  // type arguments are assignable to the dest type arguments.
15781
- return assignTypeArguments(destType, curSrcType, diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
15834
+ return assignTypeArguments(destType, curSrcType,
15835
+ // Don't emit a diag addendum if we're in an invariant context. It's
15836
+ // sufficient to simply indicate that the types are not the same
15837
+ // in this case. Adding more information is unnecessary and confusing.
15838
+ (flags & 1 /* EnforceInvariance */) === 0 ? diag : undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount);
15782
15839
  }
15783
15840
  if (destTypeVarContext && curSrcType.typeArguments && !destTypeVarContext.isLocked()) {
15784
15841
  // Populate the typeVar map with type arguments of the source.
@@ -16187,9 +16244,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16187
16244
  }
16188
16245
  if ((0, types_1.isInstantiableClass)(destType)) {
16189
16246
  if ((0, types_1.isInstantiableClass)(expandedSrcType)) {
16190
- // PEP 544 says that if the dest type is a Type[Proto] class,
16247
+ // PEP 544 says that if the dest type is a type[Proto] class,
16191
16248
  // the source must be a "concrete" (non-protocol) class.
16192
- if (types_1.ClassType.isProtocolClass(destType)) {
16249
+ if (types_1.ClassType.isProtocolClass(destType) &&
16250
+ (flags & 4096 /* IgnoreProtocolAssignmentCheck */) === 0) {
16193
16251
  if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
16194
16252
  (0, types_1.isInstantiableClass)(srcType) &&
16195
16253
  !srcType.includeSubclasses) {
@@ -17313,6 +17371,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17313
17371
  !srcParamSpec ||
17314
17372
  !(0, types_1.isTypeSame)(srcParamSpec, destParamSpec, { ignoreTypeFlags: true })) {
17315
17373
  const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* SynthesizedMethod */, effectiveSrcType.details.docString);
17374
+ remainingFunction.details.deprecatedMessage = effectiveSrcType.details.deprecatedMessage;
17316
17375
  remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
17317
17376
  remainingFunction.details.constructorTypeVarScopeId =
17318
17377
  effectiveSrcType.details.constructorTypeVarScopeId;
@@ -18319,6 +18378,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18319
18378
  runWithCancellationToken,
18320
18379
  getType,
18321
18380
  getTypeResult,
18381
+ getTypeResultForDecorator,
18322
18382
  getCachedType,
18323
18383
  getTypeOfExpression,
18324
18384
  getTypeOfAnnotation,
@@ -18408,7 +18468,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18408
18468
  disposeEvaluator,
18409
18469
  useSpeculativeMode,
18410
18470
  isSpeculativeModeInUse,
18411
- setTypeForNode,
18471
+ setTypeResultForNode,
18412
18472
  checkForCancellation,
18413
18473
  printControlFlowGraph,
18414
18474
  printTypeVarContext,