@zzzen/pyright-internal 1.2.0-dev.20230813 → 1.2.0-dev.20230820

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 (78) hide show
  1. package/dist/analyzer/binder.js +8 -2
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.d.ts +1 -0
  4. package/dist/analyzer/checker.js +77 -6
  5. package/dist/analyzer/checker.js.map +1 -1
  6. package/dist/analyzer/dataClasses.js +242 -236
  7. package/dist/analyzer/dataClasses.js.map +1 -1
  8. package/dist/analyzer/enums.js +12 -0
  9. package/dist/analyzer/enums.js.map +1 -1
  10. package/dist/analyzer/importResolver.js +3 -1
  11. package/dist/analyzer/importResolver.js.map +1 -1
  12. package/dist/analyzer/namedTuples.js +6 -0
  13. package/dist/analyzer/namedTuples.js.map +1 -1
  14. package/dist/analyzer/operations.d.ts +1 -1
  15. package/dist/analyzer/operations.js +2 -2
  16. package/dist/analyzer/operations.js.map +1 -1
  17. package/dist/analyzer/parameterUtils.d.ts +2 -1
  18. package/dist/analyzer/parameterUtils.js +15 -0
  19. package/dist/analyzer/parameterUtils.js.map +1 -1
  20. package/dist/analyzer/protocols.js +14 -0
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/service.js +2 -2
  23. package/dist/analyzer/service.js.map +1 -1
  24. package/dist/analyzer/typeEvaluator.js +194 -108
  25. package/dist/analyzer/typeEvaluator.js.map +1 -1
  26. package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -1
  27. package/dist/analyzer/typeEvaluatorTypes.js +2 -2
  28. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  29. package/dist/analyzer/typeGuards.js +3 -0
  30. package/dist/analyzer/typeGuards.js.map +1 -1
  31. package/dist/analyzer/typePrinter.js +3 -0
  32. package/dist/analyzer/typePrinter.js.map +1 -1
  33. package/dist/analyzer/typeUtils.d.ts +1 -0
  34. package/dist/analyzer/typeUtils.js +20 -2
  35. package/dist/analyzer/typeUtils.js.map +1 -1
  36. package/dist/analyzer/types.js +1 -0
  37. package/dist/analyzer/types.js.map +1 -1
  38. package/dist/common/serviceProvider.d.ts +4 -3
  39. package/dist/languageServerBase.d.ts +2 -2
  40. package/dist/languageServerBase.js +4 -2
  41. package/dist/languageServerBase.js.map +1 -1
  42. package/dist/localization/localize.d.ts +22 -4
  43. package/dist/localization/localize.js +7 -2
  44. package/dist/localization/localize.js.map +1 -1
  45. package/dist/localization/package.nls.cs.json +3 -2
  46. package/dist/localization/package.nls.de.json +3 -2
  47. package/dist/localization/package.nls.en-us.json +16 -11
  48. package/dist/localization/package.nls.es.json +3 -2
  49. package/dist/localization/package.nls.fr.json +3 -2
  50. package/dist/localization/package.nls.it.json +3 -2
  51. package/dist/localization/package.nls.ja.json +3 -2
  52. package/dist/localization/package.nls.ko.json +3 -2
  53. package/dist/localization/package.nls.pl.json +3 -2
  54. package/dist/localization/package.nls.pt-br.json +3 -2
  55. package/dist/localization/package.nls.qps-ploc.json +3 -2
  56. package/dist/localization/package.nls.ru.json +3 -2
  57. package/dist/localization/package.nls.tr.json +3 -2
  58. package/dist/localization/package.nls.zh-cn.json +3 -2
  59. package/dist/localization/package.nls.zh-tw.json +2 -1
  60. package/dist/parser/parser.d.ts +1 -0
  61. package/dist/parser/parser.js +78 -18
  62. package/dist/parser/parser.js.map +1 -1
  63. package/dist/server.js +1 -1
  64. package/dist/server.js.map +1 -1
  65. package/dist/tests/harness/fourslash/testState.d.ts +1 -1
  66. package/dist/tests/harness/fourslash/testState.js +2 -2
  67. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  68. package/dist/tests/typeEvaluator1.test.js +4 -4
  69. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  70. package/dist/tests/typeEvaluator2.test.js +9 -1
  71. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  72. package/dist/tests/typeEvaluator3.test.js +7 -3
  73. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  74. package/dist/tests/typeEvaluator4.test.js +9 -1
  75. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  76. package/dist/tests/typeEvaluator5.test.js +9 -1
  77. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  78. package/package.json +1 -1
