@zzzen/pyright-internal 1.2.0-dev.20240609 → 1.2.0-dev.20240616

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 (134) hide show
  1. package/dist/analyzer/binder.d.ts +3 -1
  2. package/dist/analyzer/binder.js +9 -3
  3. package/dist/analyzer/binder.js.map +1 -1
  4. package/dist/analyzer/checker.js +3 -3
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/constraintSolver.js +1 -4
  7. package/dist/analyzer/constraintSolver.js.map +1 -1
  8. package/dist/analyzer/constructors.js +0 -2
  9. package/dist/analyzer/constructors.js.map +1 -1
  10. package/dist/analyzer/dataClasses.d.ts +0 -1
  11. package/dist/analyzer/dataClasses.js +51 -77
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/decorators.d.ts +2 -1
  14. package/dist/analyzer/decorators.js +34 -39
  15. package/dist/analyzer/decorators.js.map +1 -1
  16. package/dist/analyzer/docStringUtils.d.ts +0 -1
  17. package/dist/analyzer/docStringUtils.js +1 -6
  18. package/dist/analyzer/docStringUtils.js.map +1 -1
  19. package/dist/analyzer/enums.js +1 -1
  20. package/dist/analyzer/enums.js.map +1 -1
  21. package/dist/analyzer/importResolver.js +11 -9
  22. package/dist/analyzer/importResolver.js.map +1 -1
  23. package/dist/analyzer/namedTuples.js +3 -3
  24. package/dist/analyzer/namedTuples.js.map +1 -1
  25. package/dist/analyzer/parseTreeUtils.d.ts +1 -1
  26. package/dist/analyzer/properties.js +2 -2
  27. package/dist/analyzer/properties.js.map +1 -1
  28. package/dist/analyzer/protocols.js +14 -3
  29. package/dist/analyzer/protocols.js.map +1 -1
  30. package/dist/analyzer/service.js +27 -48
  31. package/dist/analyzer/service.js.map +1 -1
  32. package/dist/analyzer/sourceFile.d.ts +2 -1
  33. package/dist/analyzer/sourceFile.js +4 -2
  34. package/dist/analyzer/sourceFile.js.map +1 -1
  35. package/dist/analyzer/typeDocStringUtils.d.ts +1 -0
  36. package/dist/analyzer/typeDocStringUtils.js +8 -1
  37. package/dist/analyzer/typeDocStringUtils.js.map +1 -1
  38. package/dist/analyzer/typeEvaluator.js +468 -459
  39. package/dist/analyzer/typeEvaluator.js.map +1 -1
  40. package/dist/analyzer/typePrinter.js +4 -2
  41. package/dist/analyzer/typePrinter.js.map +1 -1
  42. package/dist/analyzer/typeUtils.d.ts +0 -1
  43. package/dist/analyzer/typeUtils.js +9 -22
  44. package/dist/analyzer/typeUtils.js.map +1 -1
  45. package/dist/analyzer/typedDicts.js +6 -6
  46. package/dist/analyzer/typedDicts.js.map +1 -1
  47. package/dist/analyzer/types.d.ts +40 -42
  48. package/dist/analyzer/types.js +84 -91
  49. package/dist/analyzer/types.js.map +1 -1
  50. package/dist/commands/dumpFileDebugInfoCommand.js +16 -24
  51. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  52. package/dist/common/cancellationUtils.d.ts +1 -0
  53. package/dist/common/cancellationUtils.js +15 -1
  54. package/dist/common/cancellationUtils.js.map +1 -1
  55. package/dist/common/configOptions.js +1 -1
  56. package/dist/common/configOptions.js.map +1 -1
  57. package/dist/common/docStringService.d.ts +15 -0
  58. package/dist/common/docStringService.js +38 -0
  59. package/dist/common/docStringService.js.map +1 -0
  60. package/dist/common/envVarUtils.js +3 -1
  61. package/dist/common/envVarUtils.js.map +1 -1
  62. package/dist/common/extensibility.d.ts +1 -7
  63. package/dist/common/extensibility.js.map +1 -1
  64. package/dist/common/languageServerInterface.d.ts +1 -2
  65. package/dist/common/languageServerInterface.js.map +1 -1
  66. package/dist/common/serviceKeys.d.ts +2 -0
  67. package/dist/common/serviceKeys.js +1 -0
  68. package/dist/common/serviceKeys.js.map +1 -1
  69. package/dist/common/serviceProvider.js +3 -0
  70. package/dist/common/serviceProvider.js.map +1 -1
  71. package/dist/common/serviceProviderExtensions.d.ts +2 -0
  72. package/dist/common/serviceProviderExtensions.js +8 -0
  73. package/dist/common/serviceProviderExtensions.js.map +1 -1
  74. package/dist/common/stringUtils.d.ts +1 -0
  75. package/dist/common/stringUtils.js +5 -1
  76. package/dist/common/stringUtils.js.map +1 -1
  77. package/dist/common/uri/uriUtils.d.ts +1 -1
  78. package/dist/common/uri/uriUtils.js +1 -1
  79. package/dist/common/uri/uriUtils.js.map +1 -1
  80. package/dist/languageServerBase.d.ts +1 -1
  81. package/dist/languageServerBase.js +2 -2
  82. package/dist/languageServerBase.js.map +1 -1
  83. package/dist/languageService/completionProvider.d.ts +1 -0
  84. package/dist/languageService/completionProvider.js +16 -7
  85. package/dist/languageService/completionProvider.js.map +1 -1
  86. package/dist/languageService/completionProviderUtils.d.ts +2 -1
  87. package/dist/languageService/completionProviderUtils.js +6 -4
  88. package/dist/languageService/completionProviderUtils.js.map +1 -1
  89. package/dist/languageService/definitionProvider.d.ts +2 -1
  90. package/dist/languageService/definitionProvider.js.map +1 -1
  91. package/dist/languageService/hoverProvider.d.ts +2 -1
  92. package/dist/languageService/hoverProvider.js +7 -5
  93. package/dist/languageService/hoverProvider.js.map +1 -1
  94. package/dist/languageService/signatureHelpProvider.d.ts +3 -1
  95. package/dist/languageService/signatureHelpProvider.js +8 -6
  96. package/dist/languageService/signatureHelpProvider.js.map +1 -1
  97. package/dist/localization/package.nls.cs.json +2 -1
  98. package/dist/localization/package.nls.de.json +2 -1
  99. package/dist/localization/package.nls.es.json +1 -0
  100. package/dist/localization/package.nls.fr.json +2 -1
  101. package/dist/localization/package.nls.it.json +2 -1
  102. package/dist/localization/package.nls.ja.json +2 -1
  103. package/dist/localization/package.nls.ko.json +2 -1
  104. package/dist/localization/package.nls.pl.json +2 -1
  105. package/dist/localization/package.nls.pt-br.json +2 -1
  106. package/dist/localization/package.nls.qps-ploc.json +2 -1
  107. package/dist/localization/package.nls.ru.json +2 -1
  108. package/dist/localization/package.nls.tr.json +2 -1
  109. package/dist/localization/package.nls.zh-cn.json +2 -1
  110. package/dist/localization/package.nls.zh-tw.json +2 -1
  111. package/dist/tests/checker.test.js +8 -0
  112. package/dist/tests/checker.test.js.map +1 -1
  113. package/dist/tests/config.test.js +1 -1
  114. package/dist/tests/config.test.js.map +1 -1
  115. package/dist/tests/docStringConversion.test.d.ts +2 -1
  116. package/dist/tests/docStringConversion.test.js +300 -293
  117. package/dist/tests/docStringConversion.test.js.map +1 -1
  118. package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +2 -2
  119. package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -1
  120. package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +1 -1
  121. package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -1
  122. package/dist/tests/harness/fourslash/testState.js +2 -1
  123. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  124. package/dist/tests/pathUtils.test.js +6 -0
  125. package/dist/tests/pathUtils.test.js.map +1 -1
  126. package/dist/tests/signatureHelp.test.js +2 -1
  127. package/dist/tests/signatureHelp.test.js.map +1 -1
  128. package/dist/tests/uri.test.js +6 -0
  129. package/dist/tests/uri.test.js.map +1 -1
  130. package/dist/workspaceFactory.d.ts +1 -1
  131. package/package.json +1 -1
  132. package/dist/tests/docStringUtils.test.d.ts +0 -1
  133. package/dist/tests/docStringUtils.test.js +0 -74
  134. package/dist/tests/docStringUtils.test.js.map +0 -1
@@ -466,7 +466,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
466
466
  functionClass = getBuiltInType(node, 'function');
467
467
  unionTypeClass = getTypesType(node, 'UnionType');
468
468
  if (unionTypeClass && (0, types_1.isClass)(unionTypeClass)) {
469
- unionTypeClass.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
469
+ unionTypeClass.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
470
470
  }
471
471
  // Initialize and cache "Collection" to break a cyclical dependency
472
472
  // that occurs when resolving tuple below.
@@ -487,7 +487,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
487
487
  }
488
488
  // Wire up the `Any` class to the special-form version of our internal AnyType.
