@zzzen/pyright-internal 1.2.0-dev.20240908 → 1.2.0-dev.20240915

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 (111) hide show
  1. package/dist/analyzer/analysis.d.ts +1 -0
  2. package/dist/analyzer/analysis.js +2 -0
  3. package/dist/analyzer/analysis.js.map +1 -1
  4. package/dist/analyzer/backgroundAnalysisProgram.js +6 -2
  5. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  6. package/dist/analyzer/cacheManager.d.ts +2 -2
  7. package/dist/analyzer/cacheManager.js.map +1 -1
  8. package/dist/analyzer/checker.js +30 -151
  9. package/dist/analyzer/checker.js.map +1 -1
  10. package/dist/analyzer/constraintSolver.d.ts +1 -2
  11. package/dist/analyzer/constraintSolver.js.map +1 -1
  12. package/dist/analyzer/patternMatching.js +3 -1
  13. package/dist/analyzer/patternMatching.js.map +1 -1
  14. package/dist/analyzer/program.js +2 -3
  15. package/dist/analyzer/program.js.map +1 -1
  16. package/dist/analyzer/properties.js.map +1 -1
  17. package/dist/analyzer/protocols.d.ts +1 -2
  18. package/dist/analyzer/protocols.js.map +1 -1
  19. package/dist/analyzer/pythonPathUtils.d.ts +1 -1
  20. package/dist/analyzer/service.d.ts +3 -1
  21. package/dist/analyzer/service.js +50 -33
  22. package/dist/analyzer/service.js.map +1 -1
  23. package/dist/analyzer/sourceMapper.js +8 -4
  24. package/dist/analyzer/sourceMapper.js.map +1 -1
  25. package/dist/analyzer/tuples.d.ts +1 -2
  26. package/dist/analyzer/tuples.js.map +1 -1
  27. package/dist/analyzer/typeEvaluator.js +103 -66
  28. package/dist/analyzer/typeEvaluator.js.map +1 -1
  29. package/dist/analyzer/typeEvaluatorTypes.d.ts +22 -1
  30. package/dist/analyzer/typeEvaluatorTypes.js +62 -1
  31. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  32. package/dist/analyzer/typeGuards.d.ts +3 -12
  33. package/dist/analyzer/typeGuards.js +276 -454
  34. package/dist/analyzer/typeGuards.js.map +1 -1
  35. package/dist/analyzer/typePrinter.d.ts +1 -2
  36. package/dist/analyzer/typePrinter.js +4 -24
  37. package/dist/analyzer/typePrinter.js.map +1 -1
  38. package/dist/analyzer/typeStubWriter.js +12 -1
  39. package/dist/analyzer/typeStubWriter.js.map +1 -1
  40. package/dist/analyzer/typeUtils.d.ts +0 -17
  41. package/dist/analyzer/typeUtils.js +7 -59
  42. package/dist/analyzer/typeUtils.js.map +1 -1
  43. package/dist/analyzer/typedDicts.d.ts +1 -2
  44. package/dist/analyzer/typedDicts.js.map +1 -1
  45. package/dist/analyzer/types.d.ts +1 -0
  46. package/dist/analyzer/types.js +12 -0
  47. package/dist/analyzer/types.js.map +1 -1
  48. package/dist/backgroundAnalysisBase.d.ts +23 -16
  49. package/dist/backgroundAnalysisBase.js +64 -35
  50. package/dist/backgroundAnalysisBase.js.map +1 -1
  51. package/dist/backgroundThreadBase.js +9 -0
  52. package/dist/backgroundThreadBase.js.map +1 -1
  53. package/dist/common/languageServerInterface.d.ts +1 -1
  54. package/dist/common/uri/uriUtils.d.ts +1 -1
  55. package/dist/common/uri/uriUtils.js +6 -1
  56. package/dist/common/uri/uriUtils.js.map +1 -1
  57. package/dist/languageServerBase.d.ts +2 -2
  58. package/dist/languageServerBase.js +1 -3
  59. package/dist/languageServerBase.js.map +1 -1
  60. package/dist/languageService/analyzerServiceExecutor.d.ts +6 -1
  61. package/dist/languageService/analyzerServiceExecutor.js +7 -6
  62. package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
  63. package/dist/languageService/fileWatcherDynamicFeature.d.ts +5 -1
  64. package/dist/languageService/fileWatcherDynamicFeature.js +12 -2
  65. package/dist/languageService/fileWatcherDynamicFeature.js.map +1 -1
  66. package/dist/localization/localize.d.ts +8 -0
  67. package/dist/localization/localize.js +2 -0
  68. package/dist/localization/localize.js.map +1 -1
  69. package/dist/localization/package.nls.cs.json +155 -153
  70. package/dist/localization/package.nls.de.json +128 -126
  71. package/dist/localization/package.nls.en-us.json +1632 -406
  72. package/dist/localization/package.nls.es.json +151 -149
  73. package/dist/localization/package.nls.fr.json +129 -127
  74. package/dist/localization/package.nls.it.json +143 -141
  75. package/dist/localization/package.nls.ja.json +142 -140
  76. package/dist/localization/package.nls.ko.json +155 -153
  77. package/dist/localization/package.nls.pl.json +178 -176
  78. package/dist/localization/package.nls.pt-br.json +139 -137
  79. package/dist/localization/package.nls.qps-ploc.json +392 -390
  80. package/dist/localization/package.nls.ru.json +170 -168
  81. package/dist/localization/package.nls.tr.json +153 -151
  82. package/dist/localization/package.nls.zh-cn.json +149 -147
  83. package/dist/localization/package.nls.zh-tw.json +133 -131
  84. package/dist/tests/checker.test.js +9 -0
  85. package/dist/tests/checker.test.js.map +1 -1
  86. package/dist/tests/envVarUtils.test.js +0 -3
  87. package/dist/tests/envVarUtils.test.js.map +1 -1
  88. package/dist/tests/harness/fourslash/testLanguageService.js +0 -3
  89. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  90. package/dist/tests/harness/fourslash/testState.js +2 -5
  91. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  92. package/dist/tests/harness/fourslash/testStateUtils.d.ts +1 -0
  93. package/dist/tests/harness/fourslash/testStateUtils.js +5 -0
  94. package/dist/tests/harness/fourslash/testStateUtils.js.map +1 -1
  95. package/dist/tests/harness/vfs/filesystem.d.ts +3 -2
  96. package/dist/tests/harness/vfs/filesystem.js +6 -3
  97. package/dist/tests/harness/vfs/filesystem.js.map +1 -1
  98. package/dist/tests/service.test.js +31 -0
  99. package/dist/tests/service.test.js.map +1 -1
  100. package/dist/tests/typeEvaluator1.test.js +4 -0
  101. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  102. package/dist/tests/typeEvaluator3.test.js +4 -0
  103. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  104. package/dist/tests/typeEvaluator6.test.js +5 -1
  105. package/dist/tests/typeEvaluator6.test.js.map +1 -1
  106. package/dist/tests/typeEvaluator7.test.js +1 -1
  107. package/dist/tests/typeEvaluator8.test.js +2 -2
  108. package/dist/workspaceFactory.d.ts +2 -20
  109. package/dist/workspaceFactory.js +19 -57
  110. package/dist/workspaceFactory.js.map +1 -1
  111. package/package.json +1 -1