@@ -686,7 +686,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
686
686
  function reportInvalidUseOfPep695TypeAlias(type, node) {
687
687
  var _a;
688
688
  // PEP 695 type aliases cannot be used as instantiable classes.
689
- if (((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.name) && type.typeAliasInfo.isPep695Syntax) {
689
+ if (((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.name) && type.typeAliasInfo.isPep695Syntax && types_1.TypeBase.isSpecialForm(type)) {
690
690
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasNotAllowed().format({ name: type.typeAliasInfo.name }), node);
691
691
  return true;
692
692
  }
@@ -980,9 +980,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
980
980
  if (options === null || options === void 0 ? void 0 : options.associateTypeVarsWithScope) {
981
981
  evaluatorFlags |= 8192 /* AssociateTypeVarsWithCurrentScope */;
982
982
  }
983
- else {
984
- evaluatorFlags |= 4096 /* DisallowTypeVarsWithoutScopeId */;
985
- }
986
983
  if (options === null || options === void 0 ? void 0 : options.allowUnpackedTypedDict) {
987
984
  evaluatorFlags |= 8388608 /* AllowUnpackedTypedDict */;
988
985
  }
@@ -2507,14 +2504,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2507
2504
  (types_1.ClassType.isBuiltIn(callType, 'TypeVar') ||
2508
2505
  types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
2509
2506
  types_1.ClassType.isBuiltIn(callType, 'ParamSpec'))) {
2510
- if (target.nodeType !== 38 /* Name */ || target.value !== type.details.name) {
2507
+ const typeVarTarget = target.nodeType === 54 /* TypeAnnotation */ ? target.valueExpression : target;
2508
+ if (typeVarTarget.nodeType !== 38 /* Name */ || typeVarTarget.value !== type.details.name) {
2511
2509
  addError(type.details.isParamSpec
2512
2510
  ? localize_1.Localizer.Diagnostic.paramSpecAssignedName().format({
2513
2511
  name: types_1.TypeVarType.getReadableName(type),
2514
2512
  })
2515
2513
  : localize_1.Localizer.Diagnostic.typeVarAssignedName().format({
2516
2514
  name: types_1.TypeVarType.getReadableName(type),
2517
- }), target);
2515
+ }), typeVarTarget);
2518
2516
  }
2519
2517
  }
2520
2518
  }
@@ -3079,7 +3077,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3079
3077
  }
3080
3078
  }
3081
3079
  }
3082
- else if ((flags & 4096 /* DisallowTypeVarsWithoutScopeId */) !== 0) {
3080
+ else if ((flags & 4096 /* AllowTypeVarsWithoutScopeId */) === 0) {
3083
3081
  if ((type.scopeId === undefined || scopedTypeVarInfo.foundInterveningClass) &&
3084
3082
  !type.details.isSynthesized) {
3085
3083
  let message;
@@ -3271,7 +3269,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3271
3269
  4 /* AllowForwardReferences */ |
3272
3270
  524288 /* NotParsedByInterpreter */ |
3273
3271
  2048 /* DisallowTypeVarsWithScopeId */ |
3274
- 4096 /* DisallowTypeVarsWithoutScopeId */ |
3275
3272
  8192 /* AssociateTypeVarsWithCurrentScope */));
3276
3273
  const baseTypeResult = getTypeOfExpression(node.leftExpression, baseTypeFlags);
3277
3274
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
@@ -3888,10 +3885,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3888
3885
  },
3889
3886
  ];
3890
3887
  if (usage.method === 'get') {
3891
- // Provide "objtype" argument.
3888
+ // Provide "owner" argument.
3889
+ // Use Any rather than None for the owner argument if accessing through an object.
3890
+ // None is more correct, but it doesn't really matter, and many descriptor classes
3891
+ // incorrectly annotate the owner parameter. Rather than create a bunch of noise,
3892
+ // we'll use Any here.
3892
3893
  argList.push({
3893
3894
  argumentCategory: 0 /* Simple */,
3894
- typeResult: { type: baseTypeClass },
3895
+ typeResult: {
3896
+ type: isAccessedThroughObject ? types_1.AnyType.create() : baseTypeClass,
3897
+ },
3895
3898
  });
3896
3899
  }
3897
3900
  else if (usage.method === 'set') {
@@ -4487,6 +4490,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4487
4490
  if ((0, types_1.isParamSpec)(typeArg)) {
4488
4491
  functionType.details.paramSpec = typeArg;
4489
4492
  }
4493
+ else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
4494
+ types_1.FunctionType.addDefaultParameters(functionType);
4495
+ functionType.details.flags |= 32768 /* SkipArgsKwargsCompatibilityCheck */;
4496
+ }
4490
4497
  }
