@zzzen/pyright-internal 1.2.0-dev.20230723 → 1.2.0-dev.20230806

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 (125) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +2 -2
  2. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  3. package/dist/analyzer/binder.js +3 -1
  4. package/dist/analyzer/binder.js.map +1 -1
  5. package/dist/analyzer/checker.js +5 -25
  6. package/dist/analyzer/checker.js.map +1 -1
  7. package/dist/analyzer/codeFlowEngine.js +11 -11
  8. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  9. package/dist/analyzer/constraintSolver.js +11 -10
  10. package/dist/analyzer/constraintSolver.js.map +1 -1
  11. package/dist/analyzer/constructors.js +25 -5
  12. package/dist/analyzer/constructors.js.map +1 -1
  13. package/dist/analyzer/docStringConversion.js +9 -5
  14. package/dist/analyzer/docStringConversion.js.map +1 -1
  15. package/dist/analyzer/enums.js +1 -1
  16. package/dist/analyzer/enums.js.map +1 -1
  17. package/dist/analyzer/importResolver.js +15 -14
  18. package/dist/analyzer/importResolver.js.map +1 -1
  19. package/dist/analyzer/parameterUtils.js +5 -1
  20. package/dist/analyzer/parameterUtils.js.map +1 -1
  21. package/dist/analyzer/patternMatching.js +24 -0
  22. package/dist/analyzer/patternMatching.js.map +1 -1
  23. package/dist/analyzer/program.d.ts +4 -2
  24. package/dist/analyzer/program.js +31 -25
  25. package/dist/analyzer/program.js.map +1 -1
  26. package/dist/analyzer/service.js +7 -7
  27. package/dist/analyzer/service.js.map +1 -1
  28. package/dist/analyzer/sourceFile.d.ts +5 -0
  29. package/dist/analyzer/sourceFile.js +11 -5
  30. package/dist/analyzer/sourceFile.js.map +1 -1
  31. package/dist/analyzer/typeEvaluator.js +247 -185
  32. package/dist/analyzer/typeEvaluator.js.map +1 -1
  33. package/dist/analyzer/typeGuards.js +1 -1
  34. package/dist/analyzer/typeGuards.js.map +1 -1
  35. package/dist/analyzer/typeUtils.d.ts +8 -8
  36. package/dist/analyzer/typeUtils.js +84 -17
  37. package/dist/analyzer/typeUtils.js.map +1 -1
  38. package/dist/analyzer/types.d.ts +8 -5
  39. package/dist/analyzer/types.js +13 -12
  40. package/dist/analyzer/types.js.map +1 -1
  41. package/dist/backgroundAnalysisBase.d.ts +5 -4
  42. package/dist/backgroundAnalysisBase.js +6 -6
  43. package/dist/backgroundAnalysisBase.js.map +1 -1
  44. package/dist/backgroundThreadBase.d.ts +2 -1
  45. package/dist/backgroundThreadBase.js +1 -1
  46. package/dist/backgroundThreadBase.js.map +1 -1
  47. package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
  48. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  49. package/dist/common/chokidarFileWatcherProvider.d.ts +1 -1
  50. package/dist/common/configOptions.d.ts +1 -0
  51. package/dist/common/configOptions.js +5 -1
  52. package/dist/common/configOptions.js.map +1 -1
  53. package/dist/common/diagnosticRules.d.ts +1 -0
  54. package/dist/common/diagnosticRules.js +1 -0
  55. package/dist/common/diagnosticRules.js.map +1 -1
  56. package/dist/common/extensibility.d.ts +3 -12
  57. package/dist/common/extensibility.js +5 -1
  58. package/dist/common/extensibility.js.map +1 -1
  59. package/dist/common/fileSystem.d.ts +1 -14
  60. package/dist/common/fileSystem.js +1 -31
  61. package/dist/common/fileSystem.js.map +1 -1
  62. package/dist/common/fileWatcher.d.ts +15 -0
  63. package/dist/common/fileWatcher.js +34 -0
  64. package/dist/common/fileWatcher.js.map +1 -0
  65. package/dist/common/realFileSystem.d.ts +2 -1
  66. package/dist/common/realFileSystem.js +2 -2
  67. package/dist/common/realFileSystem.js.map +1 -1
  68. package/dist/languageServerBase.d.ts +9 -6
  69. package/dist/languageServerBase.js +19 -11
  70. package/dist/languageServerBase.js.map +1 -1
  71. package/dist/languageService/completionProvider.js +3 -3
  72. package/dist/languageService/completionProvider.js.map +1 -1
  73. package/dist/languageService/hoverProvider.js +1 -6
  74. package/dist/languageService/hoverProvider.js.map +1 -1
  75. package/dist/languageService/tooltipUtils.js +7 -1
  76. package/dist/languageService/tooltipUtils.js.map +1 -1
  77. package/dist/localization/localize.d.ts +0 -4
  78. package/dist/localization/localize.js +0 -1
  79. package/dist/localization/localize.js.map +1 -1
  80. package/dist/localization/package.nls.cs.json +6 -6
  81. package/dist/localization/package.nls.de.json +6 -6
  82. package/dist/localization/package.nls.en-us.json +2 -3
  83. package/dist/localization/package.nls.es.json +6 -6
  84. package/dist/localization/package.nls.fr.json +6 -6
  85. package/dist/localization/package.nls.it.json +6 -6
  86. package/dist/localization/package.nls.ja.json +6 -6
  87. package/dist/localization/package.nls.ko.json +6 -6
  88. package/dist/localization/package.nls.pl.json +6 -6
  89. package/dist/localization/package.nls.pt-br.json +6 -6
  90. package/dist/localization/package.nls.qps-ploc.json +6 -6
  91. package/dist/localization/package.nls.ru.json +6 -6
  92. package/dist/localization/package.nls.tr.json +6 -6
  93. package/dist/localization/package.nls.zh-cn.json +6 -6
  94. package/dist/localization/package.nls.zh-tw.json +6 -6
  95. package/dist/pyright.js +2 -0
  96. package/dist/pyright.js.map +1 -1
  97. package/dist/readonlyAugmentedFileSystem.d.ts +2 -1
  98. package/dist/readonlyAugmentedFileSystem.js.map +1 -1
  99. package/dist/server.js +2 -1
  100. package/dist/server.js.map +1 -1
  101. package/dist/tests/docStringConversion.test.js +94 -0
  102. package/dist/tests/docStringConversion.test.js.map +1 -1
  103. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.d.ts +0 -0
  104. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js +30 -0
  105. package/dist/tests/fourslash/completions.importPrivateNoPytyped.fourslash.js.map +1 -0
  106. package/dist/tests/fourslash/completions.importPytyped.fourslash.d.ts +0 -0
  107. package/dist/tests/fourslash/completions.importPytyped.fourslash.js +29 -0
  108. package/dist/tests/fourslash/completions.importPytyped.fourslash.js.map +1 -0
  109. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.d.ts +0 -0
  110. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js +29 -0
  111. package/dist/tests/fourslash/completions.importPytypedLocal.fourslash.js.map +1 -0
  112. package/dist/tests/fourslash/hover.async.fourslash.d.ts +1 -0
  113. package/dist/tests/fourslash/hover.async.fourslash.js +12 -0
  114. package/dist/tests/fourslash/hover.async.fourslash.js.map +1 -0
  115. package/dist/tests/harness/vfs/filesystem.d.ts +2 -1
  116. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  117. package/dist/tests/typeEvaluator2.test.js +11 -1
  118. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  119. package/dist/tests/typeEvaluator3.test.js +13 -3
  120. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  121. package/dist/tests/typeEvaluator4.test.js +5 -1
  122. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  123. package/dist/tests/typeEvaluator5.test.js +8 -4
  124. package/dist/tests/typeEvaluator5.test.js.map +1 -1
  125. package/package.json +2 -2