@@ -567,6 +567,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
567
567
  };
568
568
  }
569
569
  }
570
+ if (inferenceContext) {
571
+ // Handle TypeForm assignments.
572
+ typeResult.type = convertToTypeFormType(inferenceContext.expectedType, typeResult.type);
573
+ }
570
574
  // Don't allow speculative caching for assignment expressions because
571
575
  // the target name node won't have a corresponding type cached speculatively.
572
576
  const allowSpeculativeCaching = node.nodeType !== 4 /* ParseNodeType.AssignmentExpression */;
@@ -2026,6 +2030,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2026
2030
  function getTupleClassType() {
2027
2031
  return tupleClass && (0, types_1.isInstantiableClass)(tupleClass) ? tupleClass : undefined;
2028
2032
  }
2033
+ function getDictClassType() {
2034
+ return dictClass && (0, types_1.isInstantiableClass)(dictClass) ? dictClass : undefined;
2035
+ }
2036
+ function getStrClassType() {
2037
+ return strClass && (0, types_1.isInstantiableClass)(strClass) ? strClass : undefined;
2038
+ }
2029
2039
  function getObjectType() {
2030
2040
  return objectClass ? (0, typeUtils_1.convertToInstance)(objectClass) : types_1.UnknownType.create();
2031
2041
  }