489
489
  if (objectClass && (0, types_1.isInstantiableClass)(objectClass) && typeClass && (0, types_1.isInstantiableClass)(typeClass)) {
490
- const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | -2147483648 /* ClassTypeFlags.SpecialFormClass */,
490
+ const anyClass = types_1.ClassType.createInstantiable('Any', 'typing.Any', 'typing', uri_1.Uri.empty(), 1 /* ClassTypeFlags.BuiltInClass */ | 8388608 /* ClassTypeFlags.SpecialFormClass */,
491
491
  /* typeSourceId */ -1,
492
492
  /* declaredMetaclass */ undefined,
493
493
  /* effectiveMetaclass */ typeClass);
@@ -740,6 +740,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
740
740
  if (expectingInstantiable) {
741
741
  validateTypeIsInstantiable(typeResult, flags, node);
742
742
  }
743
+ // If this is a PEP 695 type alias, remove the special form so the type
744
+ // printer prints it as its aliased type rather than TypeAliasType.
745
+ if ((flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0) {
746
+ if (typeResult.type.specialForm && types_1.ClassType.isBuiltIn(typeResult.type.specialForm, 'TypeAliasType')) {
747
+ typeResult.type = types_1.TypeBase.cloneAsSpecialForm(typeResult.type, undefined);
748
+ }
749
+ }
743
750
  return typeResult;
744
751
  }
745
752
  // Reports the case where a function or class has been decorated with
@@ -1460,7 +1467,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1460
1467
  }
1461
1468
  // If this is a type[Any] or type[Unknown], allow any other members.
1462
1469
  if ((0, types_1.isClassInstance)(objectType) && types_1.ClassType.isBuiltIn(objectType, 'type') && objectType.includeSubclasses) {
1463
- if ((flags & 8 /* MemberAccessFlags.SkipTypeBaseClass */) === 0) {
1470
+ if ((flags & (8 /* MemberAccessFlags.SkipTypeBaseClass */ | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */)) === 0) {
1464
1471
  const typeArg = objectType.typeArguments && objectType.typeArguments.length >= 1
1465
1472
  ? objectType.typeArguments[0]
1466
1473
  : types_1.UnknownType.create();
@@ -4049,7 +4056,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4049
4056
  isDescriptorError = true;
4050
4057
  }
4051
4058
  if ((0, types_1.isInstantiableClass)(memberInfo.classType) &&
4052
- types_1.ClassType.isFrozenDataClass(memberInfo.classType) &&
4059
+ types_1.ClassType.isDataClassFrozen(memberInfo.classType) &&
4053
4060
  isAccessedThroughObject) {
4054
4061
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.dataClassFrozen().format({
4055
4062
  name: printType(types_1.ClassType.cloneAsInstance(memberInfo.classType)),
@@ -5647,7 +5654,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5647
5654
  // the base type of this call is not the same as one of the tracked signatures.
5648
5655
  // This is important for nested generic calls (e.g. "foo(foo(x))").
5649
5656
  if (signatureTracker) {
5650
- baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.leftExpression.start);
5657
+ baseTypeResult.type = (0, typeUtils_1.ensureFunctionSignaturesAreUnique)(baseTypeResult.type, signatureTracker, node.start);
5651
5658
  }
5652
5659
  if (!(0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
5653
5660
  if (node.leftExpression.nodeType === 38 /* ParseNodeType.Name */ && node.leftExpression.value === 'super') {
@@ -6964,6 +6971,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6964
6971
  if ((0, types_1.isTypeVar)(unexpandedCallType)) {
6965
6972
  returnType = (0, typeUtils_1.convertToInstance)(unexpandedCallType);
6966
6973
  }
6974
+ // If we instantiated the "deprecated" class, attach the deprecation
6975
+ // message to the instance.
6976
+ if (errorNode.nodeType === 9 /* ParseNodeType.Call */ &&
6977
+ returnType &&
6978
+ (0, types_1.isClassInstance)(returnType) &&
6979
+ types_1.ClassType.isBuiltIn(returnType, 'deprecated')) {
6980
+ returnType = types_1.ClassType.cloneForDeprecatedInstance(returnType, (0, decorators_1.getDeprecatedMessageFromCall)(errorNode));
6981
+ }
6967
6982
  // If we instantiated a type, transform it into a class.
6968
6983
  // This can happen if someone directly instantiates a metaclass
6969
6984
  // deriving from type.
@@ -8026,36 +8041,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8026
8041
  }), errorNode.nodeType === 9 /* ParseNodeType.Call */ ? errorNode.leftExpression : errorNode);
8027
8042
  }
8028
8043
  }
8029
- if (type.boundTypeVarScopeId) {
8030
- // If the function was bound to a class or object and was a constructor, a
8031
- // static method or a class method, it's possible that some of that class's
8032
- // type variables have not yet been solved. Add that class's TypeVar scope ID.
8033
- if (type.preBoundFlags !== undefined && type.boundToType && (0, typeUtils_1.requiresSpecialization)(type.boundToType)) {
8034
- if (type.preBoundFlags &
8035
- (4 /* FunctionTypeFlags.StaticMethod */ | 2 /* FunctionTypeFlags.ClassMethod */ | 4 /* FunctionTypeFlags.StaticMethod */)) {
8036
- typeVarContext.addSolveForScope(type.boundTypeVarScopeId);
8037
- }
8038
- }
8039
- // The type annotation for the "self" parameter in an __init__ method to
8040
- // can influence the type being constructed.
8041
- if (type.details.name === '__init__' &&
8042
- type.strippedFirstParamType &&
8043
- type.boundToType &&
8044
- (0, types_1.isClassInstance)(type.strippedFirstParamType) &&
8045
- (0, types_1.isClassInstance)(type.boundToType) &&
8046
- types_1.ClassType.isSameGenericClass(type.strippedFirstParamType, type.boundToType) &&
8047
- type.strippedFirstParamType.typeArguments) {
8048
- const typeParams = type.strippedFirstParamType.details.typeParameters;
8049
- specializedInitSelfType = type.strippedFirstParamType;
8050
- type.strippedFirstParamType.typeArguments.forEach((typeArg, index) => {
8051
- if (index < typeParams.length) {
8052
- const typeParam = typeParams[index];
8053
- if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8054
- typeVarContext.setTypeVarType(typeParams[index], typeArg);
8055
- }
8044
+ // The type annotation for the "self" parameter in an __init__ method to
8045
+ // can influence the type being constructed.
8046
+ if (type.details.name === '__init__' &&
8047
+ type.strippedFirstParamType &&
8048
+ type.boundToType &&
8049
+ (0, types_1.isClassInstance)(type.strippedFirstParamType) &&
8050
+ (0, types_1.isClassInstance)(type.boundToType) &&
8051
+ types_1.ClassType.isSameGenericClass(type.strippedFirstParamType, type.boundToType) &&
8052
+ type.strippedFirstParamType.typeArguments) {
8053
+ const typeParams = type.strippedFirstParamType.details.typeParameters;
8054
+ specializedInitSelfType = type.strippedFirstParamType;
8055
+ type.strippedFirstParamType.typeArguments.forEach((typeArg, index) => {
8056
+ if (index < typeParams.length) {
8057
+ const typeParam = typeParams[index];
8058
+ if (!(0, types_1.isTypeSame)(typeParam, typeArg, { ignorePseudoGeneric: true })) {
8059
+ typeVarContext.setTypeVarType(typeParams[index], typeArg);
8056
8060
  }
8057
- });
8058
- }
8061
+ }
8062
+ });
8059
8063
  }
8060
8064
  // Special-case a few built-in calls that are often used for
8061
8065
  // casting or checking for unknown types.
@@ -9191,7 +9195,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9191
9195
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.newTypeLiteral(), argList[1].node || errorNode);
9192
9196
  }
9193
9197
  let classFlags = baseClass.details.flags & ~(1 /* ClassTypeFlags.BuiltInClass */ | 2 /* ClassTypeFlags.SpecialBuiltIn */);
9194
- classFlags |= 8192 /* ClassTypeFlags.Final */ | 536870912 /* ClassTypeFlags.NewTypeClass */ | 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */;
9198
+ classFlags |= 256 /* ClassTypeFlags.Final */ | 2097152 /* ClassTypeFlags.NewTypeClass */ | 4194304 /* ClassTypeFlags.ValidTypeAliasClass */;
9195
9199
  const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
9196
9200
  /* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
9197
9201
  classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
@@ -9223,7 +9227,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9223
9227
  });
9224
9228
  types_1.FunctionType.addDefaultParameters(newType);
9225
9229
  newType.details.declaredReturnType = types_1.ClassType.cloneAsInstance(classType);
9226
- newType.details.constructorTypeVarScopeId = classType.details.typeVarScopeId;
9230
+ newType.details.constructorTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(classType);
9227
9231
  types_1.ClassType.getSymbolTable(classType).set('__new__', symbol_1.Symbol.createWithType(4 /* SymbolFlags.ClassMember */, newType));
9228
9232
  }
9229
9233
  return classType;
@@ -9245,7 +9249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
9245
9249
  if (!(0, types_1.isClassInstance)(arg1Type) || !(0, typeUtils_1.isTupleClass)(arg1Type) || arg1Type.tupleTypeArguments === undefined) {
9246
9250
  return undefined;
9247
9251
  }