@@ -772,6 +772,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
772
772
  };
773
773
  typeResult = {
774
774
  type: iteratorTypeResult.type,
775
+ typeErrors: iterTypeResult.typeErrors,
775
776
  unpackedType: iterType,
776
777
  isIncomplete: iteratorTypeResult.isIncomplete,
777
778
  };
@@ -2967,10 +2968,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2967
2968
  if (decl.type === 2 /* Parameter */) {
2968
2969
  return true;
2969
2970
  }
2970
- // Assume alias declarations are also always safe to narrow.
2971
- if (decl.type === 8 /* Alias */) {
2972
- return true;
2973
- }
2974
2971
  const declCodeFlowNode = AnalyzerNodeInfo.getFlowNode(decl.node);
2975
2972
  if (!declCodeFlowNode) {
2976
2973
  return false;
@@ -3704,7 +3701,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3704
3701
  // to leave the Self type generic (not specialized). We'll also
3705
3702
  // skip this for __new__ methods because they are not bound
3706
3703
  // to the class but rather assume the type of the cls argument.
3707
- const selfClass = bindToType || memberName === '__new__' ? undefined : classType;
3704
+ const selfClass = !!bindToType || memberName === '__new__' ? undefined : classType;
3708
3705
  const typeResult = getTypeOfMemberInternal(memberInfo, selfClass);
3709
3706
  if (typeResult) {
3710
3707
  type = typeResult.type;
@@ -3818,7 +3815,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3818
3815
  // a descriptor protocol, only 'get' operations are allowed. If it's accessed
3819
3816
  // through the object, all access methods are supported.
3820
3817
  if (isAccessedThroughObject || usage.method === 'get') {
3821
- lookupClass = (0, typeUtils_1.convertToInstance)(concreteSubtype.details.effectiveMetaclass);
3818
+ lookupClass = types_1.ClassType.cloneAsInstance(concreteSubtype.details.effectiveMetaclass);
3822
3819
  isAccessedThroughMetaclass = true;
3823
3820
  }
3824
3821
  else {
@@ -4641,7 +4638,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
4641
4638
  const isFinalAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'Final');
4642
4639
  const isClassVarAnnotation = (0, types_1.isInstantiableClass)(concreteSubtype) && types_1.ClassType.isBuiltIn(concreteSubtype, 'ClassVar');
4643
4640
  // Inlined TypedDicts are supported only for 'dict' (and not for 'Dict').
4644
- const supportsTypedDictTypeArg = (0, types_1.isInstantiableClass)(concreteSubtype) &&
4641
+ // This feature is currently experimental.
4642
+ const supportsTypedDictTypeArg = AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures &&
4643
+ (0, types_1.isInstantiableClass)(concreteSubtype) &&
4645
4644
  types_1.ClassType.isBuiltIn(concreteSubtype, 'dict') &&
4646
4645
  !concreteSubtype.aliasName;
4647
4646
  let typeArgs = getTypeArgs(node, flags, {
@@ -7485,13 +7484,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7485
7484
  }
7486
7485
  if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
7487
7486
  const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
7488
- (0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start);
7489
- const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
7490
- /* typeArguments */ undefined,
7491
- /* isTypeArgumentExplicit */ false);
7492
- effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
7493
- unknownIfNotFound: true,
7494
- });
7487
+ if ((0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes, errorNode.start)) {
7488
+ const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
7489
+ /* typeArguments */ undefined,
7490
+ /* isTypeArgumentExplicit */ false);
7491
+ effectiveExpectedType = (0, typeUtils_1.applySolvedTypeVars)(genericReturnType, tempTypeVarContext, {
7492
+ unknownIfNotFound: true,
7493
+ });
7494
+ }
7495
7495
  }
7496
7496
  }
7497
7497
  else if ((0, types_1.isFunction)(effectiveReturnType)) {
@@ -7654,12 +7654,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7654
7654
  }
7655
7655
  }
7656
7656
  });
7657
+ let paramSpecTypeVarContext = [];
7657
7658
  // Handle the assignment of additional arguments that map to a param spec.
7658
7659
  if (matchResults.paramSpecArgList && matchResults.paramSpecTarget) {
7659
- if (!validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext, typeCondition)) {
7660
+ const paramSpecArgResult = validateFunctionArgumentsForParamSpec(errorNode, matchResults.paramSpecArgList, matchResults.paramSpecTarget, typeVarContext, typeCondition);
7661
+ if (paramSpecArgResult.argumentErrors) {
7660
7662
  argumentErrors = true;
7661
7663
  argumentMatchScore += 1;
7662
7664
  }
7665
+ paramSpecTypeVarContext = paramSpecArgResult.typeVarContexts;
7663
7666
  }