@@ -3185,7 +3195,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3185
3195
  }
3186
3196
  }
3187
3197
  if (((_b = type.props) === null || _b === void 0 ? void 0 : _b.typeAliasInfo) && types_1.TypeBase.isInstantiable(type)) {
3188
- type = types_1.TypeBase.cloneWithTypeForm(type, (0, typeUtils_1.convertToInstance)(specializeTypeAliasWithDefaults(type, /* errorNode */ undefined)));
3198
+ let typeFormType = type;
3199
+ if ((flags & 2 /* EvalFlags.NoSpecialize */) === 0) {
3200
+ typeFormType = specializeTypeAliasWithDefaults(typeFormType, /* errorNode */ undefined);
3201
+ }
3202
+ type = types_1.TypeBase.cloneWithTypeForm(type, (0, typeUtils_1.convertToInstance)(typeFormType));
3189
3203
  }
3190
3204
  return type;
3191
3205
  }
@@ -3654,6 +3668,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3654
3668
  }
3655
3669
  // Detect, report, and fill in missing type arguments if appropriate.
3656
3670
  typeResult.type = reportMissingTypeArgs(node, typeResult.type, flags);
3671
+ // Add TypeForm details if appropriate.
3672
+ typeResult.type = addTypeFormForSymbol(node, typeResult.type, flags, /* includesVarDecl */ false);
3657
3673
  }
3658
3674
  if (baseTypeResult.isIncomplete) {
3659
3675
  typeResult.isIncomplete = true;
@@ -3681,7 +3697,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3681
3697
  return typeResult;
3682
3698
  }
3683
3699
  function getTypeOfMemberAccessWithBaseType(node, baseTypeResult, usage, flags) {
3684
- var _a, _b, _c;
3700
+ var _a, _b, _c, _d;
3685
3701
  let baseType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(baseTypeResult.type);
3686
3702
  const memberName = node.d.member.d.value;
3687
3703
  let diag = new diagnostic_1.DiagnosticAddendum();
@@ -3694,12 +3710,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3694
3710
  const isRequired = false;
3695
3711
  const isNotRequired = false;
3696
3712
  let memberAccessDeprecationInfo;
3713
+ if ((_a = usage === null || usage === void 0 ? void 0 : usage.setType) === null || _a === void 0 ? void 0 : _a.isIncomplete) {
3714
+ isIncomplete = true;
3715
+ }
3697
3716
  // If the base type was incomplete and unbound, don't proceed
3698
3717
  // because false positive errors will be generated.
3699
3718
  if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
3700
3719
  return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
3701
3720
  }
3702
- if (((_a = baseType.props) === null || _a === void 0 ? void 0 : _a.specialForm) && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
3721
+ if (((_b = baseType.props) === null || _b === void 0 ? void 0 : _b.specialForm) && (flags & 256 /* EvalFlags.TypeExpression */) === 0) {
3703
3722
  baseType = baseType.props.specialForm;
3704
3723
  }
3705
3724
  if ((0, types_1.isParamSpec)(baseType) && baseType.priv.paramSpecAccess) {
@@ -3777,7 +3796,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3777
3796
  types_1.ClassType.isSameGenericClass(enumMemberResult.type, baseType) &&
3778
3797
  enumMemberResult.type.priv.literalValue !== undefined) {
3779
3798
  const diagMessage = usage.method === 'set' ? localize_1.LocMessage.enumMemberSet() : localize_1.LocMessage.enumMemberDelete();
3780
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.d.member, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node.d.member);
3799
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue, diagMessage.format({ name: memberName }) + diag.getString(), node.d.member, (_c = diag.getEffectiveTextRange()) !== null && _c !== void 0 ? _c : node.d.member);
3781
3800
  }
3782
3801
  }
3783
3802
  }
@@ -3980,7 +3999,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
3980
3999
  const rule = isFunctionRule
3981
4000
  ? diagnosticRules_1.DiagnosticRule.reportFunctionMemberAccess
3982
4001
  : diagnosticRules_1.DiagnosticRule.reportAttributeAccessIssue;
3983
- addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.d.member, (_c = diag.getEffectiveTextRange()) !== null && _c !== void 0 ? _c : node.d.member);
4002
+ addDiagnostic(rule, diagMessage.format({ name: memberName, type: printType(baseType) }) + diag.getString(), node.d.member, (_d = diag.getEffectiveTextRange()) !== null && _d !== void 0 ? _d : node.d.member);
3984
4003
  }