9248
- const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 1073741824 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, arg1Type.details.effectiveMetaclass);
9252
+ const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.fileUri, 4194304 /* ClassTypeFlags.ValidTypeAliasClass */, ParseTreeUtils.getTypeSourceId(errorNode), metaclass, arg1Type.details.effectiveMetaclass);
9249
9253
  arg1Type.tupleTypeArguments.forEach((typeArg) => {
9250
9254
  const specializedType = makeTopLevelTypeVarsConcrete(typeArg.type);
9251
9255
  if ((0, typeUtils_1.isEffectivelyInstantiable)(specializedType)) {
@@ -10058,128 +10062,134 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10058
10062
  }
10059
10063
  let functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* FunctionTypeFlags.PartiallyEvaluated */);
10060
10064
  functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
10061
- // Pre-cache the incomplete function type in case the evaluation of the
10062
- // lambda depends on itself.
10063
- writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvaluatorFlags.None */);
10064
- // We assume for simplicity that the parameter signature of the lambda is
10065
- // the same as the expected type. If this isn't the case, we'll use
10066
- // object for any lambda parameters that don't match. We could make this
10067
- // more sophisticated in the future, but it becomes very complex to handle
10068
- // all of the permutations.
10069
- let sawParamMismatch = false;
10070
- node.parameters.forEach((param, index) => {
10071
- let paramType;
10072
- if (expectedParamDetails && !sawParamMismatch) {
10073
- if (index < expectedParamDetails.params.length) {
10074
- const expectedParam = expectedParamDetails.params[index];
10075
- // If the parameter category matches and both of the parameters are
10076
- // either separators (/ or *) or not separators, copy the type
10077
- // from the expected parameter.
10078
- if (expectedParam.param.category === param.category && !param.name === !expectedParam.param.name) {
10079
- paramType = expectedParam.type;
10065
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
10066
+ // Pre-cache the incomplete function type in case the evaluation of the
10067
+ // lambda depends on itself.
10068
+ writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* EvaluatorFlags.None */);
10069
+ // We assume for simplicity that the parameter signature of the lambda is
10070
+ // the same as the expected type. If this isn't the case, we'll use
10071
+ // object for any lambda parameters that don't match. We could make this
10072
+ // more sophisticated in the future, but it becomes very complex to handle
10073
+ // all of the permutations.
10074
+ let sawParamMismatch = false;
10075
+ node.parameters.forEach((param, index) => {
10076
+ let paramType;
10077
+ if (expectedParamDetails && !sawParamMismatch) {
10078
+ if (index < expectedParamDetails.params.length) {
10079
+ const expectedParam = expectedParamDetails.params[index];
10080
+ // If the parameter category matches and both of the parameters are
10081
+ // either separators (/ or *) or not separators, copy the type
10082
+ // from the expected parameter.
10083
+ if (expectedParam.param.category === param.category &&
10084
+ !param.name === !expectedParam.param.name) {
10085
+ paramType = expectedParam.type;
10086
+ }
10087
+ else {
10088
+ sawParamMismatch = true;
10089
+ }
10080
10090
  }
10081
- else {
10082
- sawParamMismatch = true;
10091
+ else if (param.defaultValue) {
10092
+ // If the lambda param has a default value but there is no associated
10093
+ // parameter in the expected type, assume that the default value is
10094
+ // being used to explicitly capture a value from an outer scope. Infer
10095
+ // its type from the default value expression.
10096
+ paramType = getTypeOfExpression(param.defaultValue, undefined, inferenceContext).type;
10083
10097
  }
10084
10098
  }
10085
10099
  else if (param.defaultValue) {
10086
- // If the lambda param has a default value but there is no associated
10087
- // parameter in the expected type, assume that the default value is
10088
- // being used to explicitly capture a value from an outer scope. Infer
10089
- // its type from the default value expression.
10090
- paramType = getTypeOfExpression(param.defaultValue, undefined, inferenceContext).type;
10091
- }
10092
- }
10093
- else if (param.defaultValue) {
10094
- // If there is no inference context but we have a default value,
10095
- // use the default value to infer the parameter's type.
10096
- paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
10097
- }
10098
- if (param.name) {
10099
- writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvaluatorFlags.None */);
10100
- }
10101
- if (param.defaultValue) {
10102
- // Evaluate the default value if it's present.
10103
- getTypeOfExpression(param.defaultValue, 1 /* EvaluatorFlags.ConvertEllipsisToAny */);
10104
- }
10105
- // Determine whether we need to insert an implied position-only parameter.
10106
- // This is needed when a function's parameters are named using the old-style
10107
- // way of specifying position-only parameters.
10108
- if (index >= 0) {
10109
- let isImplicitPositionOnlyParam = false;
10110
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
10111
- if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)) {
10112
- isImplicitPositionOnlyParam = true;
10100
+ // If there is no inference context but we have a default value,
10101
+ // use the default value to infer the parameter's type.
10102
+ paramType = inferParameterTypeFromDefaultValue(param.defaultValue);
10103
+ }
10104
+ if (param.name) {
10105
+ writeTypeCache(param.name, { type: transformVariadicParamType(node, param.category, paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create()) }, 0 /* EvaluatorFlags.None */);
10106
+ }
10107
+ if (param.defaultValue) {
10108
+ // Evaluate the default value if it's present.
10109
+ getTypeOfExpression(param.defaultValue, 1 /* EvaluatorFlags.ConvertEllipsisToAny */);
10110
+ }
10111
+ // Determine whether we need to insert an implied position-only parameter.
10112
+ // This is needed when a function's parameters are named using the old-style
10113
+ // way of specifying position-only parameters.
10114
+ if (index >= 0) {
10115
+ let isImplicitPositionOnlyParam = false;
10116
+ if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
10117
+ if ((0, symbolNameUtils_1.isPrivateName)(param.name.value)) {
10118
+ isImplicitPositionOnlyParam = true;
10119
+ }
10120
+ }
10121
+ else {
10122
+ paramsArePositionOnly = false;
10123
+ }
10124
+ if (paramsArePositionOnly &&
10125
+ !isImplicitPositionOnlyParam &&
10126
+ functionType.details.parameters.length > 0) {
10127
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10128
+ }
10129
+ if (!isImplicitPositionOnlyParam) {
10130
+ paramsArePositionOnly = false;
10113
10131
  }
10114
10132
  }
10115
- else {
10116
- paramsArePositionOnly = false;
10117
- }
10118
- if (paramsArePositionOnly &&
10119
- !isImplicitPositionOnlyParam &&
10120
- functionType.details.parameters.length > 0) {
10121
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10133
+ const functionParam = {
10134
+ category: param.category,
10135
+ name: param.name ? param.name.value : undefined,
10136
+ hasDefault: !!param.defaultValue,
10137
+ defaultValueExpression: param.defaultValue,
10138
+ hasDeclaredType: true,
10139
+ type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
10140
+ };
10141
+ types_1.FunctionType.addParameter(functionType, functionParam);
10142
+ });
10143
+ if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
10144
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10145
+ }
10146
+ let typeErrors = false;
10147
+ // If we're speculatively evaluating the lambda, create another speculative
10148
+ // evaluation scope for the return expression and do not allow retention
10149
+ // of the cached types.
10150
+ // We need to set allowCacheRetention to false because we don't want to
10151
+ // cache the type of the lambda return expression because it depends on
10152
+ // the parameter types that we set above, and the speculative type cache
10153
+ // doesn't know about that context.
10154
+ useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
10155
+ ? node.expression
10156
+ : undefined, () => {
10157
+ const returnTypeResult = getTypeOfExpression(node.expression,
10158
+ /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10159
+ functionType.inferredReturnType = returnTypeResult.type;
10160
+ if (returnTypeResult.isIncomplete) {
10161
+ isIncomplete = true;
10122
10162
  }
10123
- if (!isImplicitPositionOnlyParam) {
10124
- paramsArePositionOnly = false;
10163
+ if (returnTypeResult.typeErrors) {
10164
+ typeErrors = true;
10125
10165
  }
10126
- }
10127
- const functionParam = {
10128
- category: param.category,
10129
- name: param.name ? param.name.value : undefined,
10130
- hasDefault: !!param.defaultValue,
10131
- defaultValueExpression: param.defaultValue,
10132
- hasDeclaredType: true,
10133
- type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
10134
- };
10135
- types_1.FunctionType.addParameter(functionType, functionParam);
10136
- });
10137
- if (paramsArePositionOnly && functionType.details.parameters.length > 0) {
10138
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
10139
- }
10140
- let typeErrors = false;
10141
- // If we're speculatively evaluating the lambda, create another speculative
10142
- // evaluation scope for the return expression and do not allow retention
10143
- // of the cached types.
10144
- // We need to set allowCacheRetention to false because we don't want to
10145
- // cache the type of the lambda return expression because it depends on
10146
- // the parameter types that we set above, and the speculative type cache
10147
- // doesn't know about that context.
10148
- useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
10149
- ? node.expression
10150
- : undefined, () => {
10151
- const returnTypeResult = getTypeOfExpression(node.expression,
10152
- /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
10153
- functionType.inferredReturnType = returnTypeResult.type;
10154
- if (returnTypeResult.isIncomplete) {
10155
- isIncomplete = true;
10156
- }
10157
- if (returnTypeResult.typeErrors) {
10158
- typeErrors = true;
10159
- }
10160
- else if (expectedReturnType) {
10161
- // If the expectedReturnType is generic, see if the actual return type
10162
- // provides types for some or all type variables.
10163
- if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10164
- const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10165
- if (assignType(expectedReturnType, returnTypeResult.type, /* diag */ undefined, typeVarContext)) {
10166
- functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10167
- applyInScopePlaceholders: true,
10168
- });
10166
+ else if (expectedReturnType) {
10167
+ // If the expectedReturnType is generic, see if the actual return type
10168
+ // provides types for some or all type variables.
10169
+ if ((0, typeUtils_1.requiresSpecialization)(expectedReturnType)) {
10170
+ const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(functionType));
10171
+ if (assignType(expectedReturnType, returnTypeResult.type,
10172
+ /* diag */ undefined, typeVarContext)) {
10173
+ functionType = (0, typeUtils_1.applySolvedTypeVars)(functionType, typeVarContext, {
10174
+ applyInScopePlaceholders: true,
10175
+ });
10176
+ }
10169
10177
  }
10170
10178
  }
10179
+ }, {
10180
+ dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
10181
+ allowDiagnostics: !forceSpeculative &&
10182
+ !isDiagnosticSuppressedForNode(node) &&
10183
+ !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
10184
+ });
10185
+ // Mark the function type as no longer being evaluated.
10186
+ functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
10187
+ // Is the resulting function compatible with the expected type?
10188
+ if (expectedType && !assignType(expectedType, functionType)) {
10189
+ typeErrors = true;
10171
10190
  }
