@zzzen/pyright-internal 1.2.0-dev.20250202 → 1.2.0-dev.20250216

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 (132) hide show
  1. package/dist/analyzer/binder.js +1 -0
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +2 -1
  4. package/dist/analyzer/checker.js +53 -89
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/codeFlowEngine.js +2 -2
  7. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  8. package/dist/analyzer/constraintTracker.d.ts +2 -2
  9. package/dist/analyzer/constraintTracker.js +11 -5
  10. package/dist/analyzer/constraintTracker.js.map +1 -1
  11. package/dist/analyzer/constructors.js +2 -2
  12. package/dist/analyzer/constructors.js.map +1 -1
  13. package/dist/analyzer/importResolver.d.ts +1 -1
  14. package/dist/analyzer/parameterUtils.d.ts +4 -1
  15. package/dist/analyzer/parameterUtils.js +7 -3
  16. package/dist/analyzer/parameterUtils.js.map +1 -1
  17. package/dist/analyzer/program.d.ts +1 -0
  18. package/dist/analyzer/program.js +4 -1
  19. package/dist/analyzer/program.js.map +1 -1
  20. package/dist/analyzer/protocols.js +26 -11
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/service.d.ts +1 -0
  23. package/dist/analyzer/service.js +3 -1
  24. package/dist/analyzer/service.js.map +1 -1
  25. package/dist/analyzer/sourceFile.d.ts +10 -0
  26. package/dist/analyzer/sourceFile.js +5 -0
  27. package/dist/analyzer/sourceFile.js.map +1 -1
  28. package/dist/analyzer/sourceFileInfoUtils.d.ts +1 -0
  29. package/dist/analyzer/sourceFileInfoUtils.js +12 -11
  30. package/dist/analyzer/sourceFileInfoUtils.js.map +1 -1
  31. package/dist/analyzer/typeEvaluator.js +257 -122
  32. package/dist/analyzer/typeEvaluator.js.map +1 -1
  33. package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
  34. package/dist/analyzer/typeGuards.js +20 -3
  35. package/dist/analyzer/typeGuards.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +2 -1
  37. package/dist/analyzer/typeUtils.js +8 -2
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typedDicts.js +25 -10
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/backgroundAnalysisBase.d.ts +2 -2
  42. package/dist/backgroundAnalysisBase.js +14 -13
  43. package/dist/backgroundAnalysisBase.js.map +1 -1
  44. package/dist/backgroundThreadBase.d.ts +6 -2
  45. package/dist/backgroundThreadBase.js +7 -1
  46. package/dist/backgroundThreadBase.js.map +1 -1
  47. package/dist/common/fileSystem.d.ts +2 -0
  48. package/dist/common/fileSystem.js.map +1 -1
  49. package/dist/common/languageServerInterface.d.ts +0 -24
  50. package/dist/common/languageServerInterface.js.map +1 -1
  51. package/dist/common/realFileSystem.d.ts +2 -0
  52. package/dist/common/realFileSystem.js +8 -0
  53. package/dist/common/realFileSystem.js.map +1 -1
  54. package/dist/common/serviceKeys.d.ts +1 -1
  55. package/dist/common/serviceProviderExtensions.d.ts +1 -1
  56. package/dist/common/serviceProviderExtensions.js +2 -2
  57. package/dist/common/serviceProviderExtensions.js.map +1 -1
  58. package/dist/common/uri/uriMap.d.ts +17 -0
  59. package/dist/common/uri/uriMap.js +76 -0
  60. package/dist/common/uri/uriMap.js.map +1 -0
  61. package/dist/languageServerBase.d.ts +2 -1
  62. package/dist/languageServerBase.js +2 -0
  63. package/dist/languageServerBase.js.map +1 -1
  64. package/dist/languageService/completionProvider.js +1 -1
  65. package/dist/languageService/completionProvider.js.map +1 -1
  66. package/dist/languageService/referencesProvider.js +9 -2
  67. package/dist/languageService/referencesProvider.js.map +1 -1
  68. package/dist/localization/localize.d.ts +4 -5
  69. package/dist/localization/localize.js +2 -2
  70. package/dist/localization/localize.js.map +1 -1
  71. package/dist/localization/package.nls.cs.json +7 -7
  72. package/dist/localization/package.nls.de.json +7 -7
  73. package/dist/localization/package.nls.en-us.json +7 -7
  74. package/dist/localization/package.nls.es.json +7 -7
  75. package/dist/localization/package.nls.fr.json +7 -7
  76. package/dist/localization/package.nls.it.json +7 -7
  77. package/dist/localization/package.nls.ja.json +7 -7
  78. package/dist/localization/package.nls.ko.json +7 -7
  79. package/dist/localization/package.nls.pl.json +7 -7
  80. package/dist/localization/package.nls.pt-br.json +7 -7
  81. package/dist/localization/package.nls.qps-ploc.json +3 -3
  82. package/dist/localization/package.nls.ru.json +7 -7
  83. package/dist/localization/package.nls.tr.json +7 -7
  84. package/dist/localization/package.nls.zh-cn.json +7 -7
  85. package/dist/localization/package.nls.zh-tw.json +7 -7
  86. package/dist/parser/parser.js +6 -3
  87. package/dist/parser/parser.js.map +1 -1
  88. package/dist/parser/tokenizer.js +9 -7
  89. package/dist/parser/tokenizer.js.map +1 -1
  90. package/dist/partialStubService.d.ts +26 -0
  91. package/dist/partialStubService.js +138 -0
  92. package/dist/partialStubService.js.map +1 -0
  93. package/dist/pyrightFileSystem.d.ts +1 -21
  94. package/dist/pyrightFileSystem.js +7 -137
  95. package/dist/pyrightFileSystem.js.map +1 -1
  96. package/dist/readonlyAugmentedFileSystem.d.ts +7 -4
  97. package/dist/readonlyAugmentedFileSystem.js +124 -60
  98. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  99. package/dist/server.js +3 -1
  100. package/dist/server.js.map +1 -1
  101. package/dist/tests/completions.test.js +23 -0
  102. package/dist/tests/completions.test.js.map +1 -1
  103. package/dist/tests/fourslash/completions.vardecls.fourslash.js +2 -1
  104. package/dist/tests/fourslash/completions.vardecls.fourslash.js.map +1 -1
  105. package/dist/tests/fourslash/hover.async.fourslash.js +1 -1
  106. package/dist/tests/fourslash/hover.async.fourslash.js.map +1 -1
  107. package/dist/tests/fourslash/rename.typeParams.fourslash.d.ts +1 -0
  108. package/dist/tests/fourslash/rename.typeParams.fourslash.js +27 -0
  109. package/dist/tests/fourslash/rename.typeParams.fourslash.js.map +1 -0
  110. package/dist/tests/harness/fourslash/testState.js +3 -1
  111. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  112. package/dist/tests/harness/vfs/filesystem.d.ts +2 -0
  113. package/dist/tests/harness/vfs/filesystem.js +5 -2
  114. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  115. package/dist/tests/importResolver.test.js +8 -2
  116. package/dist/tests/importResolver.test.js.map +1 -1
  117. package/dist/tests/pyrightFileSystem.test.js +15 -8
  118. package/dist/tests/pyrightFileSystem.test.js.map +1 -1
  119. package/dist/tests/typeEvaluator1.test.js +1 -1
  120. package/dist/tests/typeEvaluator2.test.js +1 -1
  121. package/dist/tests/typeEvaluator4.test.js +4 -4
  122. package/dist/tests/typeEvaluator5.test.js +3 -3
  123. package/dist/tests/typeEvaluator6.test.js +6 -2
  124. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  125. package/dist/tests/typeEvaluator7.test.js +6 -2
  126. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  127. package/dist/tests/typeEvaluator8.test.js +1 -1
  128. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  129. package/dist/types.d.ts +26 -0
  130. package/dist/types.js +3 -0
  131. package/dist/types.js.map +1 -0
  132. package/package.json +1 -1