3985
4004
  // If this is member access on a function, use "Any" so if the
3986
4005
  // reportFunctionMemberAccess rule is disabled, we don't trigger
@@ -4830,13 +4849,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4830
4849
  // Handles index expressions that are providing type arguments for a
4831
4850
  // generic type alias.
4832
4851
  function createSpecializedTypeAlias(node, baseType, flags) {
4833
- var _a, _b, _c;
4834
- const aliasInfo = (_a = baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
4852
+ var _a, _b, _c, _d, _e, _f, _g;
4853
+ let aliasInfo = (_a = baseType.props) === null || _a === void 0 ? void 0 : _a.typeAliasInfo;
4854
+ let aliasBaseType = baseType;
4855
+ if (!aliasInfo && ((_b = baseType.props) === null || _b === void 0 ? void 0 : _b.typeForm)) {
4856
+ aliasInfo = (_d = (_c = baseType.props.typeForm) === null || _c === void 0 ? void 0 : _c.props) === null || _d === void 0 ? void 0 : _d.typeAliasInfo;
4857
+ aliasBaseType = (0, typeUtils_1.convertToInstantiable)(baseType.props.typeForm);
4858
+ }
4835
4859
  if (!(aliasInfo === null || aliasInfo === void 0 ? void 0 : aliasInfo.typeParams) || (aliasInfo.typeParams.length === 0 && aliasInfo.typeArgs)) {
4836
4860
  return undefined;
4837
4861
  }
4838
4862
  // If this is not instantiable, then the index expression isn't a specialization.
4839
- if (!types_1.TypeBase.isInstantiable(baseType)) {
4863
+ if (!types_1.TypeBase.isInstantiable(aliasBaseType)) {
4840
4864
  return undefined;
4841
4865
  }
4842
4866
  // If this is already specialized, the index expression isn't a specialization.
@@ -4868,7 +4892,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4868
4892
  }
4869
4893
  if (typeArgs.length > typeParams.length) {
4870
4894
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgsTooMany().format({
4871
- name: printType(baseType),
4895
+ name: printType(aliasBaseType),
4872
4896
  expected: typeParams.length,
4873
4897
  received: typeArgs.length,
4874
4898
  }), typeArgs[typeParams.length].node);
@@ -4876,15 +4900,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4876
4900
  }
4877
4901
  else if (typeArgs.length < minTypeArgCount) {
4878
4902
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeArgsTooFew().format({
4879
- name: printType(baseType),
4903
+ name: printType(aliasBaseType),
4880
4904
  expected: typeParams.length,
4881
4905
  received: typeArgs.length,
4882
4906
  }), node.d.items[node.d.items.length - 1]);
4883
4907
  reportedError = true;
4884
4908
  }
4885
4909
  // Handle the mypy_extensions.FlexibleAlias type specially.
4886
- if ((0, types_1.isInstantiableClass)(baseType) &&
4887
- baseType.shared.fullName === 'mypy_extensions.FlexibleAlias' &&
4910
+ if ((0, types_1.isInstantiableClass)(aliasBaseType) &&
4911
+ aliasBaseType.shared.fullName === 'mypy_extensions.FlexibleAlias' &&
4888
4912
  typeArgs.length >= 1) {
4889
4913
  return { node, type: typeArgs[0].type };
4890
4914
  }
@@ -4960,7 +4984,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4960
4984
  typeArgType = types_1.UnknownType.create();
4961
4985
  }
4962
4986
  if ((flags & 16384 /* EvalFlags.EnforceVarianceConsistency */) !== 0) {
4963
- const usageVariances = inferVarianceForTypeAlias(baseType);
4987
+ const usageVariances = inferVarianceForTypeAlias(aliasBaseType);
4964
4988
  if (usageVariances && index < usageVariances.length) {
4965
4989
  const usageVariance = usageVariances[index];
4966
4990
  if (!(0, typeUtils_1.isVarianceOfTypeArgCompatible)(typeArgType, usageVariance)) {
@@ -4983,12 +5007,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4983
5007
  }
4984
5008
  });