10172
- }, {
10173
- dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
10174
- allowDiagnostics: !forceSpeculative && !isDiagnosticSuppressedForNode(node) && !(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete),
10191
+ return { type: functionType, isIncomplete, typeErrors };
10175
10192
  });
10176
- // Mark the function type as no longer being evaluated.
10177
- functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
10178
- // Is the resulting function compatible with the expected type?
10179
- if (expectedType && !assignType(expectedType, functionType)) {
10180
- typeErrors = true;
10181
- }
10182
- return { type: functionType, isIncomplete, typeErrors };
10183
10193
  }
10184
10194
  function getTypeOfComprehension(node, flags, inferenceContext) {
10185
10195
  let isIncomplete = false;
@@ -11256,7 +11266,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11256
11266
  /* declaredMetaclass */ undefined,
11257
11267
  /* effectiveMetaclass */ undefined);
11258
11268
  if (aliasMapEntry.isSpecialForm) {
11259
- specialClassType.details.flags |= -2147483648 /* ClassTypeFlags.SpecialFormClass */;
11269
+ specialClassType.details.flags |= 8388608 /* ClassTypeFlags.SpecialFormClass */;
11260
11270
  }
11261
11271
  // Synthesize a single type parameter with the specified variance if
11262
11272
  // specified in the alias map entry.
@@ -11269,7 +11279,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11269
11279
  const specialBuiltInClassDeclaration = ((_a = AnalyzerNodeInfo.getDeclaration(node)) !== null && _a !== void 0 ? _a : (node.parent ? AnalyzerNodeInfo.getDeclaration(node.parent) : undefined));
11270
11280
  specialClassType.details.declaration = specialBuiltInClassDeclaration;
11271
11281
  if (fileInfo.isTypingExtensionsStubFile) {
11272
- specialClassType.details.flags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
11282
+ specialClassType.details.flags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
11273
11283
  }
11274
11284
  const baseClassName = aliasMapEntry.alias || 'object';
11275
11285
  let baseClass;
@@ -11289,7 +11299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11289
11299
  // cause the TypedDict to be marked as abstract.
11290
11300
  if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, '_TypedDict')) {
11291
11301
  baseClass = types_1.ClassType.cloneWithNewFlags(baseClass, baseClass.details.flags &
11292
- ~(2048 /* ClassTypeFlags.SupportsAbstractMethods */ | 268435456 /* ClassTypeFlags.TypeCheckOnly */));
11302
+ ~(64 /* ClassTypeFlags.SupportsAbstractMethods */ | 1048576 /* ClassTypeFlags.TypeCheckOnly */));
11293
11303
  }
11294
11304
  }
11295
11305
  }
@@ -11664,17 +11674,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11664
11674
  fileInfo.isTypeshedStubFile) {
11665
11675
  classFlags |= 1 /* ClassTypeFlags.BuiltInClass */;
11666
11676
  if (fileInfo.isTypingExtensionsStubFile) {
11667
- classFlags |= 131072 /* ClassTypeFlags.TypingExtensionClass */;
11677
+ classFlags |= 4096 /* ClassTypeFlags.TypingExtensionClass */;
11668
11678
  }
11669
11679
  if (node.name.value === 'property') {
11670
- classFlags |= 4096 /* ClassTypeFlags.PropertyClass */;
11680
+ classFlags |= 128 /* ClassTypeFlags.PropertyClass */;
11671
11681
  }
11672
11682
  if (node.name.value === 'tuple') {
11673
- classFlags |= 1048576 /* ClassTypeFlags.TupleClass */;
11683
+ classFlags |= 32768 /* ClassTypeFlags.TupleClass */;
11674
11684
  }
11675
11685
  }
11676
11686
  if (fileInfo.isStubFile) {
11677
- classFlags |= 16777216 /* ClassTypeFlags.DefinedInStub */;
11687
+ classFlags |= 262144 /* ClassTypeFlags.DefinedInStub */;
11678
11688
  }
11679
11689
  const classType = types_1.ClassType.createInstantiable(node.name.value, ParseTreeUtils.getClassFullName(node, fileInfo.moduleName, node.name.value), fileInfo.moduleName, fileInfo.fileUri, classFlags,
11680
11690
  /* typeSourceId */ 0,
@@ -11697,9 +11707,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11697
11707
  if (classDecl && classSymbol) {
11698
11708
  setSymbolResolutionPartialType(classSymbol, classDecl, classType);
11699
11709
  }
11700
- classType.details.flags |= 262144 /* ClassTypeFlags.PartiallyEvaluated */;
11710
+ classType.details.flags |= 8192 /* ClassTypeFlags.PartiallyEvaluated */;
11701
11711
  classType.details.declaration = classDecl;
11702
- try {
11712
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
11703
11713
  writeTypeCache(node, { type: classType }, /* flags */ undefined);
11704
11714
  writeTypeCache(node.name, { type: classType }, /* flags */ undefined);
11705
11715
  // Keep a list of unique type parameters that are used in the
@@ -11783,29 +11793,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11783
11793
  fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_7)) {
11784
11794
  addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
11785
11795
  }
11786
- classType.details.flags |= 16384 /* ClassTypeFlags.ProtocolClass */;
11796
+ classType.details.flags |= 512 /* ClassTypeFlags.ProtocolClass */;
11787
11797
  }
11788
11798
  if (types_1.ClassType.isBuiltIn(argType, 'property')) {
11789
- classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
11799
+ classType.details.flags |= 128 /* ClassTypeFlags.PropertyClass */;
11790
11800
  }
11791
11801
  // If the class directly derives from NamedTuple (in Python 3.6 or
11792
11802
  // newer), it's considered a (read-only) dataclass.
11793
11803
  if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
11794
11804
  if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
11795
11805
  isNamedTupleSubclass = true;
11796
- classType.details.flags |=
11797
- 4 /* ClassTypeFlags.DataClass */ |
11798
- 32 /* ClassTypeFlags.SkipSynthesizedDataClassEq */ |
11799
- 33554432 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
11806
+ classType.details.flags |= 524288 /* ClassTypeFlags.ReadOnlyInstanceVariables */;
11800
11807
  }
11801
11808
  }
11802
11809
  // If the class directly derives from TypedDict or from a class that is
11803
11810
  // a TypedDict, it is considered a TypedDict.
11804
11811
  if (types_1.ClassType.isBuiltIn(argType, 'TypedDict') || types_1.ClassType.isTypedDictClass(argType)) {
11805
- classType.details.flags |= 128 /* ClassTypeFlags.TypedDictClass */;
11812
+ classType.details.flags |= 4 /* ClassTypeFlags.TypedDictClass */;
11806
11813
  // Propagate the "effectively closed" flag from base classes.
11807
11814
  if (types_1.ClassType.isTypedDictEffectivelyClosed(argType)) {
11808
- classType.details.flags |= 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11815
+ classType.details.flags |= 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11809
11816
  }
11810
11817
  }
11811
11818
  // Validate that the class isn't deriving from itself, creating a
@@ -11836,7 +11843,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11836
11843
  classType.details.baseClasses.push(argType);
11837
11844
  if ((0, types_1.isInstantiableClass)(argType)) {
11838
11845
  if (types_1.ClassType.isEnumClass(argType)) {
11839
- classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
11846
+ classType.details.flags |= 65536 /* ClassTypeFlags.EnumClass */;
11840
11847
  }
11841
11848
  // Determine if the class is abstract. Protocol classes support abstract methods
11842
11849
  // because they are constructed by the _ProtocolMeta metaclass, which derives
@@ -11845,10 +11852,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11845
11852
  // because of dependencies on some of these built-in protocol classes.
11846
11853
  if (types_1.ClassType.supportsAbstractMethods(argType) ||
11847
11854
  (types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
11848
- classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
11855
+ classType.details.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
11849
11856
  }
11850
11857
  if (types_1.ClassType.isPropertyClass(argType)) {
11851
- classType.details.flags |= 4096 /* ClassTypeFlags.PropertyClass */;
11858
+ classType.details.flags |= 128 /* ClassTypeFlags.PropertyClass */;
11852
11859
  }
11853
11860
  if (types_1.ClassType.isFinal(argType)) {
11854
11861
  const className = printObjectTypeForClass(argType);
@@ -11898,13 +11905,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11898
11905
  addError(localize_1.LocMessage.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
11899
11906
  }
11900
11907
  else if (arg.name.value === 'total' && !constArgValue) {
11901
- classType.details.flags |= 1024 /* ClassTypeFlags.CanOmitDictValues */;
11908
+ classType.details.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
11902
11909
  }
11903
11910
  else if (arg.name.value === 'closed' && constArgValue) {
11904
11911
  // This is an experimental feature because PEP 728 hasn't been accepted yet.
11905
11912
  if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
11906
11913
  classType.details.flags |=
11907
- 256 /* ClassTypeFlags.TypedDictMarkedClosed */ | 512 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11914
+ 8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
11908
11915
  }
11909
11916
  }
11910
11917
  }
@@ -12037,7 +12044,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12037
12044
  param.category === 0 /* ParameterCategory.Simple */ &&
12038
12045
  !param.defaultValue);