@@ -61,6 +61,7 @@ const constraintSolver_1 = require("./constraintSolver");
61
61
  const constraintTracker_1 = require("./constraintTracker");
62
62
  const constructors_1 = require("./constructors");
63
63
  const dataClasses_1 = require("./dataClasses");
64
+ const declaration_1 = require("./declaration");
64
65
  const declarationUtils_1 = require("./declarationUtils");
65
66
  const decorators_1 = require("./decorators");
66
67
  const enums_1 = require("./enums");
@@ -149,7 +150,10 @@ const maxDeclarationsToUseForInference = 64;
149
150
  const maxEffectiveTypeEvaluationAttempts = 16;
150
151
  // Maximum number of combinatoric argument type expansions allowed
151
152
  // when resolving an overload.
152
- const maxOverloadArgTypeExpansionCount = 64;
153
+ const maxTotalOverloadArgTypeExpansionCount = 256;
154
+ // Maximum size of an enum that will be expanded during overload
155
+ // argument type expansion.
156
+ const maxSingleOverloadArgTypeExpansionCount = 64;
153
157
  // Maximum number of recursive function return type inference attempts
154
158
  // that can be concurrently pending before we give up.
155
159
  const maxInferFunctionReturnRecursionCount = 12;
@@ -1469,7 +1473,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1469
1473
  !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1470
1474
  !types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
1471
1475
  const descMemberInfo = getTypeOfClassMemberName(errorNode, metaclass, memberName, usage,
1472
- /* diag */ undefined, flags | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, objectType, recursionCount);
1476
+ /* diag */ undefined, flags | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */ | 4096 /* MemberAccessFlags.SkipTypedDictEntries */, objectType, recursionCount);
1473
1477
  if (descMemberInfo) {
1474
1478
  const isProperty = (0, types_1.isClassInstance)(descMemberInfo.type) && types_1.ClassType.isPropertyClass(descMemberInfo.type);
1475
1479
  if ((0, typeUtils_1.isDescriptorInstance)(descMemberInfo.type, /* requireSetter */ true) || isProperty) {
@@ -1479,7 +1483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1479
1483
  }
1480
1484
  let subDiag;
1481
1485
  if (!skipObjectTypeLookup) {
1482
- let effectiveFlags = flags;
1486
+ let effectiveFlags = flags | 4096 /* MemberAccessFlags.SkipTypedDictEntries */;
1483
1487
  if (objectTypeIsInstantiable) {
1484
1488
  effectiveFlags |=
1485
1489
  16 /* MemberAccessFlags.SkipInstanceMembers */ |
@@ -2550,6 +2554,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2550
2554
  sourceEntryTypes.splice(unboundedIndex, 0, typeToReplicate);
2551
2555
  }
2552
2556
  }
2557
+ if (sourceEntryTypes.length > targetTypes.length) {
2558
+ // Remove elements to make the count match the target count.
2559
+ sourceEntryTypes.splice(unboundedIndex, 1);
2560
+ }
2553
2561
  }