4491
4498
  else {
4492
4499
  types_1.FunctionType.addParameter(functionType, {
@@ -4866,14 +4873,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4866
4873
  typeof valueType.literalValue === 'number') {
4867
4874
  const indexValue = valueType.literalValue;
4868
4875
  const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
4869
- if (tupleType && tupleType.tupleTypeArguments && !(0, typeUtils_1.isUnboundedTupleClass)(tupleType)) {
4870
- if (indexValue >= 0 && indexValue < tupleType.tupleTypeArguments.length) {
4871
- return { type: tupleType.tupleTypeArguments[indexValue].type };
4872
- }
4873
- else if (indexValue < 0 && tupleType.tupleTypeArguments.length + indexValue >= 0) {
4874
- return {
4875
- type: tupleType.tupleTypeArguments[tupleType.tupleTypeArguments.length + indexValue].type,
4876
- };
4876
+ if (tupleType && tupleType.tupleTypeArguments) {
4877
+ if ((0, typeUtils_1.isTupleIndexUnambiguous)(tupleType, indexValue)) {
4878
+ if (indexValue >= 0 && indexValue < tupleType.tupleTypeArguments.length) {
4879
+ return { type: tupleType.tupleTypeArguments[indexValue].type };
4880
+ }
4881
+ else if (indexValue < 0 && tupleType.tupleTypeArguments.length + indexValue >= 0) {
4882
+ return {
4883
+ type: tupleType.tupleTypeArguments[tupleType.tupleTypeArguments.length + indexValue]
4884
+ .type,
4885
+ };
4886
+ }
4877
4887
  }
4878
4888
  }
4879
4889
  }
@@ -5663,7 +5673,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5663
5673
  }
5664
5674
  else if ((0, types_1.isInstantiableClass)(secondArgType)) {
5665
5675
  if ((0, types_1.isInstantiableClass)(targetClassType)) {
5666
- if (!(0, typeUtils_1.derivesFromClassRecursive)(secondArgType, targetClassType, /* ignoreUnknown */ true)) {
5676
+ if (!types_1.ClassType.isBuiltIn(targetClassType, 'type') &&
5677
+ !(0, typeUtils_1.derivesFromClassRecursive)(secondArgType, targetClassType, /* ignoreUnknown */ true)) {
5667
5678
  reportError = true;
5668
5679
  }
5669
5680
  }
@@ -6294,23 +6305,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6294
6305
  }
6295
6306
  }
6296
6307
  }
6308
+ let effectiveTypeVarContext = typeVarContext;
6309
+ if (!effectiveTypeVarContext) {
6310
+ // If a typeVarContext wasn't provided by the caller, allocate one here.
6311
+ effectiveTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(expandedCallType));
6312
+ }
6297
6313
  // The stdlib collections/__init__.pyi stub file defines namedtuple
6298
6314
  // as a function rather than a class, so we need to check for it here.
6299
6315
  if (expandedCallType.details.builtInName === 'namedtuple') {
6300
6316
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportUntypedNamedTuple, diagnosticRules_1.DiagnosticRule.reportUntypedNamedTuple, localize_1.Localizer.Diagnostic.namedTupleNoTypes(), errorNode);
6301
- return {
6317
+ const result = {
6302
6318
  returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
6303
6319
  };
6320
+ validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck);
6321
+ return result;
6304
6322
  }
6305
6323
  // Handle the NewType specially, replacing the normal return type.
6306
6324
  if (expandedCallType.details.builtInName === 'NewType') {
6307
6325
  return { returnType: createNewType(errorNode, argList) };
6308
6326
  }
6309
- let effectiveTypeVarContext = typeVarContext;
6310
- if (!effectiveTypeVarContext) {
6311
- // If a typeVarContext wasn't provided by the caller, allocate one here.
6312
- effectiveTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(expandedCallType));
6313
- }
6314
6327
  const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
6315
6328
  let isTypeIncomplete = !!functionResult.isTypeIncomplete;
6316
6329
  let returnType = functionResult.returnType;
@@ -6437,9 +6450,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6437
6450
  }
6438
6451
  }
6439
6452
  if (className === 'NamedTuple') {
6440
- return {
6453
+ const result = {
6441
6454
  returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ true),
6442
6455
  };
6456
+ const initTypeResult = getTypeOfObjectMember(errorNode, types_1.ClassType.cloneAsInstance(expandedCallType), '__init__');
6457
+ if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
6458
+ validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
6459
+ /* typeVarContext */ undefined, skipUnknownArgCheck,
6460
+ /* inferenceContext */ undefined);
6461
+ }
6462
+ return result;
6443
6463
  }