12039
12046
  if (genericParams.length > 0) {
12040
- classType.details.flags |= 32768 /* ClassTypeFlags.PseudoGenericClass */;
12047
+ classType.details.flags |= 1024 /* ClassTypeFlags.PseudoGenericClass */;
12041
12048
  // Create a type parameter for each simple, named parameter
12042
12049
  // in the __init__ method.
12043
12050
  classType.details.typeParameters = genericParams.map((param) => {
@@ -12058,7 +12065,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12058
12065
  if (classType.details.typeParameters.length === 0 && !types_1.ClassType.isBuiltIn(classType, 'type')) {
12059
12066
  if (classType.details.baseClasses.some((baseClass) => (0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.hasCustomClassGetItem(baseClass)) ||
12060
12067
  classType.details.fields.has('__class_getitem__')) {
12061
- classType.details.flags |= 524288 /* ClassTypeFlags.HasCustomClassGetItem */;
12068
+ classType.details.flags |= 16384 /* ClassTypeFlags.HasCustomClassGetItem */;
12062
12069
  }
12063
12070
  }
12064
12071
  // Determine the effective metaclass.
@@ -12071,17 +12078,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12071
12078
  classType.details.declaredMetaclass = metaclassType;
12072
12079
  if ((0, types_1.isInstantiableClass)(metaclassType)) {
12073
12080
  if ((0, enums_1.isEnumMetaclass)(metaclassType)) {
12074
- classType.details.flags |= 2097152 /* ClassTypeFlags.EnumClass */;
12081
+ classType.details.flags |= 65536 /* ClassTypeFlags.EnumClass */;
12075
12082
  }
12076
12083
  if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
12077
- classType.details.flags |= 2048 /* ClassTypeFlags.SupportsAbstractMethods */;
12084
+ classType.details.flags |= 64 /* ClassTypeFlags.SupportsAbstractMethods */;
12078
12085
  }
12079
12086
  }
12080
12087
  }
12081
12088
  }
12082
12089
  const effectiveMetaclass = computeEffectiveMetaclass(classType, node.name);
12083
12090
  // Clear the "partially constructed" flag.
12084
- classType.details.flags &= ~262144 /* ClassTypeFlags.PartiallyEvaluated */;
12091
+ classType.details.flags &= ~8192 /* ClassTypeFlags.PartiallyEvaluated */;
12085
12092
  // Now determine the decorated type of the class.
12086
12093
  let decoratedType = classType;
12087
12094
  let foundUnknown = false;
@@ -12118,7 +12125,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12118
12125
  }
12119
12126
  }
12120
12127
  if (dataClassBehaviors) {
12121
- (0, dataClasses_1.applyDataClassDefaultBehaviors)(classType, dataClassBehaviors);
12122
12128
  (0, dataClasses_1.applyDataClassClassBehaviorOverrides)(evaluatorInterface, node.name, classType, initSubclassArgs, dataClassBehaviors);
12123
12129
  }
12124
12130
  // Run any deferred class completions that depend on this class.
@@ -12146,8 +12152,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12146
12152
  (0, typedDicts_1.synthesizeTypedDictClassMethods)(evaluatorInterface, node, classType);
12147
12153
  }
12148
12154
  // Synthesize dataclass methods.
12149
- if (types_1.ClassType.isDataClass(classType)) {
12150
- const skipSynthesizedInit = types_1.ClassType.isSkipSynthesizedDataClassInit(classType);
12155
+ if (types_1.ClassType.isDataClass(classType) || isNamedTupleSubclass) {
12156
+ const skipSynthesizedInit = types_1.ClassType.isDataClassSkipGenerateInit(classType);
12151
12157
  let hasExistingInitMethod = skipSynthesizedInit;
12152
12158
  // See if there's already a non-synthesized __init__ method.
12153
12159
  // We shouldn't override it.
@@ -12213,15 +12219,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12213
12219
  // Update the decorated class type.
12214
12220
  writeTypeCache(node, { type: decoratedType }, 0 /* EvaluatorFlags.None */);
12215
12221
  return { classType, decoratedType };
12216
- }
12217
- catch (e) {
12218
- if (cancellationUtils_1.OperationCanceledException.is(e)) {
12219
- // If the work was canceled before the class types were updated, the
12220
- // class type in the type cache is in an invalid, partially-constructed state.
12221
- e.isTypeCacheInvalid = true;
12222
- }
12223
- throw e;
12224
- }
12222
+ });
12225
12223
  }
12226
12224
  // Determines whether the type parameters has a default that refers to another
12227
12225
  // type parameter. If so, validates that it is in the list of "live" type
@@ -12637,7 +12635,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12637
12635
  // Evaluates the type of a "def" statement without applying an async
12638
12636
  // modifier or any decorators.