7664
7667
  else if (type.details.paramSpec) {
7665
7668
  if (!sawParamSpecArgs || !sawParamSpecKwargs) {
@@ -7703,8 +7706,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7703
7706
  eliminateUnsolvedInUnions = false;
7704
7707
  }
7705
7708
  // We'll leave TypeVars unsolved if the call is a recursive
7706
- // call to a generic function.
7707
- const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
7709
+ // call to a generic function or if this isn't a callable
7710
+ // return with type parameters that are rescoped from the original
7711
+ // function to the returned callable.
7712
+ const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope)) && !type.details.rescopedTypeParameters;
7708
7713
  let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
7709
7714
  unknownIfNotFound,
7710
7715
  unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
@@ -7713,17 +7718,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7713
7718
  applyInScopePlaceholders: true,
7714
7719
  });
7715
7720
  specializedReturnType = (0, typeUtils_1.addConditionToType)(specializedReturnType, typeCondition);
7721
+ // If the function includes a ParamSpec and the captured signature(s) includes
7722
+ // generic types, we may need to apply those solved TypeVars.
7723
+ if (paramSpecTypeVarContext.length > 0) {
7724
+ paramSpecTypeVarContext.forEach((paramSpecTypeVarContext) => {
7725
+ if (paramSpecTypeVarContext) {
7726
+ specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(specializedReturnType, paramSpecTypeVarContext);
7727
+ }
7728
+ });
7729
+ }
7716
7730
  // If the final return type is an unpacked tuple, turn it into a normal (unpacked) tuple.
7717
7731
  if ((0, types_1.isUnpackedClass)(specializedReturnType)) {
7718
7732
  specializedReturnType = types_1.ClassType.cloneForUnpacked(specializedReturnType, /* isUnpackedTuple */ false);
7719
7733
  }
7720
- // Handle 'TypeGuard' and 'StrictTypeGuard' specially. We'll transform the
7721
- // return type into a 'bool' object with a type argument that reflects the
7722
- // narrowed type.
7734
+ // Handle 'TypeGuard' specially. We'll transform the return type into a 'bool'
7735
+ // object with a type argument that reflects the narrowed type.
7723
7736
  if ((0, types_1.isClassInstance)(specializedReturnType) &&
7724
- types_1.ClassType.isBuiltIn(specializedReturnType, ['TypeGuard', 'StrictTypeGuard']) &&
7737
+ types_1.ClassType.isBuiltIn(specializedReturnType, 'TypeGuard') &&
7725
7738
  specializedReturnType.typeArguments &&
7726
- specializedReturnType.typeArguments.length > 0) {
7739
+ specializedReturnType.typeArguments.length > 0 &&
7740
+ (0, types_1.isClassInstance)(returnType) &&
7741
+ returnType.typeArguments &&
7742
+ returnType.typeArguments.length > 0) {
7727
7743
  if (boolClassType && (0, types_1.isInstantiableClass)(boolClassType)) {
7728
7744
  let typeGuardType = specializedReturnType.typeArguments[0];
7729
7745
  // If the first argument is a simple (non-constrained) TypeVar,
@@ -7742,10 +7758,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7742
7758
  ]);
7743
7759
  }
7744
7760
  }
7745
- specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, types_1.ClassType.isBuiltIn(specializedReturnType, 'StrictTypeGuard')));
7761
+ let useStrictTypeGuardSemantics = false;
7762
+ if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
7763
+ // Determine the type of the first parameter.
7764
+ const paramIndex = type.boundToType ? 1 : 0;
7765
+ if (paramIndex < type.details.parameters.length) {
7766
+ const paramType = types_1.FunctionType.getEffectiveParameterType(type, paramIndex);
7767
+ // If the type guard meets the requirements that the first parameter
7768
+ // type is a proper subtype of the return type, we can use strict
7769
+ // type guard semantics.
7770
+ if (assignType(paramType, returnType.typeArguments[0])) {
7771
+ useStrictTypeGuardSemantics = true;
7772
+ }
7773
+ }
7774
+ }
7775
+ specializedReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.cloneForTypeGuard(boolClassType, typeGuardType, useStrictTypeGuardSemantics));
7746
7776
  }
7747
7777
  }
7748
- specializedReturnType = adjustCallableReturnType(specializedReturnType);
7778
+ specializedReturnType = adjustCallableReturnType(specializedReturnType, signatureTracker.getTrackedSignatures());
7749
7779
  if (specializedInitSelfType) {
7750
7780
  specializedInitSelfType = (0, typeUtils_1.applySolvedTypeVars)(specializedInitSelfType, typeVarContext);
7751
7781
  }
@@ -7787,19 +7817,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7787
7817
  }
7788
7818
  return [];
7789
7819
  }
7790
- function adjustCallableReturnType(returnType) {
7791
- // If the return type includes a generic Callable type, set the type var
7792
- // scope to a wildcard to allow these type vars to be solved. This won't
7793
- // work with overloads or unions of callables. It's intended for a
7794
- // specific use case. We may need to make this more sophisticated in
7795
- // the future.
7820
+ // If the return type includes a generic Callable type, set the type var
7821
+ // scope to a wildcard to allow these type vars to be solved. This won't
7822
+ // work with overloads or unions of callables. It's intended for a
7823
+ // specific use case. We may need to make this more sophisticated in
7824
+ // the future.
7825
+ // The trackedSignatures parameter supplies a list of function signatures
7826
+ // that were used for the function and the arguments passed to it. This is
7827
+ // important because the callable return value may be called again with
7828
+ // one of these signatures, so we may need to "uniquify" the type parameters
7829
+ // to avoid conflicts.
7830
+ function adjustCallableReturnType(returnType, trackedSignatures) {
7796
7831
  if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
7797
7832
  const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType);
7798
7833
  // If there are no unsolved type variables, we're done. If there are
7799
7834
  // unsolved type parameters, treat them as though they are rescoped
7800
7835
  // to the callable.
7801
7836
  if (typeVarsInReturnType.length > 0) {
7802
- return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, types_1.WildcardTypeVarScopeId, typeVarsInReturnType);
7837
+ return types_1.FunctionType.cloneWithNewTypeVarScopeId(returnType, types_1.WildcardTypeVarScopeId, typeVarsInReturnType, trackedSignatures);
7803
7838
  }