6444
6464
  if (className === 'NewType') {
6445
6465
  return { returnType: createNewType(errorNode, argList) };
@@ -8637,7 +8657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8637
8657
  typeParameters = [];
8638
8658
  let isTypeParamListValid = true;
8639
8659
  typeParamsExpr.expressions.map((expr) => {
8640
- let entryType = getTypeOfExpression(expr, 128 /* ExpectingInstantiableType */).type;
8660
+ let entryType = getTypeOfExpression(expr, 128 /* ExpectingInstantiableType */ | 4096 /* AllowTypeVarsWithoutScopeId */).type;
8641
8661
  if ((0, types_1.isTypeVar)(entryType)) {
8642
8662
  if (entryType.scopeId) {
8643
8663
  isTypeParamListValid = false;
@@ -8937,7 +8957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8937
8957
  }
8938
8958
  function getTypeOfDictionaryWithContext(node, inferenceContext, expectedDiagAddendum) {
8939
8959
  inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
8940
- const concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
8960
+ let concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
8941
8961
  if (!(0, types_1.isClassInstance)(concreteExpectedType)) {
8942
8962
  return undefined;
8943
8963
  }
@@ -8946,6 +8966,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8946
8966
  let isIncomplete = false;
8947
8967
  // Handle TypedDict's as a special case.
8948
8968
  if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
8969
+ // Remove any conditions associated with the type so the resulting type isn't
8970
+ // considered compatible with a bound TypeVar.
8971
+ concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
8949
8972
  const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
8950
8973
  // Infer the key and value types if possible.
8951
8974
  if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
@@ -8955,17 +8978,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8955
8978
  /* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum)) {
8956
8979
  isIncomplete = true;
8957
8980
  }
8958
- if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
8959
- const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface, concreteExpectedType, keyTypes, valueTypes,
8960
- // Don't overwrite existing expectedDiagAddendum messages if they were
8961
- // already provided by getKeyValueTypesFromDictionary.
8962
- (expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.isEmpty()) ? expectedDiagAddendum : undefined);
8963
- if (resultTypedDict) {
8964
- return {
8965
- type: resultTypedDict,
8966
- isIncomplete,
8967
- };
8968
- }
8981
+ const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface, concreteExpectedType, keyTypes, valueTypes,
8982
+ // Don't overwrite existing expectedDiagAddendum messages if they were
8983
+ // already provided by getKeyValueTypesFromDictionary.
8984
+ (expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.isEmpty()) ? expectedDiagAddendum : undefined);
8985
+ if (resultTypedDict) {
8986
+ return {
8987
+ type: resultTypedDict,
8988
+ isIncomplete,
8989
+ };
8969
8990
  }
8970
8991
  return undefined;
8971
8992
  }
@@ -9901,6 +9922,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9901
9922
  if ((0, types_1.isParamSpec)(typeArg)) {
9902
9923
  functionType.details.paramSpec = typeArg;
9903
9924
  }
9925
+ else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
9926
+ types_1.FunctionType.addDefaultParameters(functionType);
9927
+ functionType.details.flags |= 32768 /* SkipArgsKwargsCompatibilityCheck */;
9928
+ }
9904
9929
  }
9905
9930
  else {
9906
9931
  types_1.FunctionType.addParameter(functionType, {
@@ -10279,7 +10304,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10279
10304
  else {
10280
10305
  typeArgs.forEach((typeArg, index) => {
10281
10306
  if (index === typeArgs.length - 1) {
10282
- if (!(0, types_1.isParamSpec)(typeArg.type)) {
10307
+ if (!(0, types_1.isParamSpec)(typeArg.type) && !(0, typeUtils_1.isEllipsisType)(typeArg.type)) {
10283
10308
  addError(localize_1.Localizer.Diagnostic.concatenateParamSpecMissing(), typeArg.node);
10284
10309
  }
10285
10310
  }
@@ -10337,7 +10362,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10337
10362
  typeArgs.forEach((typeArg, index) => {
10338
10363
  if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
10339
10364
  if (!isTupleTypeParam) {
10340
- addError(localize_1.Localizer.Diagnostic.ellipsisContext(), typeArg.node);
10365
+ if (!allowParamSpec) {
10366
+ addError(localize_1.Localizer.Diagnostic.ellipsisContext(), typeArg.node);
10367
+ }
10341
10368
  }
10342
10369
  else if (typeArgs.length !== 2 || index !== 1) {
10343
10370
  addError(localize_1.Localizer.Diagnostic.ellipsisSecondArg(), typeArg.node);
@@ -10555,7 +10582,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10555
10582
  names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
10556
10583
  }), errorNode);
10557
10584
  }
10558
- return types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
10585
+ const typeAlias = types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
10586
+ // All PEP 695 type aliases are special forms because they are
10587
+ // TypeAliasType objects at runtime.
10588
+ if (isPep695Syntax) {
10589
+ typeAlias.flags |= 8 /* SpecialForm */;
10590
+ }
10591
+ return typeAlias;
10559
10592
  }
10560
10593
  function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
10561
10594
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
@@ -10701,7 +10734,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10701
10734
  return undefined;
10702
10735
  }
10703
10736
  function evaluateTypesForAssignmentStatement(node) {
10704
- var _a;
10737
+ var _a, _b;
10705
10738
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
10706
10739
  // If the entire statement has already been evaluated, don't
10707
10740
  // re-evaluate it.
@@ -10800,20 +10833,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10800
10833
  srcType = types_1.ClassType.cloneWithLiteral(boolType, constExprValue);
10801
10834
  }
10802
10835
  }
10803
- // If there was a declared type, make sure the RHS value is compatible.
10804
- if (declaredType) {
10805
- if (assignType(declaredType, srcType)) {
10806
- // Narrow the resulting type if possible.
10807
- if (!(0, types_1.isAnyOrUnknown)(srcType)) {
10808
- srcType = narrowTypeBasedOnAssignment(node, declaredType, srcType);
10809
- }
10810
- }
10811
- }
10812
10836
  // If this is an enum, transform the type as required.
10813
10837
  rightHandType = srcType;
10814
10838
  if (node.leftExpression.nodeType === 38 /* Name */ && !node.typeAnnotationComment) {
10815
10839
  rightHandType =
10816
- (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType) || rightHandType;
10840
+ (_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType)) !== null && _a !== void 0 ? _a : rightHandType;
10817
10841
  }
10818
10842
  if (typeAliasNameNode) {
10819
10843
  // If this was a speculative type alias, it becomes a real type alias
@@ -10834,7 +10858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10834
10858
  typeAliasTypeVar.details.boundType = rightHandType;
10835
10859
  // Record the type parameters within the recursive type alias so it
10836
10860
  // can be specialized.
10837
- typeAliasTypeVar.details.recursiveTypeParameters = (_a = rightHandType.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeParameters;
10861
+ typeAliasTypeVar.details.recursiveTypeParameters = (_b = rightHandType.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.typeParameters;
10838
10862
  }
10839
10863
  }
10840
10864
  }
@@ -11269,6 +11293,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11269
11293
  classType.details.fields = (innerScope === null || innerScope === void 0 ? void 0 : innerScope.symbolTable)
11270
11294
  ? new Map(innerScope.symbolTable)
11271
11295
  : new Map();
11296
+ // Determine whether the class should inherit __hash__. If a class defines
11297
+ // __eq__ but doesn't define __hash__ then __hash__ is set to None.
11298
+ if (classType.details.fields.has('__eq__') && !classType.details.fields.has('__hash__')) {
11299
+ classType.details.fields.set('__hash__', symbol_1.Symbol.createWithType(4 /* ClassMember */ | 128 /* ClassVar */ | 64 /* IgnoredForProtocolMatch */, types_1.NoneType.createInstance()));
11300
+ }
11272
11301
  // Determine whether the class's instance variables are constrained
11273
11302
  // to those defined by __slots__. We need to do this prior to dataclass
11274
11303
  // processing because dataclasses can implicitly add to the slots
@@ -11319,7 +11348,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11319
11348
  classType.details.flags |= 262144 /* HasCustomClassGetItem */;
11320
11349
  }
11321
11350
  }
11322
- // Determine the effective metaclass and detect metaclass conflicts.
11351
+ // Determine the effective metaclass.
11323
11352
  if (metaclassNode) {
11324
11353
  const metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
11325
11354
  if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
@@ -12105,11 +12134,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12105
12134
  }
12106
12135
  validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index));
12107
12136
  });