12639
12637
  function getTypeOfFunctionPredecorated(node) {
12640
- var _a, _b, _c;
12638
+ var _a;
12641
12639
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
12642
12640
  // Is this type already cached?
12643
12641
  const cachedFunctionType = readTypeCache(node.name, 0 /* EvaluatorFlags.None */);
@@ -12692,299 +12690,303 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12692
12690
  if (functionDecl && functionSymbol) {
12693
12691
  setSymbolResolutionPartialType(functionSymbol.symbol, functionDecl, functionType);
12694
12692
  }
12695
- writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
12696
- // Is this an "__init__" method within a pseudo-generic class? If so,
12697
- // we'll add generic types to the constructor's parameters.
12698
- const addGenericParamTypes = containingClassType &&
12699
- types_1.ClassType.isPseudoGenericClass(containingClassType) &&
12700
- node.name.value === '__init__';
12701
- const paramTypes = [];
12702
- // Determine if the first parameter should be skipped for comment-based
12703
- // function annotations.
12704
- let firstCommentAnnotationIndex = 0;
12705
- if (containingClassType && (functionType.details.flags & 4 /* FunctionTypeFlags.StaticMethod */) === 0) {
12706
- firstCommentAnnotationIndex = 1;
12707
- }
12708
- // If there is a function annotation comment, validate that it has the correct
12709
- // number of parameter annotations.
12710
- if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12711
- const expected = node.parameters.length - firstCommentAnnotationIndex;
12712
- const received = node.functionAnnotationComment.paramTypeAnnotations.length;
12713
- // For methods with "self" or "cls" parameters, the annotation list
12714
- // can either include or exclude the annotation for the first parameter.
12715
- if (firstCommentAnnotationIndex > 0 && received === node.parameters.length) {
12716
- firstCommentAnnotationIndex = 0;
12717
- }
12718
- else if (received !== expected) {
12719
- addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
12720
- expected,
12721
- received,
12722
- }), node.functionAnnotationComment);
12723
- }
12724
- }
12725
- // If this function uses PEP 695 syntax for type parameters,
12726
- // accumulate the list of type parameters upfront.
12727
- const typeParametersSeen = [];
12728
- if (node.typeParameters) {
12729
- functionType.details.typeParameters = evaluateTypeParameterList(node.typeParameters).map((typeParam) => (0, typeUtils_1.convertToInstance)(typeParam));
12730
- }
12731
- else {
12732
- functionType.details.typeParameters = typeParametersSeen;
12733
- }
12734
- let paramsArePositionOnly = true;
12735
- const isFirstParamClsOrSelf = containingClassType &&
12736
- (types_1.FunctionType.isClassMethod(functionType) ||
12737
- types_1.FunctionType.isInstanceMethod(functionType) ||
12738
- types_1.FunctionType.isConstructorMethod(functionType));
12739
- const firstNonClsSelfParamIndex = isFirstParamClsOrSelf ? 1 : 0;
12740
- node.parameters.forEach((param, index) => {
12741
- let paramType;
12742
- let annotatedType;
12743
- let paramTypeNode;
12744
- if (param.name) {
12745
- if (index === 0 && isFirstParamClsOrSelf) {
12746
- // Mark "self/cls" as accessed.
12747
- markParamAccessed(param);
12748
- }
12749
- else if (types_1.FunctionType.isAbstractMethod(functionType)) {
12750
- // Mark all parameters in abstract methods as accessed.
12751
- markParamAccessed(param);
12752
- }
12753
- else if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12754
- // Mark all parameters in protocol methods as accessed.
12755
- markParamAccessed(param);
12756
- }
12757
- }
12758
- if (param.typeAnnotation) {
12759
- paramTypeNode = param.typeAnnotation;
12760
- }
12761
- else if (param.typeAnnotationComment) {
12762
- paramTypeNode = param.typeAnnotationComment;
12693
+ return (0, cancellationUtils_1.invalidateTypeCacheIfCanceled)(() => {
12694
+ var _a, _b;
12695
+ writeTypeCache(node.name, { type: functionType }, /* flags */ undefined);
12696
+ // Is this an "__init__" method within a pseudo-generic class? If so,
12697
+ // we'll add generic types to the constructor's parameters.
12698
+ const addGenericParamTypes = containingClassType &&
12699
+ types_1.ClassType.isPseudoGenericClass(containingClassType) &&
12700
+ node.name.value === '__init__';
12701
+ const paramTypes = [];
12702
+ // Determine if the first parameter should be skipped for comment-based
12703
+ // function annotations.
12704
+ let firstCommentAnnotationIndex = 0;
12705
+ if (containingClassType && (functionType.details.flags & 4 /* FunctionTypeFlags.StaticMethod */) === 0) {
12706
+ firstCommentAnnotationIndex = 1;
12707
+ }
12708
+ // If there is a function annotation comment, validate that it has the correct
12709
+ // number of parameter annotations.
12710
+ if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12711
+ const expected = node.parameters.length - firstCommentAnnotationIndex;
12712
+ const received = node.functionAnnotationComment.paramTypeAnnotations.length;
12713
+ // For methods with "self" or "cls" parameters, the annotation list
12714
+ // can either include or exclude the annotation for the first parameter.
12715
+ if (firstCommentAnnotationIndex > 0 && received === node.parameters.length) {
12716
+ firstCommentAnnotationIndex = 0;
12717
+ }
12718
+ else if (received !== expected) {
12719
+ addError(localize_1.LocMessage.annotatedParamCountMismatch().format({
12720
+ expected,
12721
+ received,
12722
+ }), node.functionAnnotationComment);
12723
+ }
12724
+ }
12725
+ // If this function uses PEP 695 syntax for type parameters,
12726
+ // accumulate the list of type parameters upfront.
12727
+ const typeParametersSeen = [];
12728
+ if (node.typeParameters) {
12729
+ functionType.details.typeParameters = evaluateTypeParameterList(node.typeParameters).map((typeParam) => (0, typeUtils_1.convertToInstance)(typeParam));
12763
12730
  }
12764
- else if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12765
- const adjustedIndex = index - firstCommentAnnotationIndex;
12766
- if (adjustedIndex >= 0 && adjustedIndex < node.functionAnnotationComment.paramTypeAnnotations.length) {
12767
- paramTypeNode = node.functionAnnotationComment.paramTypeAnnotations[adjustedIndex];
12768
- }
12731
+ else {
12732
+ functionType.details.typeParameters = typeParametersSeen;
12769
12733
  }
12770
- if (paramTypeNode) {
12771
- if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
12772
- annotatedType = types_1.UnknownType.create();
12734
+ let paramsArePositionOnly = true;
12735
+ const isFirstParamClsOrSelf = containingClassType &&
12736
+ (types_1.FunctionType.isClassMethod(functionType) ||
12737
+ types_1.FunctionType.isInstanceMethod(functionType) ||
12738
+ types_1.FunctionType.isConstructorMethod(functionType));
12739
+ const firstNonClsSelfParamIndex = isFirstParamClsOrSelf ? 1 : 0;
12740
+ node.parameters.forEach((param, index) => {
12741
+ let paramType;
12742
+ let annotatedType;
12743
+ let paramTypeNode;
12744
+ if (param.name) {
12745
+ if (index === 0 && isFirstParamClsOrSelf) {
12746
+ // Mark "self/cls" as accessed.
12747
+ markParamAccessed(param);
12748
+ }
12749
+ else if (types_1.FunctionType.isAbstractMethod(functionType)) {
12750
+ // Mark all parameters in abstract methods as accessed.
12751
+ markParamAccessed(param);
12752
+ }
12753
+ else if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12754
+ // Mark all parameters in protocol methods as accessed.
12755
+ markParamAccessed(param);
12756
+ }
12773
12757
  }
12774
- else {
12775
- annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
12758
+ if (param.typeAnnotation) {
12759
+ paramTypeNode = param.typeAnnotation;
12776
12760
  }
12777
- if (annotatedType) {
12778
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
12761
+ else if (param.typeAnnotationComment) {
12762
+ paramTypeNode = param.typeAnnotationComment;
12779
12763
  }
12780
- if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
12781
- addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12782
- name1: annotatedType.details.name,
12783
- name2: annotatedType.details.name,
12784
- }), paramTypeNode);
12785
- annotatedType = types_1.UnknownType.create();
12764
+ else if (node.functionAnnotationComment && !node.functionAnnotationComment.isParamListEllipsis) {
12765
+ const adjustedIndex = index - firstCommentAnnotationIndex;
12766
+ if (adjustedIndex >= 0 &&
12767
+ adjustedIndex < node.functionAnnotationComment.paramTypeAnnotations.length) {
12768
+ paramTypeNode = node.functionAnnotationComment.paramTypeAnnotations[adjustedIndex];
12769
+ }
12786
12770
  }
12787
- }
12788
- if (!annotatedType && addGenericParamTypes) {
12789
- if (index > 0 && param.category === 0 /* ParameterCategory.Simple */ && param.name && !param.defaultValue) {
12790
- const typeParamName = getPseudoGenericTypeVarName(param.name.value);
12791
- annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
12771
+ if (paramTypeNode) {
12772
+ if ((functionInfo.flags & 524288 /* FunctionTypeFlags.NoTypeCheck */) !== 0) {
12773
+ annotatedType = types_1.UnknownType.create();
12774
+ }
12775
+ else {
12776
+ annotatedType = getTypeOfParameterAnnotation(paramTypeNode, param.category);
12777
+ }
12778
+ if (annotatedType) {
12779
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(annotatedType), functionType.details.typeVarScopeId);
12780
+ }
12781
+ if ((0, types_1.isVariadicTypeVar)(annotatedType) && !annotatedType.isVariadicUnpacked) {
12782
+ addError(localize_1.LocMessage.unpackedTypeVarTupleExpected().format({
12783
+ name1: annotatedType.details.name,
12784
+ name2: annotatedType.details.name,
12785
+ }), paramTypeNode);
12786
+ annotatedType = types_1.UnknownType.create();
12787
+ }
12792
12788
  }
12793
- }
12794
- if (annotatedType) {
12795
- const adjustedAnnotatedType = adjustParameterAnnotatedType(param, annotatedType);
12796
- if (adjustedAnnotatedType !== annotatedType) {
12797
- annotatedType = adjustedAnnotatedType;
12789
+ if (!annotatedType && addGenericParamTypes) {
12790
+ if (index > 0 && param.category === 0 /* ParameterCategory.Simple */ && param.name && !param.defaultValue) {
12791
+ const typeParamName = getPseudoGenericTypeVarName(param.name.value);
12792
+ annotatedType = containingClassType.details.typeParameters.find((param) => param.details.name === typeParamName);
12793
+ }
12798
12794
  }
12799
- }
12800
- let defaultValueType;
12801
- if (param.defaultValue) {
12802
- // If this is a stub file, a protocol, an overload, or a class
12803
- // whose body is a placeholder implementation, treat a "...", as
12804
- // an "Any" value.
12805
- let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12806
- if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12807
- treatEllipsisAsAny = true;
12795
+ if (annotatedType) {
12796
+ const adjustedAnnotatedType = adjustParameterAnnotatedType(param, annotatedType);
12797
+ if (adjustedAnnotatedType !== annotatedType) {
12798
+ annotatedType = adjustedAnnotatedType;
12799
+ }
12808
12800
  }
12809
- if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12810
- treatEllipsisAsAny = true;
12801
+ let defaultValueType;
12802
+ if (param.defaultValue) {
12803
+ // If this is a stub file, a protocol, an overload, or a class
12804
+ // whose body is a placeholder implementation, treat a "...", as
12805
+ // an "Any" value.
12806
+ let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12807
+ if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12808
+ treatEllipsisAsAny = true;
12809
+ }
12810
+ if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12811
+ treatEllipsisAsAny = true;
12812
+ }
12813
+ defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvaluatorFlags.ConvertEllipsisToAny */ : 0 /* EvaluatorFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12811
12814
  }
12812
- defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* EvaluatorFlags.ConvertEllipsisToAny */ : 0 /* EvaluatorFlags.None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12813
- }
12814
- if (annotatedType) {
12815
- // If there was both a type annotation and a default value, verify
12816
- // that the default value matches the annotation.
12817
- if (param.defaultValue && defaultValueType) {
12818
- const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12819
- const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.details.typeVarScopeId);
12820
- if (containingClassType && containingClassType.details.typeVarScopeId !== undefined) {
12821
- if (node.name.value === '__init__' || node.name.value === '__new__') {
12822
- typeVarContext.addSolveForScope(containingClassType.details.typeVarScopeId);
12815
+ if (annotatedType) {
12816
+ // If there was both a type annotation and a default value, verify
12817
+ // that the default value matches the annotation.
12818
+ if (param.defaultValue && defaultValueType) {
12819
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12820
+ const typeVarContext = new typeVarContext_1.TypeVarContext(functionType.details.typeVarScopeId);
12821
+ if (containingClassType && containingClassType.details.typeVarScopeId !== undefined) {
12822
+ if (node.name.value === '__init__' || node.name.value === '__new__') {
12823
+ typeVarContext.addSolveForScope(containingClassType.details.typeVarScopeId);
12824
+ }
12825
+ }
12826
+ if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12827
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12828
+ sourceType: printType(defaultValueType),
12829
+ paramType: printType(annotatedType),
12830
+ }) + diagAddendum.getString(), param.defaultValue);
12823
12831
  }
12824
12832
  }
12825
- if (!assignType(annotatedType, defaultValueType, diagAddendum, typeVarContext)) {
12826
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportArgumentType, localize_1.LocMessage.paramAssignmentMismatch().format({
12827
- sourceType: printType(defaultValueType),
12828
- paramType: printType(annotatedType),
12829
- }) + diagAddendum.getString(), param.defaultValue);
12830
- }
12831
- }
12832
- paramType = annotatedType;
12833
- }
12834
- // Determine whether we need to insert an implied position-only parameter.
12835
- // This is needed when a function's parameters are named using the old-style
12836
- // way of specifying position-only parameters.
12837
- if (index >= firstNonClsSelfParamIndex) {
12838
- let isImplicitPositionOnlyParam = false;
12839
- if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
12840
- if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
12841
- !node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
12842
- isImplicitPositionOnlyParam = true;
12843
- // If the parameter name indicates an implicit position-only parameter
12844
- // but we have already seen non-position-only parameters, report an error.
12845
- if (!paramsArePositionOnly &&
12846
- functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
12847
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
12833
+ paramType = annotatedType;
12834
+ }
12835
+ // Determine whether we need to insert an implied position-only parameter.
12836
+ // This is needed when a function's parameters are named using the old-style
12837
+ // way of specifying position-only parameters.
12838
+ if (index >= firstNonClsSelfParamIndex) {
12839
+ let isImplicitPositionOnlyParam = false;
12840
+ if (param.category === 0 /* ParameterCategory.Simple */ && param.name) {
12841
+ if ((0, symbolNameUtils_1.isPrivateName)(param.name.value) &&
12842
+ !node.parameters.some((p) => p.category === 0 /* ParameterCategory.Simple */ && !p.name)) {
12843
+ isImplicitPositionOnlyParam = true;
12844
+ // If the parameter name indicates an implicit position-only parameter
12845
+ // but we have already seen non-position-only parameters, report an error.
12846
+ if (!paramsArePositionOnly &&
12847
+ functionType.details.parameters.every((p) => p.category === 0 /* ParameterCategory.Simple */)) {
12848
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.positionOnlyAfterNon(), param.name);
12849
+ }
12848
12850
  }
12849
12851
  }
12852
+ else {
12853
+ paramsArePositionOnly = false;
12854
+ }
12855
+ if (paramsArePositionOnly &&
12856
+ !isImplicitPositionOnlyParam &&
12857
+ functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12858
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12859
+ }
12860
+ if (!isImplicitPositionOnlyParam) {
12861
+ paramsArePositionOnly = false;
12862
+ }
12863
+ }
12864
+ // If there was no annotation for the parameter, infer its type if possible.
12865
+ let isTypeInferred = false;
12866
+ if (!paramTypeNode) {
12867
+ isTypeInferred = true;
12868
+ const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
12869
+ if (inferredType) {
12870
+ paramType = inferredType;
12871
+ }
12872
+ }
12873
+ const functionParam = {
12874
+ category: param.category,
12875
+ name: param.name ? param.name.value : undefined,
12876
+ hasDefault: !!param.defaultValue,
12877
+ defaultValueExpression: param.defaultValue,
12878
+ defaultType: defaultValueType,
12879
+ type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
12880
+ typeAnnotation: paramTypeNode,
12881
+ hasDeclaredType: !!paramTypeNode,
12882
+ isTypeInferred,
12883
+ };
12884
+ types_1.FunctionType.addParameter(functionType, functionParam);
12885
+ if (functionParam.hasDeclaredType) {
12886
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
12887
+ }
12888
+ if (param.name) {
12889
+ const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
12890
+ paramTypes.push(variadicParamType);
12850
12891
  }
12851
12892
  else {
12852
- paramsArePositionOnly = false;
12893
+ paramTypes.push(functionParam.type);
12853
12894
  }
12854
- if (paramsArePositionOnly &&
12855
- !isImplicitPositionOnlyParam &&
12856
- functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12857
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12895
+ });
12896
+ if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12897
+ types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12898
+ }
12899
+ // Update the types for the nodes associated with the parameters.
12900
+ paramTypes.forEach((paramType, index) => {
12901
+ const paramNameNode = node.parameters[index].name;
12902
+ if (paramNameNode) {
12903
+ if ((0, types_1.isUnknown)(paramType)) {
12904
+ functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12905
+ }
12906
+ writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvaluatorFlags.None */);
12858
12907
  }
12859
- if (!isImplicitPositionOnlyParam) {
12860
- paramsArePositionOnly = false;
12861
- }
12862
- }
12863
- // If there was no annotation for the parameter, infer its type if possible.
12864
- let isTypeInferred = false;
12865
- if (!paramTypeNode) {
12866
- isTypeInferred = true;
12867
- const inferredType = inferParameterType(node, functionType.details.flags, index, containingClassType);
12868
- if (inferredType) {
12869
- paramType = inferredType;
12870
- }
12871
- }
12872
- const functionParam = {
12873
- category: param.category,
12874
- name: param.name ? param.name.value : undefined,
12875
- hasDefault: !!param.defaultValue,
12876
- defaultValueExpression: param.defaultValue,
12877
- defaultType: defaultValueType,
12878
- type: paramType !== null && paramType !== void 0 ? paramType : types_1.UnknownType.create(),
12879
- typeAnnotation: paramTypeNode,
12880
- hasDeclaredType: !!paramTypeNode,
12881
- isTypeInferred,
12882
- };
12883
- types_1.FunctionType.addParameter(functionType, functionParam);
12884
- if (functionParam.hasDeclaredType) {
12885
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionParam.type), functionType.details.typeVarScopeId);
12908
+ });
12909
+ // If the function ends in P.args and P.kwargs parameters, make it exempt from
12910
+ // args/kwargs compatibility checks. This is important for protocol comparisons.
12911
+ if (paramTypes.length >= 2) {
12912
+ const paramType1 = paramTypes[paramTypes.length - 2];
12913
+ const paramType2 = paramTypes[paramTypes.length - 1];
12914
+ if ((0, types_1.isParamSpec)(paramType1) &&
12915
+ paramType1.paramSpecAccess === 'args' &&
12916
+ (0, types_1.isParamSpec)(paramType2) &&
12917
+ paramType2.paramSpecAccess === 'kwargs') {
12918
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12919
+ }
12920
+ }
12921
+ // If the function contains an *args and a **kwargs parameter and both
12922
+ // are annotated as Any or are unannotated, make it exempt from
12923
+ // args/kwargs compatibility checks.
12924
+ const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12925
+ if (variadicsWithAnyType.length >= 2) {
12926
+ functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12886
12927
  }