2554
2562
  // If there's an unpack operator in the target and we have too many source elements,
2555
2563
  // combine them to assign to the unpacked target.
@@ -2936,12 +2944,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2936
2944
  break;
2937
2945
  }
2938
2946
  case 56 /* ParseNodeType.Unpack */: {
2939
- if (target.d.expr.nodeType === 38 /* ParseNodeType.Name */) {
2940
- assignTypeToNameNode(target.d.expr, {
2941
- type: getBuiltInObject(target.d.expr, 'list', [typeResult.type]),
2942
- isIncomplete: typeResult.isIncomplete,
2943
- }, ignoreEmptyContainers, srcExpr);
2944
- }
2947
+ assignTypeToExpression(target.d.expr, {
2948
+ type: getBuiltInObject(target.d.expr, 'list', [typeResult.type]),
2949
+ isIncomplete: typeResult.isIncomplete,
2950
+ }, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2945
2951
  break;
2946
2952
  }
2947
2953
  case 0 /* ParseNodeType.Error */: {
@@ -6733,7 +6739,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6733
6739
  }
6734
6740
  expandedArgTypes = expandArgTypes(contextFreeArgTypes, expandedArgTypes);
6735
6741
  // Check for combinatoric explosion and break out of loop.
6736
- if (!expandedArgTypes || expandedArgTypes.length > maxOverloadArgTypeExpansionCount) {
6742
+ if (!expandedArgTypes || expandedArgTypes.length > maxTotalOverloadArgTypeExpansionCount) {
6737
6743
  break;
6738
6744
  }
6739
6745
  }
@@ -6802,12 +6808,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
6802
6808
  if ((0, types_1.isClassInstance)(subtype)) {
6803
6809
  // Expand any bool or Enum literals.
6804
6810
  const expandedLiteralTypes = (0, typeGuards_1.enumerateLiteralsForType)(evaluatorInterface, subtype);
6805
- if (expandedLiteralTypes) {
6811
+ if (expandedLiteralTypes && expandedLiteralTypes.length <= maxSingleOverloadArgTypeExpansionCount) {
6806
6812
  (0, collectionUtils_1.appendArray)(expandedTypes, expandedLiteralTypes);
6807
6813
  return;
6808
6814
  }
6809
6815
  // Expand any fixed-size tuples.
6810
- const expandedTuples = (0, tuples_1.expandTuple)(subtype, maxOverloadArgTypeExpansionCount);
6816
+ const expandedTuples = (0, tuples_1.expandTuple)(subtype, maxSingleOverloadArgTypeExpansionCount);
6811
6817
  if (expandedTuples) {
6812
6818
  (0, collectionUtils_1.appendArray)(expandedTypes, expandedTuples);
6813
6819
  return;
@@ -7370,7 +7376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7370
7376
  // This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
7371
7377
  function matchArgsToParams(errorNode, argList, typeResult, overloadIndex) {
7372
7378
  const overload = typeResult.type;
7373
- const paramDetails = (0, parameterUtils_1.getParamListDetails)(overload);
7379
+ const paramDetails = (0, parameterUtils_1.getParamListDetails)(overload, { disallowExtraKwargsForTd: true });
7374
7380
  const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(overload);
7375
7381
  let argIndex = 0;
7376
7382
  let matchedUnpackedListOfUnknownLength = false;
@@ -7498,7 +7504,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7498
7504
  }
7499
7505
  else {
7500
7506
  let tooManyPositionals = false;
7501
- if (foundUnpackedListArg && argList[argIndex].argCategory === 1 /* ArgCategory.UnpackedList */) {
7507
+ if (argList[argIndex].argCategory === 1 /* ArgCategory.UnpackedList */) {
7502
7508
  // If this is an unpacked iterable, we will conservatively assume that it
7503
7509
  // might have zero iterations unless we can tell from its type that it
7504
7510
  // definitely has at least one iterable value.
@@ -7510,9 +7516,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7510
7516
  argType.priv.tupleTypeArgs.length > 0) {
7511
7517
  tooManyPositionals = true;
7512
7518
  }
7513
- else {
7514
- matchedUnpackedListOfUnknownLength = true;
7515
- }
7516
7519
  }
7517
7520
  else {
7518
7521
  tooManyPositionals = true;
@@ -7601,6 +7604,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7601
7604
  listElementType = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
7602
7605
  /* isAsync */ false, errorNode,
7603
7606
  /* emitNotIterableError */ false)?.type;
7607
+ if (paramInfo.param.category === 1 /* ParamCategory.ArgsList */) {
7608
+ matchedUnpackedListOfUnknownLength = true;
7609
+ }
7604
7610
  }
7605
7611
  const funcArg = listElementType
7606
7612
  ? {
@@ -7844,8 +7850,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7844
7850
  const kwargsParam = paramDetails.params[paramDetails.kwargsIndex];
7845
7851
  validateArgTypeParams.push({
7846
7852
  paramCategory: 2 /* ParamCategory.KwargsDict */,
7847
- paramType: kwargsParam.declaredType,
7848
- requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(kwargsParam.declaredType),
7853
+ paramType: kwargsParam.type,
7854
+ requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(kwargsParam.type),
7849
7855
  argument: {
7850
7856
  argCategory: 2 /* ArgCategory.UnpackedDictionary */,
7851
7857
  typeResult: { type: extraItemsType },
@@ -8105,25 +8111,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8105
8111
  const param = paramInfo.param;
8106
8112
  if (param.category === 0 /* ParamCategory.Simple */ && param.name) {
8107
8113
  const entry = paramMap.get(param.name);
8108
- if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0) {
8109
- const defaultArgType = paramInfo.defaultType;
8110
- if (defaultArgType &&
8111
- !(0, typeUtils_1.isEllipsisType)(defaultArgType) &&
8112
- (0, typeUtils_1.requiresSpecialization)(paramInfo.declaredType)) {
8113
- validateArgTypeParams.push({
8114
- paramCategory: param.category,
8115
- paramType: paramInfo.type,
8116
- requiresTypeVarMatching: true,
8117
- argument: {
8118
- argCategory: 0 /* ArgCategory.Simple */,
8119
- typeResult: { type: defaultArgType },
8120
- },
8121
- isDefaultArg: true,
8122
- errorNode,
8123
- paramName: param.name,
8124
- isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
8125
- });
8126
- }
8114
+ if (entry && entry.argsNeeded === 0 && entry.argsReceived === 0 && paramInfo.defaultType) {
8115
+ validateArgTypeParams.push({
8116
+ paramCategory: param.category,
8117
+ paramType: paramInfo.type,
8118
+ requiresTypeVarMatching: true,
8119
+ argument: {
8120
+ argCategory: 0 /* ArgCategory.Simple */,
8121
+ typeResult: { type: paramInfo.defaultType },
8122
+ },
8123
+ isDefaultArg: true,
8124
+ errorNode,
8125
+ paramName: param.name,
8126
+ isParamNameSynthesized: types_1.FunctionParam.isNameSynthesized(param),
8127
+ });
8127
8128
  }
8128
8129
  }
8129
8130
  });
@@ -8198,10 +8199,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8198
8199
  }
8199
8200
  let relevance = 0;
8200
8201
  if (matchedUnpackedListOfUnknownLength) {
8201
- // Lower the relevance if we made assumptions about the length
8202
+ // Increase the relevance if we made assumptions about the length
8202
8203
  // of an unpacked argument. This will favor overloads that
8203
8204
  // associate this case with a *args parameter.
8204
- relevance--;
8205
+ relevance++;
8205
8206
  }
8206
8207
  // Special-case the builtin isinstance and issubclass functions.
8207
8208
  if (types_1.FunctionType.isBuiltIn(overload, ['isinstance', 'issubclass']) && validateArgTypeParams.length === 2) {
@@ -10223,7 +10224,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
10223
10224
  return generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
10224
10225
  }
10225
10226
  // Handle old-style (pre-await) Coroutines as a special case.
10226
- if ((0, types_1.isClassInstance)(yieldFromSubtype) && types_1.ClassType.isBuiltIn(yieldFromSubtype, 'Coroutine')) {
10227
+ if ((0, types_1.isClassInstance)(yieldFromSubtype) &&
10228
+ types_1.ClassType.isBuiltIn(yieldFromSubtype, ['Coroutine', 'CoroutineType'])) {
10227
10229
  return types_1.UnknownType.create();
10228
10230
  }
10229
10231
  // Handle simple iterables.
@@ -12067,6 +12069,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12067
12069
  if (fileInfo.isStubFile) {
12068
12070
  exprFlags |= 4 /* EvalFlags.ForwardRefs */;
12069
12071
  }
12072
+ let sawClosedOrExtraItems = false;
12070
12073
  node.d.arguments.forEach((arg) => {
12071
12074
  // Ignore unpacked arguments.
12072
12075
  if (arg.d.argCategory === 2 /* ArgCategory.UnpackedDictionary */) {
@@ -12249,15 +12252,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12249
12252
  else if (arg.d.name.d.value === 'total' && !constArgValue) {
12250
12253
  classType.shared.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
12251
12254
  }
12252
- else if (arg.d.name.d.value === 'closed' && constArgValue) {
12253
- // This is an experimental feature because PEP 728 hasn't been accepted yet.
12254
- if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
12255
- classType.shared.flags |=
12256
- 8 /* ClassTypeFlags.TypedDictMarkedClosed */ | 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
12257
- if (classType.shared.typedDictExtraItemsExpr) {
12258
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12255
+ else if (arg.d.name.d.value === 'closed') {
12256
+ if (constArgValue) {
12257
+ // This is an experimental feature because PEP 728 hasn't been accepted yet.
12258
+ if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
12259
+ classType.shared.flags |=
12260
+ 8 /* ClassTypeFlags.TypedDictMarkedClosed */ |
12261
+ 16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
12262
+ if (classType.shared.typedDictExtraItemsExpr) {
12263
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12264
+ }
12259
12265
  }
12260
12266
  }
12267
+ if (sawClosedOrExtraItems) {
12268
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
12269
+ }
12270
+ sawClosedOrExtraItems = true;
12261
12271
  }
12262
12272
  }
12263
12273
  else if (arg.d.name.d.value === 'extra_items') {
@@ -12271,6 +12281,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
12271
12281
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
12272
12282
  }
12273
12283
  }
12284
+ if (sawClosedOrExtraItems) {
12285
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
12286
+ }
12287
+ sawClosedOrExtraItems = true;
12274
12288
  }
12275
12289
  else {
12276
12290
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictInitsubclassParameter().format({ name: arg.d.name.d.value }), arg);
@@ -13550,8 +13564,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13550
13564
  }
13551
13565
  }
13552
13566
  if (!awaitableReturnType || !isGenerator) {
13553
- // Wrap in either an Awaitable or a Coroutine, which is a subclass of Awaitable.
13554
- const awaitableType = getTypingType(node, useCoroutine ? 'Coroutine' : 'Awaitable');
13567
+ // Wrap in either an Awaitable or a CoroutineType, which is a subclass of Awaitable.
13568
+ const awaitableType = useCoroutine ? getTypesType(node, 'CoroutineType') : getTypingType(node, 'Awaitable');
13555
13569
  if (awaitableType && (0, types_1.isInstantiableClass)(awaitableType)) {
13556
13570
  awaitableReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(awaitableType, useCoroutine ? [types_1.AnyType.create(), types_1.AnyType.create(), returnType] : [returnType]));
13557
13571
  }
@@ -13670,7 +13684,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13670
13684
  isYieldResultUsed = true;
13671
13685
  const iteratorTypeResult = getTypeOfExpression(yieldNode.d.expr);
13672
13686
  if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
13673
- types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
13687
+ types_1.ClassType.isBuiltIn(iteratorTypeResult.type, ['Coroutine', 'CoroutineType'])) {
13674
13688
  const yieldType = iteratorTypeResult.type.priv.typeArgs &&
13675
13689
  iteratorTypeResult.type.priv.typeArgs.length > 0
13676
13690
  ? iteratorTypeResult.type.priv.typeArgs[0]
@@ -16331,6 +16345,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16331
16345
  }
16332
16346
  declsToConsider.push(resolvedDecl);
16333
16347
  });
16348
+ // If all of the decls come from augmented assignments, we won't be able to
16349
+ // determine its type. At least one declaration must be a simple assignment.
16350
+ if (declsToConsider.every((decl) => (0, declaration_1.isVariableDeclaration)(decl) &&
16351
+ ParseTreeUtils.isNodeContainedWithinNodeType(decl.node, 5 /* ParseNodeType.AugmentedAssignment */))) {
16352
+ declsToConsider.splice(0);
16353
+ }
16334
16354
  const result = getTypeOfSymbolForDecls(symbol, declsToConsider, effectiveTypeCacheKey);
16335
16355
  result.includesVariableDecl = includesVariableDecl;
16336
16356
  result.includesIllegalTypeAliasDecl = includesIllegalTypeAliasDecl;
@@ -16878,13 +16898,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16878
16898
  if (!(0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, destType, srcType, diag, constraints, flags, recursionCount)) {
16879
16899
  return false;
16880
16900
  }
16881
- if (types_1.ClassType.isFinal(destType) !== types_1.ClassType.isFinal(srcType)) {
16882
- diag?.addMessage(localize_1.LocAddendum.typedDictFinalMismatch().format({
16883
- sourceType: printType((0, typeUtils_1.convertToInstance)(srcType)),
16884
- destType: printType((0, typeUtils_1.convertToInstance)(destType)),
16885
- }));
16886
- return false;
16887
- }
16888
16901
  // If invariance is being enforced, the two TypedDicts must be assignable to each other.
16889
16902
  if ((flags & 1 /* AssignTypeFlags.Invariant */) !== 0) {
16890
16903
  return (0, typedDicts_1.assignTypedDictToTypedDict)(evaluatorInterface, srcType, destType,
@@ -17770,7 +17783,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17770
17783
  const typeVarSignatures = [];
17771
17784
  overloads.forEach((overload) => {
17772
17785
  const overloadScopeId = (0, typeUtils_1.getTypeVarScopeId)(overload) ?? '';
17773
- const constraintsClone = constraints?.cloneWithSignature(overloadScopeId);
17786
+ const constraintsClone = constraints?.cloneWithSignature([overloadScopeId]);
17774
17787
  if (assignType(destType, overload, /* diag */ undefined, constraintsClone, flags, recursionCount)) {
17775
17788
  filteredOverloads.push(overload);
17776
17789
  if (constraintsClone) {
@@ -17929,6 +17942,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17929
17942
  if ((0, types_1.isTypeSame)(srcType, destType, {}, recursionCount)) {
17930
17943
  return true;
17931
17944
  }
17945
+ if ((flags & 16 /* AssignTypeFlags.OverloadOverlap */) !== 0 &&
17946
+ srcType.priv.subtypes.some((subtype) => (0, types_1.isAnyOrUnknown)(subtype))) {
17947
+ return false;
17948
+ }
17932
17949
  // Sort the subtypes so we have a deterministic order for unions.
17933
17950
  let sortedSrcTypes = (0, typeUtils_1.sortTypes)(srcType.priv.subtypes);
17934
17951
  let matchedSomeSubtypes = false;
@@ -18175,6 +18192,95 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18175
18192
  /* diag */ undefined,
18176
18193
  /* constraints */ undefined, 0 /* AssignTypeFlags.Default */, recursionCount));
18177
18194
  }
18195
+ // Determines whether the two types are potentially comparable -- i.e.
18196
+ // their types overlap in such a way that it makes sense for them to
18197
+ // be compared with an == or != operator.
18198
+ function isTypeComparable(leftType, rightType) {
18199
+ if ((0, types_1.isAnyOrUnknown)(leftType) || (0, types_1.isAnyOrUnknown)(rightType)) {
18200
+ return true;
18201
+ }
18202
+ if ((0, types_1.isNever)(leftType) || (0, types_1.isNever)(rightType)) {
18203
+ return false;
18204
+ }
18205
+ if ((0, types_1.isModule)(leftType) || (0, types_1.isModule)(rightType)) {
18206
+ return (0, types_1.isTypeSame)(leftType, rightType, { ignoreConditions: true });
18207
+ }
18208
+ const isLeftCallable = (0, types_1.isFunction)(leftType) || (0, types_1.isOverloaded)(leftType);
18209
+ const isRightCallable = (0, types_1.isFunction)(rightType) || (0, types_1.isOverloaded)(rightType);
18210
+ if (isLeftCallable !== isRightCallable) {
18211
+ return false;
18212
+ }
18213
+ if ((0, types_1.isInstantiableClass)(leftType) || ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isBuiltIn(leftType, 'type'))) {
18214
+ if ((0, types_1.isInstantiableClass)(rightType) ||
18215
+ ((0, types_1.isClassInstance)(rightType) && types_1.ClassType.isBuiltIn(rightType, 'type'))) {
18216
+ const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
18217
+ const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
18218
+ if (assignType(genericLeftType, genericRightType) || assignType(genericRightType, genericLeftType)) {
18219
+ return true;
18220
+ }
18221
+ }
18222
+ // Does the class have an operator overload for eq?
18223
+ const metaclass = leftType.shared.effectiveMetaclass;
18224
+ if (metaclass && (0, types_1.isClass)(metaclass)) {
18225
+ if ((0, typeUtils_1.lookUpClassMember)(metaclass, '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */)) {
18226
+ return true;
18227
+ }
18228
+ }
18229
+ return false;
18230
+ }
18231
+ if ((0, types_1.isClassInstance)(leftType)) {
18232
+ if ((0, types_1.isClass)(rightType)) {
18233
+ const genericLeftType = types_1.ClassType.specialize(leftType, /* typeArgs */ undefined);
18234
+ const genericRightType = types_1.ClassType.specialize(rightType, /* typeArgs */ undefined);
18235
+ if (assignType(genericLeftType, genericRightType) || assignType(genericRightType, genericLeftType)) {
18236
+ return true;
18237
+ }
18238
+ // Assume that if the types are disjoint and built-in classes that they
18239
+ // will never be comparable.
18240
+ if (types_1.ClassType.isBuiltIn(leftType) && types_1.ClassType.isBuiltIn(rightType) && types_1.TypeBase.isInstance(rightType)) {
18241
+ // We need to be careful with bool and int literals because
18242
+ // they are comparable under certain circumstances.
18243
+ let boolType;
18244
+ let intType;
18245
+ if (types_1.ClassType.isBuiltIn(leftType, 'bool') && types_1.ClassType.isBuiltIn(rightType, 'int')) {
18246
+ boolType = leftType;
18247
+ intType = rightType;
18248
+ }
18249
+ else if (types_1.ClassType.isBuiltIn(rightType, 'bool') && types_1.ClassType.isBuiltIn(leftType, 'int')) {
18250
+ boolType = rightType;
18251
+ intType = leftType;
18252
+ }
18253
+ if (boolType && intType) {
18254
+ const intVal = intType.priv?.literalValue;
18255
+ if (intVal === undefined) {
18256
+ return true;
18257
+ }
18258
+ if (intVal !== 0 && intVal !== 1) {
18259
+ return false;
18260
+ }
18261
+ const boolVal = boolType.priv?.literalValue;
18262
+ if (boolVal === undefined) {
18263
+ return true;
18264
+ }
18265
+ return boolVal === (intVal === 1);
18266
+ }
18267
+ return false;
18268
+ }
18269
+ }
18270
+ // Does the class have an operator overload for eq?
18271
+ const eqMethod = (0, typeUtils_1.lookUpClassMember)(types_1.ClassType.cloneAsInstantiable(leftType), '__eq__', 4 /* MemberAccessFlags.SkipObjectBaseClass */);
18272
+ if (eqMethod) {
18273
+ // If this is a synthesized method for a dataclass, we can assume
18274
+ // that other dataclass types will not be comparable.
18275
+ if (types_1.ClassType.isDataClass(leftType) && eqMethod.symbol.getSynthesizedType()) {
18276
+ return false;
18277
+ }
18278
+ return true;
18279
+ }
18280
+ return false;
18281
+ }
18282
+ return true;
18283
+ }
18178
18284
  function assignToUnionType(destType, srcType, diag, constraints, flags, recursionCount) {
18179
18285
  // If we need to enforce invariance, the source needs to be compatible
18180
18286
  // with all subtypes in the dest, unless those subtypes are subclasses
@@ -18357,17 +18463,26 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18357
18463
  for (const mroClass of objType.shared.mro) {
18358
18464
  if ((0, types_1.isClass)(mroClass) && types_1.ClassType.isProtocolClass(mroClass)) {
18359
18465
  for (const field of types_1.ClassType.getSymbolTable(mroClass)) {
18360
- if (field[0] !== '__call__' && !field[1].isIgnoredForProtocolMatch()) {
18361
- let fieldIsPartOfFunction = false;
18362
- if (prefetched?.functionClass && (0, types_1.isClass)(prefetched.functionClass)) {
18363
- if (types_1.ClassType.getSymbolTable(prefetched.functionClass).has(field[0])) {
18364
- fieldIsPartOfFunction = true;
18365
- }
18366
- }
18367
- if (!fieldIsPartOfFunction) {
18368
- return undefined;
18466
+ const fieldName = field[0];
18467
+ const fieldSymbol = field[1];
18468
+ // We're expecting a __call__ method. We will also ignore a
18469
+ // __slots__ definition, which is (by convention) ignored for
18470
+ // protocol matching.
18471
+ if (fieldName === '__call__' || fieldName === '__slots__') {
18472
+ continue;
18473
+ }
18474
+ if (fieldSymbol.isIgnoredForProtocolMatch()) {
18475
+ continue;
18476
+ }
18477
+ let fieldIsPartOfFunction = false;
18478
+ if (prefetched?.functionClass && (0, types_1.isClass)(prefetched.functionClass)) {
18479
+ if (types_1.ClassType.getSymbolTable(prefetched.functionClass).has(field[0])) {
18480
+ fieldIsPartOfFunction = true;
18369
18481
  }
18370
18482
  }
18483
+ if (!fieldIsPartOfFunction) {
18484
+ return undefined;
18485
+ }
18371
18486
  }
18372
18487
  }
18373
18488
  }
@@ -18518,6 +18633,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18518
18633
  const destPositionalCount = destParamDetails.firstKeywordOnlyIndex ?? destParamDetails.params.length;
18519
18634
  const srcPositionalCount = srcParamDetails.firstKeywordOnlyIndex ?? srcParamDetails.params.length;
18520
18635
  const positionalsToMatch = Math.min(destPositionalCount, srcPositionalCount);
18636
+ const skippedPosParamIndices = [];
18521
18637
  // Match positional parameters.
18522
18638
  for (let paramIndex = 0; paramIndex < positionalsToMatch; paramIndex++) {
18523
18639
  if (paramIndex === 0 &&
@@ -18529,6 +18645,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18529
18645
  }
18530
18646
  // Skip over the *args parameter since it's handled separately below.
18531
18647
  if (paramIndex === destParamDetails.argsIndex) {
18648
+ if (!(0, types_1.isUnpackedTypeVarTuple)(destParamDetails.params[destParamDetails.argsIndex].type)) {
18649
+ skippedPosParamIndices.push(paramIndex);
18650
+ }
18532
18651
  continue;
18533
18652
  }
18534
18653
  const destParam = destParamDetails.params[paramIndex];
@@ -18621,7 +18740,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18621
18740
  canAssign = false;
18622
18741
  }
18623
18742
  if (destPositionalCount < srcPositionalCount && !targetIncludesParamSpec) {
18743
+ // Add any remaining positional parameter indices to the list that
18744
+ // need to be validated.
18624
18745
  for (let i = destPositionalCount; i < srcPositionalCount; i++) {
18746
+ skippedPosParamIndices.push(i);
18747
+ }
18748
+ for (const i of skippedPosParamIndices) {
18625
18749
  // If the dest has an *args parameter, make sure it can accept the remaining
18626
18750
  // positional arguments in the source.
18627
18751
  if (destParamDetails.argsIndex !== undefined) {
@@ -18781,66 +18905,76 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18781
18905
  }
18782
18906
  if (srcStartOfNamed >= 0) {
18783
18907
  srcParamDetails.params.forEach((srcParamInfo, index) => {
18784
- if (index >= srcStartOfNamed) {
18785
- if (srcParamInfo.param.name &&
18786
- srcParamInfo.param.category === 0 /* ParamCategory.Simple */ &&
18787
- srcParamInfo.kind !== parameterUtils_1.ParamKind.Positional) {
18788
- const destParamInfo = destParamMap.get(srcParamInfo.param.name);
18789
- const paramDiag = diag?.createAddendum();
18790
- const srcParamType = srcParamInfo.type;
18791
- if (!destParamInfo) {
18792
- if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.defaultType) {
18793
- if (paramDiag) {
18794
- paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
18795
- name: srcParamInfo.param.name,
18796
- }));
18797
- }
18798
- canAssign = false;
18799
- }
18800
- else if (destParamDetails.kwargsIndex !== undefined) {
18801
- // Make sure we can assign the type to the Kwargs.
18802
- if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamType, destParamDetails.params[destParamDetails.kwargsIndex].index, diag?.createAddendum(), constraints, flags, recursionCount)) {
18803
- canAssign = false;
18804
- }
18805
- }
18806
- else if (srcParamInfo.defaultType) {
18807
- // Assign default arg values in case they are needed for
18808
- // populating TypeVar constraints.
18809
- const defaultArgType = srcParamInfo.defaultType ?? srcParamInfo.defaultType;
18810
- if (defaultArgType &&
18811
- !assignType(srcParamInfo.type, defaultArgType, diag?.createAddendum(), constraints, flags, recursionCount)) {
18812
- if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) === 0) {
18813
- canAssign = false;
18814
- }
18815
- }
18816
- }
18908
+ if (index < srcStartOfNamed) {
18909
+ return;
18910
+ }
18911
+ if (!srcParamInfo.param.name ||
18912
+ srcParamInfo.param.category !== 0 /* ParamCategory.Simple */ ||
18913
+ srcParamInfo.kind === parameterUtils_1.ParamKind.Positional) {
18914
+ return;
18915
+ }
18916
+ const destParamInfo = destParamMap.get(srcParamInfo.param.name);
18917
+ const paramDiag = diag?.createAddendum();
18918
+ const srcParamType = srcParamInfo.type;
18919
+ if (!destParamInfo) {
18920
+ if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.defaultType) {
18921
+ if (paramDiag) {
18922
+ paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
18923
+ name: srcParamInfo.param.name,
18924
+ }));
18817
18925
  }
18818
- else {
18819
- const destParamType = destParamInfo.type;
18820
- const specializedDestParamType = constraints
18821
- ? solveAndApplyConstraints(destParamType, constraints)
18822
- : destParamType;
18823
- if (!assignParam(destParamInfo.type, srcParamType,
18824
- /* paramIndex */ undefined, paramDiag?.createAddendum(), constraints, flags, recursionCount)) {
18825
- if (paramDiag) {
18826
- paramDiag.addMessage(localize_1.LocAddendum.namedParamTypeMismatch().format({
18827
- name: srcParamInfo.param.name,
18828
- sourceType: printType(specializedDestParamType),
18829
- destType: printType(srcParamType),
18830
- }));
18831
- }
18832
- canAssign = false;
18833
- }
18834
- if (destParamInfo.defaultType && !srcParamInfo.defaultType) {
18835
- diag?.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
18836
- name: srcParamInfo.param.name,
18837
- }));
18926
+ canAssign = false;
18927
+ }
18928
+ else if (destParamDetails.kwargsIndex !== undefined) {
18929
+ // Make sure we can assign the type to the Kwargs.
18930
+ if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamType, destParamDetails.params[destParamDetails.kwargsIndex].index, diag?.createAddendum(), constraints, flags, recursionCount)) {
18931
+ canAssign = false;
18932
+ }
18933
+ }
18934
+ else if (srcParamInfo.defaultType) {
18935
+ // Assign default arg values in case they are needed for
18936
+ // populating TypeVar constraints.
18937
+ const defaultArgType = srcParamInfo.defaultType ?? srcParamInfo.defaultType;
18938
+ if (defaultArgType &&
18939
+ !assignType(srcParamInfo.type, defaultArgType, diag?.createAddendum(), constraints, flags, recursionCount)) {
18940
+ if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) === 0) {
18838
18941
  canAssign = false;
18839
18942
  }
18840
- destParamMap.delete(srcParamInfo.param.name);
18841
18943
  }
18842
18944
  }