12137
+ // If it's an async function, wrap the return type in an Awaitable or Generator.
12138
+ const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
12108
12139
  // Clear the "partially evaluated" flag to indicate that the functionType
12109
12140
  // is fully evaluated.
12110
12141
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
12111
- // If it's an async function, wrap the return type in an Awaitable or Generator.
12112
- const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
12113
12142
  // Apply all of the decorators in reverse order.
12114
12143
  let decoratedType = preDecoratedType;
12115
12144
  let foundUnknown = false;
@@ -12322,7 +12351,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12322
12351
  (0, debug_1.assert)(types_1.FunctionType.isAsync(functionType));
12323
12352
  // Clone the original function and replace its return type with an
12324
12353
  // Awaitable[<returnType>]. Mark the new function as no longer async.
12325
- const awaitableFunctionType = types_1.FunctionType.cloneWithNewFlags(functionType, functionType.details.flags & ~512 /* Async */);
12354
+ const awaitableFunctionType = types_1.FunctionType.cloneWithNewFlags(functionType, functionType.details.flags & ~(512 /* Async */ | 131072 /* PartiallyEvaluated */));
12326
12355
  if (functionType.details.declaredReturnType) {
12327
12356
  awaitableFunctionType.details.declaredReturnType = createAwaitableReturnType(node, functionType.details.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
12328
12357
  }
@@ -12805,7 +12834,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12805
12834
  for (const caseStatement of node.parent.cases) {
12806
12835
  if (caseStatement === node) {
12807
12836
  if (fileInfo.diagnosticRuleSet.reportUnnecessaryComparison !== 'none') {
12808
- (0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.pattern, subjectType);
12837
+ if (!subjectTypeResult.isIncomplete) {
12838
+ (0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.pattern, subjectType);
12839
+ }
12809
12840
  }
12810
12841
  break;
12811
12842
  }
@@ -12821,23 +12852,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12821
12852
  if (isTypeCached(node)) {
12822
12853
  return;
12823
12854
  }
12824
- // Use the first element of the name parts as the symbol.
12825
- const symbolNameNode = node.module.nameParts[0];
12826
- // Look up the symbol to find the alias declaration.
12827
- let symbolType = getAliasedSymbolTypeForName(node, symbolNameNode.value);
12828
- if (!symbolType) {
12829
- return;
12855
+ if (node.isWildcardImport) {
12856
+ // Write back a dummy type so we don't evaluate this node again.
12857
+ writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /* None */);
12858
+ const flowNode = AnalyzerNodeInfo.getFlowNode(node);
12859
+ if (flowNode && (flowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) !== 0) {
12860
+ const wildcardFlowNode = flowNode;
12861
+ wildcardFlowNode.names.forEach((name) => {
12862
+ var _a, _b;
12863
+ const importedSymbolType = getAliasedSymbolTypeForName(node, name);
12864
+ if (!importedSymbolType) {
12865
+ return;
12866
+ }
12867
+ const symbolWithScope = lookUpSymbolRecursive(node, name, /* honorCodeFlow */ false);
12868
+ if (!symbolWithScope) {
12869
+ return;
12870
+ }
12871
+ const declaredType = (_a = getDeclaredTypeOfSymbol(symbolWithScope.symbol)) === null || _a === void 0 ? void 0 : _a.type;
12872
+ if (!declaredType) {
12873
+ return;
12874
+ }
12875
+ const diagAddendum = new diagnostic_1.DiagnosticAddendum();
12876
+ if (!assignType(declaredType, importedSymbolType, diagAddendum)) {
12877
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAssignmentMismatchWildcard().format({
12878
+ ...printSrcDestTypes(importedSymbolType, declaredType),
12879
+ name,
12880
+ }) + diagAddendum.getString(), node, (_b = node.wildcardToken) !== null && _b !== void 0 ? _b : node);
12881
+ }
12882
+ });
12883
+ }
12830
12884
  }
12831
- // Is there a cached module type associated with this node? If so, use
12832
- // it instead of the type we just created.
12833
- const cachedModuleType = readTypeCache(node, 0 /* None */);
12834
- if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
12835
- if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
12836
- symbolType = cachedModuleType;
12885
+ else {
12886
+ // Use the first element of the name parts as the symbol.
12887
+ const symbolNameNode = node.module.nameParts[0];
12888
+ // Look up the symbol to find the alias declaration.
12889
+ let symbolType = getAliasedSymbolTypeForName(node, symbolNameNode.value);
12890
+ if (!symbolType) {
12891
+ return;
12837
12892
  }
12893
+ // Is there a cached module type associated with this node? If so, use
12894
+ // it instead of the type we just created.
12895
+ const cachedModuleType = readTypeCache(node, 0 /* None */);
12896
+ if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
12897
+ if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
12898
+ symbolType = cachedModuleType;
12899
+ }
12900
+ }
12901
+ assignTypeToNameNode(symbolNameNode, symbolType,
12902
+ /* isIncomplete */ false,
12903
+ /* ignoreEmptyContainers */ false);
12904
+ writeTypeCache(node, { type: symbolType }, 0 /* None */);
12838
12905
  }