12887
- if (param.name) {
12888
- const variadicParamType = transformVariadicParamType(node, param.category, functionParam.type);
12889
- paramTypes.push(variadicParamType);
12928
+ // If there was a defined return type, analyze that first so when we
12929
+ // walk the contents of the function, return statements can be
12930
+ // validated against this type.
12931
+ const returnTypeAnnotationNode = (_a = node.returnTypeAnnotation) !== null && _a !== void 0 ? _a : (_b = node.functionAnnotationComment) === null || _b === void 0 ? void 0 : _b.returnTypeAnnotation;
12932
+ if (returnTypeAnnotationNode) {
12933
+ // Temporarily set the return type to unknown in case of recursion.
12934
+ functionType.details.declaredReturnType = types_1.UnknownType.create();
12935
+ const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
12936
+ associateTypeVarsWithScope: true,
12937
+ });
12938
+ functionType.details.declaredReturnType = returnType;
12890
12939
  }
12891
12940
  else {
12892
- paramTypes.push(functionParam.type);
12893
- }
12894
- });
12895
- if (paramsArePositionOnly && functionType.details.parameters.length > firstNonClsSelfParamIndex) {
12896
- types_1.FunctionType.addPositionOnlyParameterSeparator(functionType);
12897
- }
12898
- // Update the types for the nodes associated with the parameters.
12899
- paramTypes.forEach((paramType, index) => {
12900
- const paramNameNode = node.parameters[index].name;
12901
- if (paramNameNode) {
12902
- if ((0, types_1.isUnknown)(paramType)) {
12903
- functionType.details.flags |= 16384 /* FunctionTypeFlags.UnannotatedParams */;
12941
+ // If there was no return type annotation and this is a type stub,
12942
+ // we have no opportunity to infer the return type, so we'll indicate
12943
+ // that it's unknown.
12944
+ if (fileInfo.isStubFile) {
12945
+ // Special-case the __init__ method, which is commonly left without
12946
+ // an annotated return type, but we can assume it returns None.
12947
+ if (node.name.value === '__init__') {
12948
+ functionType.details.declaredReturnType = getNoneType();
12949
+ }
12950
+ else {
12951
+ functionType.details.declaredReturnType = types_1.UnknownType.create();
12952
+ }
12904
12953
  }
12905
- writeTypeCache(paramNameNode, { type: paramType }, 0 /* EvaluatorFlags.None */);
12906
12954
  }
12907
- });
12908
- // If the function ends in P.args and P.kwargs parameters, make it exempt from
12909
- // args/kwargs compatibility checks. This is important for protocol comparisons.
12910
- if (paramTypes.length >= 2) {
12911
- const paramType1 = paramTypes[paramTypes.length - 2];
12912
- const paramType2 = paramTypes[paramTypes.length - 1];
12913
- if ((0, types_1.isParamSpec)(paramType1) &&
12914
- paramType1.paramSpecAccess === 'args' &&
12915
- (0, types_1.isParamSpec)(paramType2) &&
12916
- paramType2.paramSpecAccess === 'kwargs') {
12917
- functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12955
+ // Accumulate any type parameters used in the return type.
12956
+ if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12957
+ (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12918
12958
  }
12919
- }
12920
- // If the function contains an *args and a **kwargs parameter and both
12921
- // are annotated as Any or are unannotated, make it exempt from
12922
- // args/kwargs compatibility checks.
12923
- const variadicsWithAnyType = functionType.details.parameters.filter((param) => param.category !== 0 /* ParameterCategory.Simple */ && param.name && (0, types_1.isAnyOrUnknown)(param.type));
12924
- if (variadicsWithAnyType.length >= 2) {
12925
- functionType.details.flags |= 32768 /* FunctionTypeFlags.GradualCallableForm */;
12926
- }
12927
- // If there was a defined return type, analyze that first so when we
12928
- // walk the contents of the function, return statements can be
12929
- // validated against this type.
12930
- const returnTypeAnnotationNode = (_b = node.returnTypeAnnotation) !== null && _b !== void 0 ? _b : (_c = node.functionAnnotationComment) === null || _c === void 0 ? void 0 : _c.returnTypeAnnotation;
12931
- if (returnTypeAnnotationNode) {
12932
- // Temporarily set the return type to unknown in case of recursion.
12933
- functionType.details.declaredReturnType = types_1.UnknownType.create();
12934
- const returnType = getTypeOfAnnotation(returnTypeAnnotationNode, {
12935
- associateTypeVarsWithScope: true,
12936
- });
12937
- functionType.details.declaredReturnType = returnType;
12938
- }
12939
- else {
12940
- // If there was no return type annotation and this is a type stub,
12941
- // we have no opportunity to infer the return type, so we'll indicate
12942
- // that it's unknown.
12943
- if (fileInfo.isStubFile) {
12944
- // Special-case the __init__ method, which is commonly left without
12945
- // an annotated return type, but we can assume it returns None.
12946
- if (node.name.value === '__init__') {
12947
- functionType.details.declaredReturnType = getNoneType();
12948
- }
12949
- else {
12950
- functionType.details.declaredReturnType = types_1.UnknownType.create();
12959
+ // If the return type is explicitly annotated as a generator, mark the
12960
+ // function as a generator even though it may not contain a "yield" statement.
12961
+ // This is important for generator functions declared in stub files, abstract
12962
+ // methods or protocol definitions.
12963
+ if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite)) {
12964
+ if (functionType.details.declaredReturnType &&
12965
+ (0, types_1.isClassInstance)(functionType.details.declaredReturnType) &&
12966
+ types_1.ClassType.isBuiltIn(functionType.details.declaredReturnType, [
12967
+ 'Generator',
12968
+ 'AsyncGenerator',
12969
+ 'AwaitableGenerator',
12970
+ ])) {
12971
+ functionType.details.flags |= 16 /* FunctionTypeFlags.Generator */;
12951
12972
  }
12952
12973
  }
12953
- }
12954
- // Accumulate any type parameters used in the return type.
12955
- if (functionType.details.declaredReturnType && returnTypeAnnotationNode) {
12956
- (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, (0, typeUtils_1.getTypeVarArgumentsRecursive)(functionType.details.declaredReturnType), functionType.details.typeVarScopeId);
12957
- }
12958
- // If the return type is explicitly annotated as a generator, mark the
12959
- // function as a generator even though it may not contain a "yield" statement.
12960
- // This is important for generator functions declared in stub files, abstract
12961
- // methods or protocol definitions.
12962
- if (fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite)) {
12963
- if (functionType.details.declaredReturnType &&
12964
- (0, types_1.isClassInstance)(functionType.details.declaredReturnType) &&
12965
- types_1.ClassType.isBuiltIn(functionType.details.declaredReturnType, [
12966
- 'Generator',
12967
- 'AsyncGenerator',
12968
- 'AwaitableGenerator',
12969
- ])) {
12970
- functionType.details.flags |= 16 /* FunctionTypeFlags.Generator */;
12971
- }
12972
- }
12973
- // Validate the default types for all type parameters.
12974
- functionType.details.typeParameters.forEach((typeParam, index) => {
12975
- var _a;
12976
- let bestErrorNode = node.name;
12977
- if (node.typeParameters && index < node.typeParameters.parameters.length) {
12978
- const typeParamNode = node.typeParameters.parameters[index];
12979
- bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12980
- }
12981
- validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12974
+ // Validate the default types for all type parameters.
12975
+ functionType.details.typeParameters.forEach((typeParam, index) => {
12976
+ var _a;
12977
+ let bestErrorNode = node.name;
12978
+ if (node.typeParameters && index < node.typeParameters.parameters.length) {
12979
+ const typeParamNode = node.typeParameters.parameters[index];
12980
+ bestErrorNode = (_a = typeParamNode.defaultExpression) !== null && _a !== void 0 ? _a : typeParamNode.name;
12981
+ }
12982
+ validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index), functionType.details.typeVarScopeId);
12983
+ });
12984
+ // Clear the "partially evaluated" flag to indicate that the functionType
12985
+ // is fully evaluated.
12986
+ functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
12987
+ writeTypeCache(node.name, { type: functionType }, 0 /* EvaluatorFlags.None */);
12988
+ return functionType;
12982
12989
  });