4985
5009
  if (!diag.isEmpty()) {
4986
- addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeNotSpecializable().format({ type: printType(baseType) }) + diag.getString(), node, (_b = diag.getEffectiveTextRange()) !== null && _b !== void 0 ? _b : node);
5010
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeNotSpecializable().format({ type: printType(aliasBaseType) }) + diag.getString(), node, (_e = diag.getEffectiveTextRange()) !== null && _e !== void 0 ? _e : node);
4987
5011
  reportedError = true;
4988
5012
  }
4989
5013
  const solutionSet = (0, constraintSolver_1.solveConstraints)(evaluatorInterface, constraints).getMainSolutionSet();
4990
5014
  const aliasTypeArgs = [];
4991
- (_c = aliasInfo.typeParams) === null || _c === void 0 ? void 0 : _c.forEach((typeParam) => {
5015
+ (_f = aliasInfo.typeParams) === null || _f === void 0 ? void 0 : _f.forEach((typeParam) => {
4992
5016
  let typeVarType = solutionSet.getType(typeParam);
4993
5017
  // Fill in any unsolved type arguments with unknown.
4994
5018
  if (!typeVarType) {
@@ -4997,14 +5021,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4997
5021
  }
4998
5022
  aliasTypeArgs.push(typeVarType);
4999
5023
  });
5000
- let type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(baseType, constraints), {
5024
+ let type = types_1.TypeBase.cloneForTypeAlias(solveAndApplyConstraints(aliasBaseType, constraints), {
5001
5025
  ...aliasInfo,
5002
5026
  typeArgs: aliasTypeArgs,
5003
5027
  });
5004
5028
  if (isTypeFormSupported(node)) {
5005
5029
  type = types_1.TypeBase.cloneWithTypeForm(type, reportedError ? undefined : (0, typeUtils_1.convertToInstance)(type));
5006
5030
  }
5007
- return { type, node };
5031
+ if ((_g = baseType.props) === null || _g === void 0 ? void 0 : _g.typeAliasInfo) {
5032
+ return { type, node };
5033
+ }
5034
+ return { type: types_1.TypeBase.cloneWithTypeForm(baseType, (0, typeUtils_1.convertToInstance)(type)), node };
5008
5035
  }
5009
5036
  function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
5010
5037
  var _a, _b, _c;
@@ -5826,7 +5853,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5826
5853
  }
5827
5854
  else if ((0, types_1.isClass)(baseTypeResult.type) && types_1.ClassType.isBuiltIn(baseTypeResult.type, 'TypeForm')) {
5828
5855
  // Handle the "typing.TypeForm" call.
5829
- typeResult = getTypeOfTypeForm(node);
5856
+ typeResult = getTypeOfTypeForm(node, baseTypeResult.type);
5830
5857
  }
5831
5858
  else if ((0, types_1.isAnyOrUnknown)(baseTypeResult.type) &&
5832
5859
  node.d.leftExpr.nodeType === 38 /* ParseNodeType.Name */ &&
@@ -5931,21 +5958,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5931
5958
  }
5932
5959
  return typeResult;
5933
5960
  }