7804
7839
  }
7805
7840
  return returnType;
@@ -7837,12 +7872,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7837
7872
  return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, signatureContexts[0], conditionFilter);
7838
7873
  }
7839
7874
  const filteredSignatureContexts = [];
7875
+ const typeVarContexts = [];
7840
7876
  signatureContexts.forEach((context) => {
7841
7877
  // Use speculative mode to avoid emitting errors or caching types.
7842
7878
  useSpeculativeMode(errorNode, () => {
7843
- if (validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, conditionFilter)) {
7879
+ const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, context, conditionFilter);
7880
+ if (!paramSpecArgResult.argumentErrors) {
7844
7881
  filteredSignatureContexts.push(context);
7845
7882
  }
7883
+ (0, collectionUtils_1.appendArray)(typeVarContexts, paramSpecArgResult.typeVarContexts);
7846
7884
  });
7847
7885
  });
7848
7886
  // Copy back any compatible signature contexts if any were compatible.
@@ -7850,109 +7888,121 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7850
7888
  destTypeVarContext.copySignatureContexts(filteredSignatureContexts);
7851
7889
  }
7852
7890
  // Evaluate non-speculatively to produce a final result and cache types.
7853
- return validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0], conditionFilter);
7891
+ const paramSpecArgResult = validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, filteredSignatureContexts.length > 0 ? filteredSignatureContexts[0] : signatureContexts[0], conditionFilter);
7892
+ return { argumentErrors: paramSpecArgResult.argumentErrors, typeVarContexts };
7854
7893
  }
7855
7894
  function validateFunctionArgumentsForParamSpecSignature(errorNode, argList, paramSpec, typeVarContext, conditionFilter) {
7856
7895
  var _a;
7857
7896
  const paramSpecType = typeVarContext.getParamSpecType(paramSpec);
7858
7897
  if (!paramSpecType) {
7859
7898
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramSpecNotBound().format({ type: printType(paramSpec) }), ((_a = argList[0]) === null || _a === void 0 ? void 0 : _a.valueExpression) || errorNode);
7860
- return false;
7899
+ return { argumentErrors: true, typeVarContexts: [undefined] };
7861
7900
  }
7862
7901
  const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
7863
7902
  const srcTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(paramSpecType));
7864
7903
  let reportedArgError = false;
7865
- // Build a map of all named parameters.
7866
- const paramMap = new Map();
7867
- const paramSpecParams = paramSpecType.details.parameters;
7868
- paramSpecParams.forEach((param) => {
7869
- if (param.name) {
7870
- paramMap.set(param.name, param);
7871
- }
7872
- });
7873
- let positionalIndex = 0;
7874
- let positionalIndexLimit = paramSpecParams.findIndex((paramInfo) => paramInfo.category !== 0 /* Simple */);
7875
- if (positionalIndexLimit < 0) {
7876
- positionalIndexLimit = paramSpecParams.length;
7877
- }
7878
- const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
7879
- const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
7880
- const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7881
7904
  let sawUnpackedListArgument = false;
7882
7905
  let sawUnpackedDictArgument = false;