12983
- // Clear the "partially evaluated" flag to indicate that the functionType
12984
- // is fully evaluated.
12985
- functionType.details.flags &= ~131072 /* FunctionTypeFlags.PartiallyEvaluated */;
12986
- writeTypeCache(node.name, { type: functionType }, 0 /* EvaluatorFlags.None */);
12987
- return functionType;
12988
12990
  }
12989
12991
  function markParamAccessed(param) {
12990
12992
  if (param.name) {
@@ -13297,8 +13299,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13297
13299
  const iteratorTypeResult = getTypeOfExpression(yieldNode.expression);
13298
13300
  if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
13299
13301
  types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
13302
+ const yieldType = iteratorTypeResult.type.typeArguments &&
13303
+ iteratorTypeResult.type.typeArguments.length > 0
13304
+ ? iteratorTypeResult.type.typeArguments[0]
13305
+ : types_1.UnknownType.create();
13300
13306
  // Handle old-style (pre-await) Coroutines.
13301
- inferredYieldTypes.push();
13307
+ inferredYieldTypes.push(yieldType);
13302
13308
  useAwaitableGenerator = true;
13303
13309
  }
13304
13310
  else {
@@ -13324,9 +13330,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13324
13330
  }
13325
13331
  });
13326
13332
  }
13327
- if (inferredYieldTypes.length === 0) {
13328
- inferredYieldTypes.push(getNoneType());
13329
- }
13330
13333
  const inferredYieldType = (0, types_1.combineTypes)(inferredYieldTypes);
13331
13334
  // Inferred yield types need to be wrapped in a Generator or
13332
13335
  // AwaitableGenerator to produce the final result.
@@ -16397,7 +16400,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16397
16400
  let flags = 0 /* AssignTypeFlags.Default */;
16398
16401
  if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* DeclarationType.Variable */ &&
16399
16402
  !isFinalVariableDeclaration(primaryDecl) &&
16400
- !types_1.ClassType.isFrozenDataClass(destType)) {
16403
+ !types_1.ClassType.isDataClassFrozen(destType)) {
16401
16404
  // Class and instance variables that are mutable need to
16402
16405
  // enforce invariance. We will exempt variables that are
16403
16406
  // private or protected, since these are presumably
@@ -19221,7 +19224,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19221
19224
  // evaluating (and caching) the inferred return type if there is no defined return type.
19222
19225
  getFunctionEffectiveReturnType(memberType);
19223
19226
  const specializedFunction = (0, typeUtils_1.applySolvedTypeVars)(memberType, typeVarContext);
19224
- return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, (0, typeUtils_1.getTypeVarScopeId)(baseType));
19227
+ // If this is a constructor method, provide the base type's TypeVar scope ID
19228
+ // so any TypeVars in this type can be solved.
19229
+ let baseTypeTypeVarScopeId;
19230
+ if (types_1.FunctionType.isConstructorMethod(specializedFunction) || specializedFunction.details.name === '__init__') {
19231
+ baseTypeTypeVarScopeId = (0, typeUtils_1.getTypeVarScopeId)(baseType);
19232
+ }
19233
+ return types_1.FunctionType.clone(specializedFunction, stripFirstParam, baseType, baseTypeTypeVarScopeId);
19225
19234
  }
19226
19235
  function isFinalVariable(symbol) {
19227
19236
  return symbol.getDeclarations().some((decl) => isFinalVariableDeclaration(decl));