18945
+ return;
18946
+ }
18947
+ // If we're performing a partial overload match and both the source
18948
+ // and dest parameters provide defaults, assume that there could
18949
+ // be a match.
18950
+ if (srcParamInfo.defaultType && destParamInfo.defaultType) {
18951
+ if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) !== 0) {
18952
+ destParamMap.delete(srcParamInfo.param.name);
18953
+ return;
18954
+ }
18955
+ }
18956
+ const destParamType = destParamInfo.type;
18957
+ const specializedDestParamType = constraints
18958
+ ? solveAndApplyConstraints(destParamType, constraints)
18959
+ : destParamType;
18960
+ if (!assignParam(destParamInfo.type, srcParamType,
18961
+ /* paramIndex */ undefined, paramDiag?.createAddendum(), constraints, flags, recursionCount)) {
18962
+ if (paramDiag) {
18963
+ paramDiag.addMessage(localize_1.LocAddendum.namedParamTypeMismatch().format({
18964
+ name: srcParamInfo.param.name,
18965
+ sourceType: printType(specializedDestParamType),
18966
+ destType: printType(srcParamType),
18967
+ }));
18968
+ }
18969
+ canAssign = false;
18970
+ }
18971
+ if (destParamInfo.defaultType && !srcParamInfo.defaultType) {
18972
+ diag?.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
18973
+ name: srcParamInfo.param.name,
18974
+ }));
18975
+ canAssign = false;
18843
18976
  }
18977
+ destParamMap.delete(srcParamInfo.param.name);
18844
18978
  });
18845
18979
  }
18846
18980
  // See if there are any unmatched named parameters.
@@ -20073,6 +20207,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
20073
20207
  getCallSignatureInfo,
20074
20208
  getAbstractSymbols,
20075
20209
  narrowConstrainedTypeVar,
20210
+ isTypeComparable,
20076
20211
  assignType,
20077
20212
  validateOverrideMethod,
20078
20213
  validateCallArgs,