7883
- argList.forEach((arg) => {
7884
- var _a;
7885
- if (arg.argumentCategory === 0 /* Simple */) {
7886
- let paramType;
7887
- if (arg.name) {
7888
- const paramInfo = paramMap.get(arg.name.value);
7889
- if (paramInfo) {
7890
- paramType = paramInfo.type;
7891
- paramMap.delete(arg.name.value);
7892
- }
7893
- else if (kwargsParam) {
7894
- paramType = kwargsParam.type;
7895
- }
7896
- else {
7897
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramNameMissing().format({ name: arg.name.value }), arg.name || errorNode);
7898
- reportedArgError = true;
7906
+ let paramMap = new Map();
7907
+ // We'll use two passes in case there are type variables that depend
7908
+ // on later arguments.
7909
+ const passCount = 2;
7910
+ for (let i = 0; i < passCount; i++) {
7911
+ // Unless we're on the last pass, use speculative mode to suppress
7912
+ // any diagnostics.
7913
+ useSpeculativeMode(i < passCount - 1 ? errorNode : undefined, () => {
7914
+ // Build a map of all named parameters.
7915
+ paramMap = new Map();
7916
+ const paramSpecParams = paramSpecType.details.parameters;
7917
+ paramSpecParams.forEach((param) => {
7918
+ if (param.name) {
7919
+ paramMap.set(param.name, param);
7899
7920
  }
7900
- }
7901
- else {
7902
- if (positionalIndex < positionalIndexLimit) {
7903
- const paramInfo = paramSpecParams[positionalIndex];
7904
- paramType = paramInfo.type;
7905
- if (paramInfo.name) {
7906
- paramMap.delete(paramInfo.name);
7921
+ });
7922
+ let positionalIndex = 0;
7923
+ let positionalIndexLimit = paramSpecParams.findIndex((paramInfo) => paramInfo.category !== 0 /* Simple */);
7924
+ if (positionalIndexLimit < 0) {
7925
+ positionalIndexLimit = paramSpecParams.length;
7926
+ }
7927
+ const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
7928
+ const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
7929
+ const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
7930
+ argList.forEach((arg) => {
7931
+ var _a;
7932
+ if (arg.argumentCategory === 0 /* Simple */) {
7933
+ let paramType;
7934
+ if (arg.name) {
7935
+ const paramInfo = paramMap.get(arg.name.value);
7936
+ if (paramInfo) {
7937
+ paramType = paramInfo.type;
7938
+ paramMap.delete(arg.name.value);
7939
+ }
7940
+ else if (kwargsParam) {
7941
+ paramType = kwargsParam.type;
7942
+ }
7943
+ else {
7944
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.paramNameMissing().format({ name: arg.name.value }), arg.name || errorNode);
7945
+ reportedArgError = true;
7946
+ }
7947
+ }
7948
+ else {
7949
+ if (positionalIndex < positionalIndexLimit) {
7950
+ const paramInfo = paramSpecParams[positionalIndex];
7951
+ paramType = paramInfo.type;
7952
+ if (paramInfo.name) {
7953
+ paramMap.delete(paramInfo.name);
7954
+ }
7955
+ }
7956
+ else if (argsParam) {
7957
+ paramType = argsParam.type;
7958
+ }
7959
+ else {
7960
+ addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, paramSpecParams.length === 1
7961
+ ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
7962
+ : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
7963
+ expected: paramSpecParams.length,
7964
+ }), (_a = arg.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
7965
+ reportedArgError = true;
7966
+ }
7967
+ positionalIndex++;
7968
+ }
7969
+ if (paramType) {
7970
+ const argResult = validateArgType({
7971
+ paramCategory: 0 /* Simple */,
7972
+ paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes,
7973
+ /* usageOffset */ undefined),
7974
+ requiresTypeVarMatching: false,
7975
+ argument: arg,
7976
+ errorNode: arg.valueExpression || errorNode,
7977
+ }, srcTypeVarContext, signatureTracker,
7978
+ /* functionType */ undefined, { conditionFilter });
7979
+ if (!argResult.isCompatible) {
7980
+ reportedArgError = true;
7981
+ }
7907
7982
  }
7908
7983
  }
7909
- else if (argsParam) {
7910
- paramType = argsParam.type;
7984
+ else if (arg.argumentCategory === 1 /* UnpackedList */) {
7985
+ sawUnpackedListArgument = true;
7986
+ // See if there is an *args parameter.
7987
+ const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
7988
+ if (argsParam && paramMap.has(argsParam.name)) {
7989
+ // TODO - validate args type
7990
+ paramMap.delete(argsParam.name);
7991
+ }
7911
7992
  }
7912
7993
  else {
7913
- addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, paramSpecParams.length === 1
7914
- ? localize_1.Localizer.Diagnostic.argPositionalExpectedOne()
7915
- : localize_1.Localizer.Diagnostic.argPositionalExpectedCount().format({
7916
- expected: paramSpecParams.length,
7917
- }), (_a = arg.valueExpression) !== null && _a !== void 0 ? _a : errorNode);
7918
- reportedArgError = true;
7919
- }
7920
- positionalIndex++;
7921
- }
7922
- if (paramType) {
7923
- const argResult = validateArgType({
7924
- paramCategory: 0 /* Simple */,
7925
- paramType: (0, typeUtils_1.transformExpectedType)(paramType, liveTypeVarScopes, /* usageOffset */ undefined),
7926
- requiresTypeVarMatching: false,
7927
- argument: arg,
7928
- errorNode: arg.valueExpression || errorNode,
7929
- }, srcTypeVarContext, signatureTracker,
7930
- /* functionType */ undefined, { conditionFilter });
7931
- if (!argResult.isCompatible) {
7932
- reportedArgError = true;
7994
+ sawUnpackedDictArgument = true;
7995
+ (0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
7996
+ // See if there is an *kwargs parameter.
7997
+ const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
7998
+ if (kwargsParam && paramMap.has(kwargsParam.name)) {
7999
+ // TODO - validate kwargs type
8000
+ paramMap.delete(kwargsParam.name);
8001
+ }
7933
8002
  }
7934
- }
7935
- }
7936
- else if (arg.argumentCategory === 1 /* UnpackedList */) {
7937
- sawUnpackedListArgument = true;
7938
- // See if there is an *args parameter.
7939
- const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
7940
- if (argsParam && paramMap.has(argsParam.name)) {
7941
- // TODO - validate args type
7942
- paramMap.delete(argsParam.name);
7943
- }
7944
- }
7945
- else {
7946
- sawUnpackedDictArgument = true;
7947
- (0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
7948
- // See if there is an *kwargs parameter.
7949
- const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
7950
- if (kwargsParam && paramMap.has(kwargsParam.name)) {
7951
- // TODO - validate kwargs type
7952
- paramMap.delete(kwargsParam.name);
7953
- }
7954
- }
7955
- });
8003
+ });
8004
+ });
8005
+ }
7956
8006
  // Report any missing parameters.
7957
8007
  if (!reportedArgError) {
7958
8008
  let unassignedParams = Array.from(paramMap.keys());
@@ -7975,7 +8025,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
7975
8025
  if (!reportedArgError) {
7976
8026
  (0, typeUtils_1.applySourceContextTypeVarsToSignature)(typeVarContext, srcTypeVarContext);
7977
8027
  }
7978
- return !reportedArgError;
8028
+ return {
8029
+ argumentErrors: reportedArgError,
8030
+ typeVarContexts: [reportedArgError ? srcTypeVarContext : undefined],
8031
+ };
7979
8032
  }
7980
8033
  function validateArgType(argParam, typeVarContext, signatureTracker, typeResult, options) {
7981
8034
  var _a;
@@ -8759,7 +8812,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8759
8812
  if ((0, types_1.isClassInstance)(concreteSubtype)) {
8760
8813
  magicMethodType = (_a = getTypeOfObjectMember(errorNode, concreteSubtype, magicMethodName,
8761
8814
  /* usage */ undefined,
8762
- /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */, subtype)) === null || _a === void 0 ? void 0 : _a.type;
8815
+ /* diag */ undefined, 64 /* SkipAttributeAccessOverride */ | 1 /* AccessClassMembersOnly */)) === null || _a === void 0 ? void 0 : _a.type;
8763
8816
  }