12839
- assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
12840
- writeTypeCache(node, { type: symbolType }, 0 /* None */);
12841
12906
  }
12842
12907
  function evaluateTypesForTypeAnnotationNode(node) {
12843
12908
  var _a;
@@ -13663,6 +13728,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13663
13728
  if ((0, types_1.isParamSpec)(typeArg)) {
13664
13729
  functionType.details.paramSpec = typeArg;
13665
13730
  }
13731
+ else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
13732
+ types_1.FunctionType.addDefaultParameters(functionType);
13733
+ functionType.details.flags |=
13734
+ 32768 /* SkipArgsKwargsCompatibilityCheck */;
13735
+ }
13666
13736
  }
13667
13737
  else {
13668
13738
  types_1.FunctionType.addParameter(functionType, {
@@ -13762,8 +13832,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13762
13832
  let flags = 128 /* ExpectingInstantiableType */ |
13763
13833
  8 /* EvaluateStringLiteralAsType */ |
13764
13834
  131072 /* DisallowClassVar */;
13765
- if (!(options === null || options === void 0 ? void 0 : options.allowTypeVarsWithoutScopeId)) {
13766
- flags |= 4096 /* DisallowTypeVarsWithoutScopeId */;
13835
+ if (options === null || options === void 0 ? void 0 : options.allowTypeVarsWithoutScopeId) {
13836
+ flags |= 4096 /* AllowTypeVarsWithoutScopeId */;
13767
13837
  }
13768
13838
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
13769
13839
  if (fileInfo.isStubFile || (options === null || options === void 0 ? void 0 : options.allowForwardReference)) {
@@ -17044,16 +17114,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17044
17114
  // concatenated parameters must match.
17045
17115
  if (targetIncludesParamSpec &&
17046
17116
  ((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
17047
- const srcParamCount = srcType.details.parameters.length;
17048
- const destParamCount = destType.details.parameters.length;
17049
- if (srcParamCount !== destParamCount) {
17050
- // If the dest has an extra position-only parameter separator appended
17051
- // to the end of the signature, it's OK.
17052
- if (srcParamCount !== destParamCount - 1 ||
17053
- destType.details.parameters[destParamCount - 1].category !== 0 /* Simple */ ||
17054
- !!destType.details.parameters[destParamCount - 1].name) {
17055
- canAssign = false;
17056
- }
17117
+ if (srcParamDetails.params.length !== destParamDetails.params.length) {
17118
+ canAssign = false;
17057
17119
  }
17058
17120
  }
17059
17121
  const effectiveSrcTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcTypeVarContext : destTypeVarContext;
@@ -17245,6 +17307,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17245
17307
  return types_1.ClassType.cloneForSpecialization(assignedType, newTypeArgs, /* isTypeArgumentExplicit */ true);
17246
17308
  }
17247
17309
  }
17310
+ // If the declared and assigned types are the same generic type but the assigned type
17311
+ // contains one or more unknowns, use the declared type instead.
17312
+ if (types_1.ClassType.isSameGenericClass(declaredType, assignedType)) {
17313
+ if ((0, typeUtils_1.containsAnyRecursive)(assignedType) && !(0, typeUtils_1.containsAnyRecursive)(declaredType)) {
17314
+ return declaredType;
17315
+ }
17316
+ }
17248
17317
  return undefined;
17249
17318
  }
17250
17319
  // When a value is assigned to a variable with a declared type,
@@ -17257,29 +17326,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17257
17326
  return declaredSubtype;
17258
17327
  }
17259
17328
  if (assignType(declaredSubtype, assignedSubtype)) {
17260
- // If the source is generic and has unspecified type arguments,
17261
- // see if we can determine them based on the declared type.
17262
- if ((0, types_1.isInstantiableClass)(declaredSubtype) && (0, types_1.isInstantiableClass)(assignedSubtype)) {
17329
+ // If the assigned subtype is Any, stick with the declared type.
17330
+ if ((0, types_1.isAny)(assignedSubtype)) {
17331
+ return declaredSubtype;
17332
+ }
17333
+ if ((0, types_1.isClass)(declaredSubtype) &&
17334
+ (0, types_1.isClass)(assignedSubtype) &&
17335
+ types_1.TypeBase.isInstance(declaredSubtype) === types_1.TypeBase.isInstance(assignedSubtype)) {
17263
17336
  const result = replaceTypeArgsWithAny(node, declaredSubtype, assignedSubtype);
17264
17337
  if (result) {
17265
17338
  assignedSubtype = result;
17266
17339
  }
17340
+ return assignedSubtype;
17267
17341
  }
17268
- else if ((0, types_1.isClassInstance)(declaredSubtype) && (0, types_1.isClassInstance)(assignedSubtype)) {
17269
- const result = replaceTypeArgsWithAny(node, types_1.ClassType.cloneAsInstantiable(declaredSubtype), types_1.ClassType.cloneAsInstantiable(assignedSubtype));
17270
- if (result) {
17271
- assignedSubtype = types_1.ClassType.cloneAsInstance(result);
17272
- }
17273
- }
17274
- else if (!(0, types_1.isTypeVar)(declaredSubtype) && (0, types_1.isTypeVar)(assignedSubtype)) {
17342
+ if (!(0, types_1.isTypeVar)(declaredSubtype) && (0, types_1.isTypeVar)(assignedSubtype)) {
17275
17343
  // If the source is an unsolved TypeVar but the declared type is concrete,
17276
17344
  // use the concrete type.
17277
17345
  return declaredSubtype;
17278
17346
  }
17279
- // If the assigned subtype is Any, stick with the declared type.
17280
- if ((0, types_1.isAny)(assignedSubtype)) {
17281
- return declaredSubtype;
17282
- }
17283
17347
  // If the declared type doesn't contain any `Any` but the assigned
17284
17348
  // type does, stick with the declared type.
17285
17349
  if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype) && !(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
@@ -17347,28 +17411,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17347
17411
  // must all match and be in the correct order. It is OK if the base method
17348
17412
  // has additional overloads that are not present in the override.
17349
17413
  let previousMatchIndex = -1;
17350
- let overrideOverloadIndex = 0;
17351
17414
  const baseOverloads = types_1.OverloadedFunctionType.getOverloads(baseMethod);
17352
17415
  for (const overrideOverload of types_1.OverloadedFunctionType.getOverloads(overrideMethod)) {
17353
- const matchIndex = baseOverloads.findIndex((baseOverload) => {
17416
+ let possibleMatchIndex;
17417
+ let matchIndex = baseOverloads.findIndex((baseOverload, index) => {
17354
17418
  // If the override isn't applicable for this base class, skip the check.
17355
17419
  if (baseClass && !isOverrideMethodApplicable(baseOverload, baseClass)) {
17356
17420
  return false;
17357
17421
  }
17358
- return validateOverrideMethodInternal(baseOverload, overrideOverload,
17422
+ const isCompatible = validateOverrideMethodInternal(baseOverload, overrideOverload,
17359
17423
  /* diag */ undefined, enforceParamNames,
17360
17424
  /* exemptSelfClsParam */ false);
17425
+ // If the override is compatible but the match is one that is below the previous
17426
+ // matched index, keep looking for additional matches. Record the fact that
17427
+ // we found at least one match.
17428
+ if (isCompatible && index <= previousMatchIndex && possibleMatchIndex === undefined) {
17429
+ possibleMatchIndex = index;
17430
+ return false;
17431
+ }
17432
+ return isCompatible;
17361
17433
  });
17434
+ if (matchIndex < 0 && possibleMatchIndex !== undefined) {
17435
+ matchIndex = possibleMatchIndex;
17436
+ }
17362
17437
  if (matchIndex < 0) {
17363
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex + 1 }));
17364
- return false;
17438
+ continue;
17365
17439
  }
17366
17440
  if (matchIndex < previousMatchIndex) {
17367
17441
  diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadOrder());
17368
17442
  return false;
17369
17443
  }
17370
17444
  previousMatchIndex = matchIndex;
17371
- overrideOverloadIndex++;
17445
+ }
17446
+ if (previousMatchIndex < baseOverloads.length - 1) {
17447
+ // We didn't find matches for all of the base overloads.
17448
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch());
17449
+ return false;
17372
17450
  }
17373
17451
  return true;
17374
17452
  }
@@ -17638,9 +17716,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17638
17716
  }
17639
17717
  }
17640
17718
  // Verify that one or the other method doesn't contain a ParamSpec.
17641
- if (baseMethod.details.paramSpec && !overrideMethod.details.paramSpec) {
17642
- diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecMissingInOverride());
17643
- canOverride = false;
17719
+ if (baseParamDetails.paramSpec && !overrideParamDetails.paramSpec) {
17720
+ // If the override uses an `*args: Any, **kwargs: Any` signature, we
17721
+ // will allow this as an acceptable overload for a `*args: P.args, **kwargs: P.kwargs`.
17722
+ const overrideHasArgsKwargs = overrideParamDetails.argsIndex !== undefined &&
17723
+ (0, types_1.isAnyOrUnknown)(overrideParamDetails.params[overrideParamDetails.argsIndex].type) &&
17724
+ overrideParamDetails.kwargsIndex !== undefined &&
17725
+ (0, types_1.isAnyOrUnknown)(overrideParamDetails.params[overrideParamDetails.kwargsIndex].type);
17726
+ if (!overrideHasArgsKwargs) {
17727
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecMissingInOverride());
17728
+ canOverride = false;
17729
+ }
17644
17730
  }
17645
17731
  // Now check the return type.
17646
17732
  const baseReturnType = getFunctionEffectiveReturnType(baseMethod);