5934
- function getTypeOfTypeForm(node) {
5961
+ function getTypeOfTypeForm(node, typeFormClass) {
5962
+ var _a;
5935
5963
  if (node.d.args.length !== 1 ||
5936
5964
  node.d.args[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
5937
5965
  node.d.args[0].d.name !== undefined) {
5938
5966
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportCallIssue, localize_1.LocMessage.typeFormArgs(), node);
5939
5967
  return { type: types_1.UnknownType.create() };
5940
5968
  }
5941
- return getTypeOfArgExpectingType((0, typeUtils_1.convertNodeToArg)(node.d.args[0]), {
5969
+ const typeFormResult = getTypeOfArgExpectingType((0, typeUtils_1.convertNodeToArg)(node.d.args[0]), {
5942
5970
  typeFormArg: isTypeFormSupported(node),
5943
5971
  noNonTypeSpecialForms: true,
5944
5972
  typeExpression: true,
5945
5973
  });
5974
+ if (!typeFormResult.typeErrors && ((_a = typeFormResult.type.props) === null || _a === void 0 ? void 0 : _a.typeForm)) {
5975
+ typeFormResult.type = (0, typeUtils_1.convertToInstance)(types_1.ClassType.specialize(typeFormClass, [(0, typeUtils_1.convertToInstance)(typeFormResult.type.props.typeForm)]));
5976
+ }
5977
+ return typeFormResult;
5946
5978
  }
5947
5979
  function getTypeOfAssertType(node, inferenceContext) {
5948
- var _a;
5949
5980
  if (node.d.args.length !== 2 ||
5950
5981
  node.d.args[0].d.argCategory !== 0 /* ArgCategory.Simple */ ||
5951
5982
  node.d.args[0].d.name !== undefined ||
@@ -5965,24 +5996,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
5965
5996
  // The spec is unclear on whether this is the correct behavior, but it seems to be
5966
5997
  // what mypy does -- and what various library authors expect.
5967
5998
  const arg0Type = stripTypeGuard(arg0TypeResult.type);
5968
- let assertSuccess = (0, types_1.isTypeSame)(assertedType, arg0Type, {
5999
+ if (!(0, types_1.isTypeSame)(assertedType, arg0Type, {
5969
6000
  treatAnySameAsUnknown: true,
5970
6001
  ignorePseudoGeneric: true,
5971
- });
5972
- // Handle TypeForm types specially.
5973
- if (!assertSuccess &&
5974
- ((_a = arg0Type.props) === null || _a === void 0 ? void 0 : _a.typeForm) &&
5975
- (0, types_1.isClassInstance)(assertedType) &&
5976
- types_1.ClassType.isBuiltIn(assertedType, 'TypeForm')) {
5977
- const typeFormType = assertedType.priv.typeArgs && assertedType.priv.typeArgs.length >= 1
5978
- ? assertedType.priv.typeArgs[0]
5979
- : types_1.UnknownType.create();
5980
- assertSuccess = (0, types_1.isTypeSame)(arg0Type.props.typeForm, typeFormType, {
5981
- treatAnySameAsUnknown: true,
5982
- ignorePseudoGeneric: true,
5983
- });
5984
- }
5985
- if (!assertSuccess) {
6002
+ })) {
5986
6003
  const srcDestTypes = printSrcDestTypes(arg0TypeResult.type, assertedType, { expandTypeAlias: true });
5987
6004
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportAssertTypeFailure, localize_1.LocMessage.assertTypeTypeMismatch().format({
5988
6005
  expected: srcDestTypes.destType,
@@ -7068,18 +7085,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
7068
7085
  if (expandedCallType.shared.name === 'type' && argList.length === 1) {
7069
7086
  const argType = getTypeOfArg(argList[0], /* inferenceContext */ undefined).type;
7070
7087
  const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
7071
- if ((0, types_1.isInstantiableClass)(subtype) && subtype.shared.effectiveMetaclass) {
7072
- return subtype.shared.effectiveMetaclass;
7073
- }
7074
7088
  if ((0, types_1.isNever)(subtype)) {
7075
7089
  return subtype;
7076
7090
  }
7091
+ if ((0, types_1.isClass)(subtype)) {
7092
+ return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
7093
+ }
7077
7094
  if (types_1.TypeBase.isInstance(subtype)) {
7078
- if ((0, types_1.isClass)(subtype) || (0, types_1.isTypeVar)(subtype)) {
7079
- return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
7080
- }
7081
- if ((0, types_1.isFunction)(subtype)) {
7082
- return types_1.FunctionType.cloneAsInstantiable(subtype);
7095
+ if ((0, types_1.isFunction)(subtype) || (0, types_1.isTypeVar)(subtype)) {
7096
+ return (0, typeUtils_1.convertToInstantiable)(subtype);
7083
7097
  }
7084
7098
  }
7085
7099
  return types_1.ClassType.specialize(types_1.ClassType.cloneAsInstance(expandedCallType), [
@@ -17046,6 +17060,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17046
17060
  // why two types are not the same.
17047
17061
  includeDiagAddendum = false;
17048
17062
  }
17063
+ // Special-case TypeForm to retain literals when solving TypeVars.
17064
+ if (types_1.ClassType.isBuiltIn(destType, 'TypeForm')) {
17065
+ effectiveFlags |= 256 /* AssignTypeFlags.RetainLiteralsForTypeVar */;
17066
+ }
17049
17067
  if (!assignType(variance === 4 /* Variance.Contravariant */ ? srcTypeArg : destTypeArg, variance === 4 /* Variance.Contravariant */ ? destTypeArg : srcTypeArg, assignmentDiag, constraints, effectiveFlags, recursionCount)) {
17050
17068
  // Don't report errors with type variables in "pseudo-random"
17051
17069
  // classes since these type variables are not real.
@@ -17154,6 +17172,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17154
17172
  flags |= 4 /* AssignTypeFlags.SkipRecursiveTypeCheck */;
17155
17173
  }
17156
17174
  }
17175
+ // If one or both of the types has an instantiable depth greater than
17176
+ // zero, convert both to instances first.
17177
+ if (types_1.TypeBase.isInstantiable(destType) && types_1.TypeBase.isInstantiable(srcType)) {
17178
+ if (types_1.TypeBase.getInstantiableDepth(destType) > 0 || types_1.TypeBase.getInstantiableDepth(srcType) > 0) {
17179
+ return assignType((0, typeUtils_1.convertToInstance)(destType), (0, typeUtils_1.convertToInstance)(srcType), diag, constraints, flags, recursionCount);
17180
+ }
17181
+ }
17157
17182
  // Transform recursive type aliases if necessary.
17158
17183
  const transformedDestType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(destType);
17159
17184
  const transformedSrcType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(srcType);
@@ -17179,10 +17204,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17179
17204
  if ((0, types_1.isUnbound)(destType) || (0, types_1.isUnbound)(srcType)) {
17180
17205
  return true;
17181
17206
  }
17182
- // Handle TypeForm assignments.
17183
- if (assignToTypeFormType(destType, srcType, constraints, flags, recursionCount)) {
17184
- return true;
17185
- }
17186
17207
  if ((0, types_1.isTypeVar)(destType)) {
17187
17208
  if ((0, typeUtils_1.isTypeVarSame)(destType, srcType)) {
17188
17209
  return true;
@@ -17327,7 +17348,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17327
17348
  // If both the source and dest are unions, use assignFromUnionType which has
17328
17349
  // special-case logic to handle this case.
17329
17350
  if ((0, types_1.isUnion)(srcType)) {
17330
- return assignFromUnionType(destType, srcType, /* diag */ undefined, constraints, flags, recursionCount);
17351
+ return assignFromUnionType(destType, srcType, diag, constraints, flags, recursionCount);
17331
17352
  }
17332
17353
  const clonedConstraints = constraints === null || constraints === void 0 ? void 0 : constraints.clone();
17333
17354
  if (assignToUnionType(destType, srcType, /* diag */ undefined, clonedConstraints, flags, recursionCount)) {
@@ -17372,7 +17393,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17372
17393
  // PEP 544 says that if the dest type is a type[Proto] class,
17373
17394
  // the source must be a "concrete" (non-protocol) class.
17374
17395
  if (types_1.ClassType.isProtocolClass(destType)) {
17375
- if (types_1.ClassType.isProtocolClass(expandedSrcType) &&
17396
+ if ((flags & 65536 /* AssignTypeFlags.AllowProtocolClassSource */) === 0 &&
17397
+ types_1.ClassType.isProtocolClass(expandedSrcType) &&
17376
17398
  (0, types_1.isInstantiableClass)(srcType) &&
17377
17399
  !srcType.priv.includeSubclasses) {
17378
17400
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.protocolSourceIsNotConcrete().format({
@@ -17416,7 +17438,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17416
17438
  }
17417
17439
  if ((0, types_1.isClassInstance)(destType)) {
17418
17440
  if (types_1.ClassType.isBuiltIn(destType, 'type')) {
17419
- if ((0, types_1.isInstantiableClass)(srcType) && isSpecialFormClass(srcType, flags)) {
17441
+ if ((0, types_1.isInstantiableClass)(srcType) &&
17442
+ isSpecialFormClass(srcType, flags) &&
17443
+ types_1.TypeBase.getInstantiableDepth(srcType) === 0) {
17420
17444
  return false;
17421
17445
  }
17422
17446
  if ((0, types_1.isAnyOrUnknown)(srcType) && (flags & 16 /* AssignTypeFlags.OverloadOverlap */) !== 0) {
@@ -17652,20 +17676,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17652
17676
  diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.typeAssignmentMismatch().format(printSrcDestTypes(srcType, destType)));
17653
17677
  return false;
17654
17678
  }
17655
- // If the destination type is an explicit TypeForm type, see if the source
17656
- // type has an implicit TypeForm type that can be assigned to it. Also see
17657
- // of the source is a type[T] type that is assignable.
17658
- function assignToTypeFormType(destType, srcType, constraints, flags, recursionCount) {
17659
- var _a, _b;
17660
- if (!(0, types_1.isClassInstance)(destType) || !types_1.ClassType.isBuiltIn(destType, 'TypeForm')) {
17661
- return false;
17679
+ // If the expected type is an explicit TypeForm type, see if the source
17680
+ // type has an implicit TypeForm type that can be assigned to it. If so,
17681
+ // convert to an explicit TypeForm type.
17682
+ function convertToTypeFormType(expectedType, srcType) {
17683
+ var _a, _b, _c;
17684
+ // Is the source is a TypeForm type?
17685
+ if (!((_a = srcType.props) === null || _a === void 0 ? void 0 : _a.typeForm)) {
17686
+ return srcType;
17662
17687
  }
17663
- const destTypeFormType = destType.priv.typeArgs && destType.priv.typeArgs.length > 0
17664
- ? destType.priv.typeArgs[0]
17665
- : types_1.UnknownType.create();
17666
17688
  let srcTypeFormType;
17667
17689
  // Is the source is a TypeForm type?
17668
- if ((_a = srcType.props) === null || _a === void 0 ? void 0 : _a.typeForm) {
17690
+ if ((_b = srcType.props) === null || _b === void 0 ? void 0 : _b.typeForm) {
17669
17691
  srcTypeFormType = srcType.props.typeForm;
17670
17692
  }
17671
17693
  else if ((0, types_1.isClass)(srcType)) {
@@ -17676,7 +17698,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17676
17698
  }
17677
17699
  else if (types_1.ClassType.isBuiltIn(srcType, 'type')) {
17678
17700
  srcTypeFormType =
17679
- ((_b = srcType.priv.typeArgs) === null || _b === void 0 ? void 0 : _b.length) && srcType.priv.typeArgs.length > 0
17701
+ ((_c = srcType.priv.typeArgs) === null || _c === void 0 ? void 0 : _c.length) && srcType.priv.typeArgs.length > 0
17680
17702
  ? srcType.priv.typeArgs[0]
17681
17703
  : types_1.UnknownType.create();
17682
17704
  }
@@ -17687,9 +17709,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17687
17709
  }
17688
17710
  }
17689
17711
  if (!srcTypeFormType) {
17690
- return false;
17712
+ return srcType;
17691
17713
  }
17692
- return assignType(destTypeFormType, srcTypeFormType, /* diag */ undefined, constraints, flags, recursionCount);
17714
+ let resultType;
17715
+ (0, typeUtils_1.doForEachSubtype)(expectedType, (subtype) => {
17716
+ if (resultType || !(0, types_1.isClassInstance)(subtype) || !types_1.ClassType.isBuiltIn(subtype, 'TypeForm')) {
17717
+ return;
17718
+ }
17719
+ const destTypeFormType = subtype.priv.typeArgs && subtype.priv.typeArgs.length > 0
17720
+ ? subtype.priv.typeArgs[0]
17721
+ : types_1.UnknownType.create();
17722
+ if (assignType(destTypeFormType, srcTypeFormType)) {
17723
+ resultType = types_1.ClassType.specialize(subtype, [srcTypeFormType]);
17724
+ }
17725
+ });
17726
+ return resultType !== null && resultType !== void 0 ? resultType : srcType;
17693
17727
  }
17694
17728
  function assignFromUnionType(destType, srcType, diag, constraints, flags, recursionCount) {
17695
17729
  // Start by checking for an exact match. This is needed to handle unions
@@ -19830,6 +19864,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19830
19864
  getBoundMagicMethod,
19831
19865
  getTypeOfMagicMethodCall,
19832
19866
  bindFunctionToClassOrObject,
19867
+ getCallbackProtocolType,
19833
19868
  getCallSignatureInfo,
19834
19869
  getAbstractSymbols,
19835
19870
  narrowConstrainedTypeVar,
@@ -19841,6 +19876,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19841
19876
  assignClassToSelf,
19842
19877
  getTypedDictClassType,
19843
19878
  getTupleClassType,
19879
+ getDictClassType,
19880
+ getStrClassType,
19844
19881
  getObjectType,
19845
19882
  getNoneType,
19846
19883
  getUnionClassType,