8764
8817
  else if ((0, types_1.isInstantiableClass)(concreteSubtype)) {
8765
8818
  magicMethodType = (_b = getTypeOfClassMember(errorNode, concreteSubtype, magicMethodName,
@@ -10563,7 +10616,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10563
10616
  ['TypeAlias', { alias: '', module: 'builtins' }],
10564
10617
  ['Concatenate', { alias: '', module: 'builtins' }],
10565
10618
  ['TypeGuard', { alias: '', module: 'builtins' }],
10566
- ['StrictTypeGuard', { alias: '', module: 'builtins' }],
10567
10619
  ['Unpack', { alias: '', module: 'builtins' }],
10568
10620
  ['Required', { alias: '', module: 'builtins' }],
10569
10621
  ['NotRequired', { alias: '', module: 'builtins' }],
@@ -10573,7 +10625,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10573
10625
  ['LiteralString', { alias: '', module: 'builtins' }],
10574
10626
  ['ReadOnly', { alias: '', module: 'builtins' }],
10575
10627
  ]);
10576
- const aliasMapEntry = specialTypes.get(assignedName);
10628
+ let aliasMapEntry = specialTypes.get(assignedName);
10629
+ // Support ReadOnly only as an experimental feature.
10630
+ if (assignedName === 'ReadOnly' &&
10631
+ !AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
10632
+ aliasMapEntry = undefined;
10633
+ }
10577
10634
  if (aliasMapEntry) {
10578
10635
  const cachedType = readTypeCache(node, 0 /* None */);
10579
10636
  if (cachedType) {
@@ -12095,7 +12152,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12095
12152
  (0, typeUtils_1.addTypeVarsToListIfUnique)(typeParametersSeen, typeVarsInReturnType);
12096
12153
  // Note that the type parameters have been rescoped so they are not
12097
12154
  // considered valid for the body of this function.
12098
- functionType.details.rescopedTypeParameters = rescopedTypeVars;
12155
+ if (rescopedTypeVars.length > 0) {
12156
+ functionType.details.rescopedTypeParameters = rescopedTypeVars;
12157
+ }
12099
12158
  }
12100
12159
  function adjustParameterAnnotatedType(param, type) {
12101
12160
  var _a;
@@ -12240,16 +12299,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12240
12299
  }
12241
12300
  }
12242
12301
  function createAsyncFunction(node, functionType) {
12302
+ (0, debug_1.assert)(types_1.FunctionType.isAsync(functionType));
12243
12303
  // Clone the original function and replace its return type with an
12244
- // Awaitable[<returnType>].
12245
- const awaitableFunctionType = types_1.FunctionType.clone(functionType);
12304
+ // Awaitable[<returnType>]. Mark the new function as no longer async.
12305
+ const awaitableFunctionType = types_1.FunctionType.cloneWithNewFlags(functionType, functionType.details.flags & ~512 /* Async */);
12246
12306
  if (functionType.details.declaredReturnType) {
12247
12307
  awaitableFunctionType.details.declaredReturnType = createAwaitableReturnType(node, functionType.details.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
12248
12308
  }
12249
- // Note that the inferred type, once lazily computed, needs to wrap the
12250
- // resulting type in an awaitable.
12251
- functionType.details.flags |= 1024 /* WrapReturnTypeInAwait */;
12252
- awaitableFunctionType.details.flags |= 1024 /* WrapReturnTypeInAwait */;
12309
+ else {
12310
+ awaitableFunctionType.inferredReturnType = createAwaitableReturnType(node, getFunctionInferredReturnType(functionType), types_1.FunctionType.isGenerator(functionType));
12311
+ }
12253
12312
  return awaitableFunctionType;
12254
12313
  }
12255
12314
  function createAwaitableReturnType(node, returnType, isGenerator) {
@@ -12454,9 +12513,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12454
12513
  }
12455
12514
  return inferredReturnType ? { type: inferredReturnType, isIncomplete } : undefined;
12456
12515
  }
12457
- // Determines whether the function consists only of a "raise" statement
12458
- // and the exception type raised is a NotImplementedError. This is commonly
12459
- // used for abstract methods that
12516
+ // Determines whether the method consists only of a "raise" statement
12517
+ // and the exception type raised is a NotImplementedError or a subclass
12518
+ // thereof. This is commonly used for abstract methods.
12460
12519
  function methodAlwaysRaisesNotImplemented(functionDecl) {
12461
12520
  if (!functionDecl ||
12462
12521
  !functionDecl.isMethod ||
@@ -12475,7 +12534,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12475
12534
  : (0, types_1.isClassInstance)(raiseType)
12476
12535
  ? raiseType
12477
12536
  : undefined;
12478
- if (!classType || !types_1.ClassType.isBuiltIn(classType, 'NotImplementedError')) {
12537
+ if (!classType || !(0, typeUtils_1.derivesFromStdlibClass)(classType, 'NotImplementedError')) {
12479
12538
  return false;
12480
12539
  }
12481
12540
  }
@@ -13377,18 +13436,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
13377
13436
  case 'Concatenate': {
13378
13437
  return { type: createConcatenateType(errorNode, classType, typeArgs) };
13379
13438
  }
13380
- case 'TypeGuard':
13381
- case 'StrictTypeGuard': {
13439
+ case 'TypeGuard': {
13382
13440
  return { type: createTypeGuardType(errorNode, classType, typeArgs, flags) };
13383
13441
  }
13384
13442
  case 'Unpack': {
13385
13443
  return { type: createUnpackType(classType, errorNode, typeArgs, flags) };
13386
13444
  }
13387
13445
  case 'Required':
13388
- case 'NotRequired':
13389
- case 'ReadOnly': {
13446
+ case 'NotRequired': {
13390
13447
  return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
13391
13448
  }
13449
+ case 'ReadOnly': {
13450
+ if (AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.enableExperimentalFeatures) {
13451
+ return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
13452
+ }
13453
+ break;
13454
+ }
13392
13455
  case 'Self': {
13393
13456
  return { type: createSelfType(classType, errorNode, typeArgs) };
13394
13457
  }
@@ -14901,7 +14964,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14901
14964
  function getFunctionEffectiveReturnType(type, args, inferTypeIfNeeded = true) {
14902
14965
  const specializedReturnType = types_1.FunctionType.getSpecializedReturnType(type);
14903
14966
  if (specializedReturnType) {
14904
- return adjustCallableReturnType(specializedReturnType);
14967
+ return adjustCallableReturnType(specializedReturnType, /* trackedSignatures */ undefined);
14905
14968
  }
14906
14969
  if (inferTypeIfNeeded) {
14907
14970
  return getFunctionInferredReturnType(type, args);
@@ -14909,7 +14972,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14909
14972
  return types_1.UnknownType.create();
14910
14973
  }
14911
14974
  function getFunctionInferredReturnType(type, args) {
14912
- var _a;
14913
14975
  let returnType;
14914
14976
  let isIncomplete = false;
14915
14977
  let analyzeUnannotatedFunctions = true;
@@ -14956,10 +15018,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14956
15018
  if (returnTypeResult === null || returnTypeResult === void 0 ? void 0 : returnTypeResult.isIncomplete) {
14957
15019
  isIncomplete = true;
14958
15020
  }
14959
- // Do we need to wrap this in an awaitable?
14960
- if (returnType && types_1.FunctionType.isWrapReturnTypeInAwait(type)) {
14961
- returnType = createAwaitableReturnType(functionNode, returnType, !!((_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.isGenerator));
14962
- }
14963
15021
  }
14964
15022
  }
14965
15023
  }
@@ -14980,7 +15038,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14980
15038
  types_1.FunctionType.hasUnannotatedParams(type) &&
14981
15039
  !types_1.FunctionType.isStubDefinition(type) &&
14982
15040
  !types_1.FunctionType.isPyTypedDefinition(type) &&
14983
- !types_1.FunctionType.isWrapReturnTypeInAwait(type) &&
14984
15041
  args) {
14985
15042
  const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
14986
15043
  if (contextualReturnType) {
@@ -14990,7 +15047,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14990
15047
  return returnType;
14991
15048
  }
14992
15049
  function getFunctionInferredReturnTypeUsingArguments(type, args) {
14993
- var _a;
14994
15050
  let contextualReturnType;
14995
15051
  if (!type.details.declaration) {
14996
15052
  return undefined;
@@ -15102,10 +15158,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15102
15158
  });
15103
15159
  if (contextualReturnType) {
15104
15160
  contextualReturnType = (0, types_1.removeUnbound)(contextualReturnType);
15105
- // Do we need to wrap this in an awaitable?
15106
- if (types_1.FunctionType.isWrapReturnTypeInAwait(type) && !(0, types_1.isNever)(contextualReturnType)) {
15107
- contextualReturnType = createAwaitableReturnType(functionNode, contextualReturnType, !!((_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.isGenerator));
15108
- }
15109
15161
  if (!isResultFromCache) {
15110
15162
  // Cache the resulting type.
15111
15163
  if (!functionType.functionType.callSiteReturnTypeCache) {
@@ -15260,8 +15312,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15260
15312
  const typeVarContext = new typeVarContext_1.TypeVarContext();
15261
15313
  let isAssignable = true;
15262
15314
  destType.details.fields.forEach((symbol, name) => {
15263
- var _a;
15264
- if (!isAssignable || !symbol.isClassMember() || symbol.isIgnoredForProtocolMatch()) {
15315
+ if (!isAssignable || symbol.isIgnoredForProtocolMatch()) {
15265
15316
  return;
15266
15317
  }
15267
15318
  // Constructor methods are exempt from variance calculations.
@@ -15270,32 +15321,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15270
15321
  }
15271
15322
  const memberInfo = (0, typeUtils_1.lookUpClassMember)(srcType, name);
15272
15323
  (0, debug_1.assert)(memberInfo !== undefined);
15273
- let destMemberType = (_a = getDeclaredTypeOfSymbol(symbol)) === null || _a === void 0 ? void 0 : _a.type;
15274
- if (destMemberType) {
15275
- const srcMemberType = getTypeOfMember(memberInfo);
15276
- destMemberType = (0, typeUtils_1.partiallySpecializeType)(destMemberType, destType);
15277
- // Properties require special processing.
15278
- if ((0, types_1.isClassInstance)(destMemberType) &&
15279
- types_1.ClassType.isPropertyClass(destMemberType) &&
15280
- (0, types_1.isClassInstance)(srcMemberType) &&
15281
- types_1.ClassType.isPropertyClass(srcMemberType)) {
15282
- if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType, diag, typeVarContext,
15283
- /* selfTypeVarContext */ undefined, recursionCount)) {
15284
- isAssignable = false;
15285
- }
15324
+ let destMemberType = getEffectiveTypeOfSymbol(symbol);
15325
+ const srcMemberType = getTypeOfMember(memberInfo);
15326
+ destMemberType = (0, typeUtils_1.partiallySpecializeType)(destMemberType, destType);
15327
+ // Properties require special processing.
15328
+ if ((0, types_1.isClassInstance)(destMemberType) &&
15329
+ types_1.ClassType.isPropertyClass(destMemberType) &&
15330
+ (0, types_1.isClassInstance)(srcMemberType) &&
15331
+ types_1.ClassType.isPropertyClass(srcMemberType)) {
15332
+ if (!(0, properties_1.assignProperty)(evaluatorInterface, types_1.ClassType.cloneAsInstantiable(destMemberType), types_1.ClassType.cloneAsInstantiable(srcMemberType), destType, srcType, diag, typeVarContext,
15333
+ /* selfTypeVarContext */ undefined, recursionCount)) {
15334
+ isAssignable = false;
15286
15335
  }
15287
- else {
15288
- const primaryDecl = symbol.getDeclarations()[0];
15336
+ }
15337
+ else {
15338
+ const primaryDecl = symbol.getDeclarations()[0];
15339
+ let flags = 0 /* Default */;
15340
+ if ((primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ &&
15341
+ !isFinalVariableDeclaration(primaryDecl) &&
15342
+ !types_1.ClassType.isFrozenDataClass(destType)) {
15289
15343
  // Class and instance variables that are mutable need to
15290
- // enforce invariance.
15291
- const flags = (primaryDecl === null || primaryDecl === void 0 ? void 0 : primaryDecl.type) === 1 /* Variable */ && !isFinalVariableDeclaration(primaryDecl)
15292
- ? 1 /* EnforceInvariance */
15293
- : 0 /* Default */;
15294
- if (!assignType(destMemberType, srcMemberType, diag, typeVarContext,
15295
- /* srcTypeVarContext */ undefined, flags, recursionCount)) {
15296
- isAssignable = false;
15344
+ // enforce invariance. We will exempt variables that are
15345
+ // private or protected, since these are presumably
15346
+ // not modifiable outside of the class.
15347
+ if (!(0, symbolNameUtils_1.isPrivateOrProtectedName)(name)) {
15348
+ flags |= 1 /* EnforceInvariance */;
15297
15349
  }
15298
15350
  }
15351
+ if (!assignType(destMemberType, srcMemberType, diag, typeVarContext,
15352
+ /* srcTypeVarContext */ undefined, flags, recursionCount)) {
15353
+ isAssignable = false;
15354
+ }
15299
15355
  }
15300
15356
  });
15301
15357
  if (!isAssignable) {
@@ -15927,7 +15983,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15927
15983
  return !isLiteral;
15928
15984
  }
15929
15985
  }
15930
- else if (types_1.ClassType.isBuiltIn(destType, ['TypeGuard', 'StrictTypeGuard'])) {
15986
+ else if (types_1.ClassType.isBuiltIn(destType, 'TypeGuard')) {
15931
15987
  // All the source to be a "bool".
15932
15988
  if ((originalFlags & 64 /* AllowBoolTypeGuard */) !== 0) {
15933
15989
  if ((0, types_1.isClassInstance)(srcType) && types_1.ClassType.isBuiltIn(srcType, 'bool')) {
@@ -17068,7 +17124,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17068
17124
  // Handle the special case where the return type is a TypeGuard[T].
17069
17125
  // This should also act as a bool, since that's its type at runtime.
17070
17126
  if ((0, types_1.isClassInstance)(srcReturnType) &&
17071
- types_1.ClassType.isBuiltIn(srcReturnType, ['TypeGuard', 'StrictTypeGuard']) &&
17127
+ types_1.ClassType.isBuiltIn(srcReturnType, 'TypeGuard') &&
17072
17128
  boolClassType &&
17073
17129
  (0, types_1.isInstantiableClass)(boolClassType)) {
17074
17130
  if (assignType(destReturnType, types_1.ClassType.cloneAsInstance(boolClassType), returnDiag === null || returnDiag === void 0 ? void 0 : returnDiag.createAddendum(), destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
@@ -17118,7 +17174,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17118
17174
  const typeParam = assignedType.details.typeParameters[index];
17119
17175
  const expectedTypeArgType = typeVarContext.getPrimarySignature().getTypeVarType(typeParam);
17120
17176
  if (expectedTypeArgType) {
17121
- if ((0, types_1.isAny)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
17177
+ if ((0, typeUtils_1.containsAnyRecursive)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
17122
17178
  replacedTypeArg = true;
17123
17179
  return expectedTypeArgType;
17124
17180
  }
@@ -17145,12 +17201,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17145
17201
  const narrowedType = (0, typeUtils_1.mapSubtypes)(assignedType, (assignedSubtype) => {
17146
17202
  const narrowedSubtype = (0, typeUtils_1.mapSubtypes)(declaredType, (declaredSubtype) => {
17147
17203
  // We can't narrow "Any".
17148
- if ((0, types_1.isAnyOrUnknown)(declaredType)) {
17149
- return declaredType;
17204
+ if ((0, types_1.isAnyOrUnknown)(declaredSubtype)) {
17205
+ return declaredSubtype;
17150
17206
  }
17151
17207
  if (assignType(declaredSubtype, assignedSubtype)) {
17152
17208
  // If the source is generic and has unspecified type arguments,
17153
- // see if we can determine then based on the declared type.
17209
+ // see if we can determine them based on the declared type.
17154
17210
  if ((0, types_1.isInstantiableClass)(declaredSubtype) && (0, types_1.isInstantiableClass)(assignedSubtype)) {
17155
17211
  const result = replaceTypeArgsWithAny(node, declaredSubtype, assignedSubtype);
17156
17212
  if (result) {
@@ -17168,6 +17224,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17168
17224
  // use the concrete type.
17169
17225
  return declaredSubtype;
17170
17226
  }
17227
+ // If the assigned subtype is Any, stick with the declared type.
17228
+ if ((0, types_1.isAny)(assignedSubtype)) {
17229
+ return declaredSubtype;
17230
+ }
17231
+ // If the declared type doesn't contain any `Any` but the assigned
17232
+ // type does, stick with the declared type.
17233
+ if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype) && !(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
17234
+ return declaredSubtype;
17235
+ }
17171
17236
  return assignedSubtype;
17172
17237
  }
17173
17238
  return undefined;
@@ -17179,16 +17244,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17179
17244
  }
17180
17245
  return narrowedSubtype;
17181
17246
  });
17182
- // If the result of narrowing is Any, stick with the declared (unnarrowed) type.
17183
17247
  // If the result of narrowing is an Unknown that is incomplete, propagate the
17184
17248
  // incomplete type for the benefit of code flow analysis.
17185
17249
  // If the result of narrowing is a complete Unknown, combine the Unknown type
17186
17250
  // with the declared type. In strict mode, this will retain the "unknown type"
17187
17251
  // diagnostics while still providing reasonable completion suggestions.
17188
- if ((0, types_1.isAny)(narrowedType)) {
17189
- return declaredType;
17190
- }
17191
- else if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
17252
+ if ((0, typeUtils_1.isIncompleteUnknown)(narrowedType)) {
17192
17253
  return narrowedType;
17193
17254
  }
17194
17255
  else if ((0, types_1.isUnknown)(narrowedType)) {
@@ -17247,7 +17308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17247
17308
  /* exemptSelfClsParam */ false);
17248
17309
  });
17249
17310
  if (matchIndex < 0) {
17250
- diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex }));
17311
+ diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch().format({ index: overrideOverloadIndex + 1 }));
17251
17312
  return false;
17252
17313
  }
17253
17314
  if (matchIndex < previousMatchIndex) {
@@ -17406,7 +17467,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
17406
17467
  }
17407
17468
  else if (i < overrideParamDetails.positionOnlyParamCount &&
17408
17469
  i >= baseParamDetails.positionOnlyParamCount) {
17409
- if (!baseParam.isNameSynthesized) {
17470
+ if (!baseParam.isNameSynthesized &&
17471
+ baseParamDetails.params[i].source !== parameterUtils_1.ParameterSource.PositionOnly) {
17410
17472
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
17411
17473
  index: i + 1,
17412
17474
  baseName: baseParam.name || '*',