@zzzen/pyright-internal 1.2.0-dev.20231022 → 1.2.0-dev.20231029

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 (129) hide show
  1. package/dist/analyzer/backgroundAnalysisProgram.d.ts +3 -4
  2. package/dist/analyzer/backgroundAnalysisProgram.js +6 -3
  3. package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
  4. package/dist/analyzer/binder.js +1 -6
  5. package/dist/analyzer/binder.js.map +1 -1
  6. package/dist/analyzer/cacheManager.d.ts +3 -0
  7. package/dist/analyzer/cacheManager.js +11 -0
  8. package/dist/analyzer/cacheManager.js.map +1 -1
  9. package/dist/analyzer/codeFlowEngine.d.ts +0 -1
  10. package/dist/analyzer/codeFlowEngine.js +1 -1
  11. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  12. package/dist/analyzer/constraintSolver.js +9 -6
  13. package/dist/analyzer/constraintSolver.js.map +1 -1
  14. package/dist/analyzer/importResolver.d.ts +5 -2
  15. package/dist/analyzer/importResolver.js +40 -5
  16. package/dist/analyzer/importResolver.js.map +1 -1
  17. package/dist/analyzer/parseTreeUtils.d.ts +1 -0
  18. package/dist/analyzer/parseTreeUtils.js +11 -2
  19. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  20. package/dist/analyzer/program.d.ts +2 -3
  21. package/dist/analyzer/program.js +14 -24
  22. package/dist/analyzer/program.js.map +1 -1
  23. package/dist/analyzer/protocols.js +24 -6
  24. package/dist/analyzer/protocols.js.map +1 -1
  25. package/dist/analyzer/service.d.ts +1 -2
  26. package/dist/analyzer/service.js +5 -2
  27. package/dist/analyzer/service.js.map +1 -1
  28. package/dist/analyzer/sourceFile.d.ts +0 -1
  29. package/dist/analyzer/sourceFile.js +0 -9
  30. package/dist/analyzer/sourceFile.js.map +1 -1
  31. package/dist/analyzer/sourceFileInfo.d.ts +0 -4
  32. package/dist/analyzer/sourceFileInfo.js +0 -9
  33. package/dist/analyzer/sourceFileInfo.js.map +1 -1
  34. package/dist/analyzer/typeEvaluator.js +119 -84
  35. package/dist/analyzer/typeEvaluator.js.map +1 -1
  36. package/dist/analyzer/typeEvaluatorTypes.d.ts +1 -0
  37. package/dist/analyzer/typeEvaluatorTypes.js +3 -0
  38. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  39. package/dist/analyzer/typedDicts.js +7 -7
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +2 -3
  42. package/dist/analyzer/types.js +4 -10
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.d.ts +3 -1
  45. package/dist/backgroundAnalysisBase.js +27 -0
  46. package/dist/backgroundAnalysisBase.js.map +1 -1
  47. package/dist/common/fullAccessHost.js +16 -1
  48. package/dist/common/fullAccessHost.js.map +1 -1
  49. package/dist/common/pathUtils.d.ts +1 -1
  50. package/dist/common/pathUtils.js +8 -2
  51. package/dist/common/pathUtils.js.map +1 -1
  52. package/dist/common/realFileSystem.js +11 -8
  53. package/dist/common/realFileSystem.js.map +1 -1
  54. package/dist/common/serviceProviderExtensions.d.ts +2 -0
  55. package/dist/common/serviceProviderExtensions.js +5 -0
  56. package/dist/common/serviceProviderExtensions.js.map +1 -1
  57. package/dist/languageServerBase.d.ts +2 -4
  58. package/dist/languageServerBase.js +2 -5
  59. package/dist/languageServerBase.js.map +1 -1
  60. package/dist/languageService/documentSymbolCollector.d.ts +7 -0
  61. package/dist/languageService/documentSymbolCollector.js +28 -3
  62. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  63. package/dist/localization/localize.js +2 -0
  64. package/dist/localization/localize.js.map +1 -1
  65. package/dist/localization/package.nls.cs.json +1 -0
  66. package/dist/localization/package.nls.de.json +1 -0
  67. package/dist/localization/package.nls.es.json +1 -0
  68. package/dist/localization/package.nls.fr.json +1 -0
  69. package/dist/localization/package.nls.it.json +1 -0
  70. package/dist/localization/package.nls.ja.json +1 -0
  71. package/dist/localization/package.nls.ko.json +1 -0
  72. package/dist/localization/package.nls.pl.json +1 -0
  73. package/dist/localization/package.nls.pt-br.json +1 -0
  74. package/dist/localization/package.nls.qps-ploc.json +1 -0
  75. package/dist/localization/package.nls.ru.json +1 -0
  76. package/dist/localization/package.nls.tr.json +1 -0
  77. package/dist/localization/package.nls.zh-cn.json +1 -0
  78. package/dist/localization/package.nls.zh-tw.json +1 -0
  79. package/dist/server.js +3 -1
  80. package/dist/server.js.map +1 -1
  81. package/dist/tests/fourslash/completions.importInterimFile.fourslash.js +46 -0
  82. package/dist/tests/fourslash/completions.importInterimFile.fourslash.js.map +1 -0
  83. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js +4 -0
  84. package/dist/tests/fourslash/completions.wildcardimports.fourslash.js.map +1 -1
  85. package/dist/tests/fourslash/findDefinitions.classes.fourslash.js +4 -0
  86. package/dist/tests/fourslash/findDefinitions.classes.fourslash.js.map +1 -1
  87. package/dist/tests/fourslash/findDefinitions.fields.fourslash.js +4 -0
  88. package/dist/tests/fourslash/findDefinitions.fields.fourslash.js.map +1 -1
  89. package/dist/tests/fourslash/findDefinitions.functions.fourslash.js +4 -0
  90. package/dist/tests/fourslash/findDefinitions.functions.fourslash.js.map +1 -1
  91. package/dist/tests/fourslash/findDefinitions.methods.fourslash.js +4 -0
  92. package/dist/tests/fourslash/findDefinitions.methods.fourslash.js.map +1 -1
  93. package/dist/tests/fourslash/findDefinitions.parameters.fourslash.js +4 -0
  94. package/dist/tests/fourslash/findDefinitions.parameters.fourslash.js.map +1 -1
  95. package/dist/tests/fourslash/findDefinitions.variables.fourslash.js +4 -0
  96. package/dist/tests/fourslash/findDefinitions.variables.fourslash.js.map +1 -1
  97. package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.js +4 -0
  98. package/dist/tests/fourslash/findDefinitions.wildcardimports.fourslash.js.map +1 -1
  99. package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.js +4 -0
  100. package/dist/tests/fourslash/findTypeDefinitions.classes.fourslash.js.map +1 -1
  101. package/dist/tests/fourslash/fourslash.d.ts +4 -1
  102. package/dist/tests/fourslash/hover.class.docString.fourslash.js +4 -0
  103. package/dist/tests/fourslash/hover.class.docString.fourslash.js.map +1 -1
  104. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js +4 -0
  105. package/dist/tests/fourslash/hover.docFromSrc.fourslash.js.map +1 -1
  106. package/dist/tests/fourslash/hover.docFromSrc.stringFormat.fourslash.d.ts +1 -0
  107. package/dist/tests/fourslash/{hover.docFromScr.stringFormat.fourslash.js → hover.docFromSrc.stringFormat.fourslash.js} +1 -1
  108. package/dist/tests/fourslash/{hover.docFromScr.stringFormat.fourslash.js.map → hover.docFromSrc.stringFormat.fourslash.js.map} +1 -1
  109. package/dist/tests/fourslash/hover.unpackedTypedDict.key.fourslash.d.ts +1 -0
  110. package/dist/tests/fourslash/hover.unpackedTypedDict.key.fourslash.js +24 -0
  111. package/dist/tests/fourslash/hover.unpackedTypedDict.key.fourslash.js.map +1 -0
  112. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js +4 -0
  113. package/dist/tests/fourslash/hover.wildcardimports.fourslash.js.map +1 -1
  114. package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js +4 -0
  115. package/dist/tests/fourslash/signature.docstrings.wildcardimports.fourslash.js.map +1 -1
  116. package/dist/tests/harness/fourslash/testLanguageService.js +2 -2
  117. package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
  118. package/dist/tests/harness/fourslash/testState.d.ts +7 -5
  119. package/dist/tests/harness/fourslash/testState.js +25 -10
  120. package/dist/tests/harness/fourslash/testState.js.map +1 -1
  121. package/dist/tests/ipythonMode.test.js +0 -31
  122. package/dist/tests/ipythonMode.test.js.map +1 -1
  123. package/dist/tests/pathUtils.test.js +18 -0
  124. package/dist/tests/pathUtils.test.js.map +1 -1
  125. package/dist/tests/typeEvaluator2.test.js +1 -1
  126. package/dist/tests/typeEvaluator4.test.js +1 -1
  127. package/dist/tests/typeEvaluator5.test.js +1 -1
  128. package/package.json +1 -1
  129. /package/dist/tests/fourslash/{hover.docFromScr.stringFormat.fourslash.d.ts → completions.importInterimFile.fourslash.d.ts} +0 -0
@@ -1935,9 +1935,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1935
1935
  const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode,
1936
1936
  /* reference */ undefined,
1937
1937
  /* targetSymbolId */ undefined,
1938
- /* typeAtStart */ types_1.UnboundType.create(), {
1939
- skipNoReturnCallAnalysis: true,
1940
- });
1938
+ /* typeAtStart */ types_1.UnboundType.create());
1941
1939
  return codeFlowResult.type !== undefined && !(0, types_1.isNever)(codeFlowResult.type);
1942
1940
  }
1943
1941
  // Determines whether there is a code flow path from sourceNode to sinkNode.
@@ -2871,7 +2869,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2871
2869
  return undefined;
2872
2870
  }
2873
2871
  function getTypeOfName(node, flags) {
2874
- var _a;
2875
2872
  const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
2876
2873
  const name = node.value;
2877
2874
  let symbol;
@@ -3019,29 +3016,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3019
3016
  type = types_1.UnknownType.create();
3020
3017
  }
3021
3018
  }
3022
- if ((0, types_1.isTypeVar)(type) &&
3023
- !type.details.isParamSpec &&
3024
- !type.isVariadicInUnion &&
3025
- (flags & 128 /* ExpectingInstantiableType */) === 0 &&
3026
- type.details.name === name) {
3027
- // Handle the special case of a PEP 604 union. These can appear within
3028
- // an implied type alias where we are not expecting a type.
3029
- const isPep604Union = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 7 /* BinaryOperation */ &&
3030
- node.parent.operator === 6 /* BitwiseOr */;
3031
- if (!isPep604Union) {
3032
- // A TypeVar in contexts where we're not expecting a type is
3033
- // simply a TypeVar or TypeVarTuple object.
3034
- const typeVarType = type.details.isVariadic
3035
- ? getTypingType(node, 'TypeVarTuple')
3036
- : getTypingType(node, 'TypeVar');
3037
- if (typeVarType && (0, types_1.isInstantiableClass)(typeVarType)) {
3038
- type = types_1.ClassType.cloneAsInstance(typeVarType);
3039
- }
3040
- else {
3041
- type = types_1.UnknownType.create();
3042
- }
3043
- }
3044
- }
3019
+ type = convertTypeVarToRuntimeInstance(node, type, flags);
3045
3020
  if ((flags & 256 /* ExpectingTypeAnnotation */) === 0) {
3046
3021
  reportUseOfTypeCheckOnly(type, node);
3047
3022
  }
@@ -3062,6 +3037,37 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3062
3037
  }
3063
3038
  return { type, isIncomplete };
3064
3039
  }
3040
+ // If the type is a TypeVar and we're not expecting a type, convert
3041
+ // a TypeVar or TypeVarTuple into a runtime type. We don't currently
3042
+ // do this for ParamSpec (although we arguably should) because it's
3043
+ // problematic for handling P.args and P.kwargs.
3044
+ function convertTypeVarToRuntimeInstance(node, type, flags) {
3045
+ var _a;
3046
+ if (node.nodeType === 38 /* Name */ &&
3047
+ (0, types_1.isTypeVar)(type) &&
3048
+ node.value === type.details.name &&
3049
+ !type.isVariadicInUnion &&
3050
+ (flags & 128 /* ExpectingInstantiableType */) === 0) {
3051
+ if ((flags & 33554432 /* SkipConvertParamSpecToRuntimeObject */) !== 0 && type.details.isParamSpec) {
3052
+ return type;
3053
+ }
3054
+ // Handle the special case of a PEP 604 union. These can appear within
3055
+ // an implied type alias where we are not expecting a type.
3056
+ const isPep604Union = ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 7 /* BinaryOperation */ &&
3057
+ node.parent.operator === 6 /* BitwiseOr */;
3058
+ if (!isPep604Union) {
3059
+ // A TypeVar in contexts where we're not expecting a type is
3060
+ // simply a runtime object.
3061
+ if (type.details.runtimeClass) {
3062
+ type = types_1.ClassType.cloneAsInstance(type.details.runtimeClass);
3063
+ }
3064
+ else {
3065
+ type = types_1.UnknownType.create();
3066
+ }
3067
+ }
3068
+ }
3069
+ return type;
3070
+ }
3065
3071
  // Handles the case where a variable or parameter is defined in an outer
3066
3072
  // scope and captured by an inner scope (either a function or a lambda).
3067
3073
  function getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType) {
@@ -3387,15 +3393,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3387
3393
  return { type, isRescoped: false, foundInterveningClass: false };
3388
3394
  }
3389
3395
  function getTypeOfMemberAccess(node, flags) {
3390
- const baseTypeFlags = 16777218 /* MemberAccessBaseDefaults */ |
3391
- (flags &
3396
+ // Compute flags specifically for evaluating the left expression.
3397
+ let leftExprFlags = 16777218 /* MemberAccessBaseDefaults */;
3398
+ leftExprFlags |=
3399
+ flags &
3392
3400
  (256 /* ExpectingTypeAnnotation */ |
3393
3401
  32768 /* VariableTypeAnnotation */ |
3394
3402
  4 /* AllowForwardReferences */ |
3395
3403
  524288 /* NotParsedByInterpreter */ |
3396
3404
  2048 /* DisallowTypeVarsWithScopeId */ |
3397
- 8192 /* AssociateTypeVarsWithCurrentScope */));
3398
- const baseTypeResult = getTypeOfExpression(node.leftExpression, baseTypeFlags);
3405
+ 8192 /* AssociateTypeVarsWithCurrentScope */);
3406
+ // Handle special casing for ParamSpec "args" and "kwargs" accesses.
3407
+ if ((flags & 128 /* ExpectingInstantiableType */) !== 0) {
3408
+ const memberName = node.memberName.value;
3409
+ if (memberName === 'args' || memberName === 'kwargs') {
3410
+ leftExprFlags |= 33554432 /* SkipConvertParamSpecToRuntimeObject */;
3411
+ }
3412
+ }
3413
+ const baseTypeResult = getTypeOfExpression(node.leftExpression, leftExprFlags);
3399
3414
  if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
3400
3415
  return {
3401
3416
  type: types_1.UnknownType.create(/* isIncomplete */ true),
@@ -5531,7 +5546,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
5531
5546
  else {
5532
5547
  baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */ | (flags & 4 /* AllowForwardReferences */));
5533
5548
  }
5534
- const argList = node.arguments.map((arg) => {
5549
+ const argList = ParseTreeUtils.getArgumentsByRuntimeOrder(node).map((arg) => {
5535
5550
  const functionArg = {
5536
5551
  valueExpression: arg.valueExpression,
5537
5552
  argumentCategory: arg.argumentCategory,
@@ -8455,7 +8470,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8455
8470
  else {
8456
8471
  addError(localize_1.Localizer.Diagnostic.typeVarFirstArg(), firstArg.valueExpression || errorNode);
8457
8472
  }
8458
- const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false);
8473
+ const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false, classType);
8459
8474
  // Parse the remaining parameters.
8460
8475
  const paramNameMap = new Map();
8461
8476
  for (let i = 1; i < argList.length; i++) {
@@ -8581,7 +8596,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8581
8596
  else {
8582
8597
  addError(localize_1.Localizer.Diagnostic.typeVarFirstArg(), firstArg.valueExpression || errorNode);
8583
8598
  }
8584
- const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false);
8599
+ const typeVar = types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false, classType);
8585
8600
  typeVar.details.isVariadic = true;
8586
8601
  // Parse the remaining parameters.
8587
8602
  for (let i = 1; i < argList.length; i++) {
@@ -8633,7 +8648,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
8633
8648
  else {
8634
8649
  addError(localize_1.Localizer.Diagnostic.paramSpecFirstArg(), firstArg.valueExpression || errorNode);
8635
8650
  }
8636
- const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true);
8651
+ const paramSpec = types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true, classType);
8637
8652
  // Parse the remaining parameters.
8638
8653
  for (let i = 1; i < argList.length; i++) {
8639
8654
  const paramNameNode = argList[i].name;
@@ -9618,12 +9633,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9618
9633
  return { type: returnedType };
9619
9634
  }
9620
9635
  function getTypeOfLambda(node, inferenceContext) {
9621
- let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
9622
- const functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* PartiallyEvaluated */);
9623
- functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
9624
- // Pre-cache the incomplete function type in case the evaluation of the
9625
- // lambda depends on itself.
9626
- writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* None */);
9627
9636
  let expectedFunctionTypes = [];
9628
9637
  if (inferenceContext) {
9629
9638
  (0, typeUtils_1.mapSubtypes)(inferenceContext.expectedType, (subtype) => {
@@ -9638,25 +9647,34 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9638
9647
  }
9639
9648
  return undefined;
9640
9649
  });
9641
- // Determine the minimum number of parameters that are required to
9642
- // satisfy the lambda.
9643
- const minLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && !!param.name && param.defaultValue === undefined).length;
9644
- const maxLambdaParamCount = node.parameters.filter((param) => param.category === 0 /* Simple */ && !!param.name).length;
9645
- // Remove any expected subtypes that don't satisfy the minimum
9646
- // parameter count requirement.
9647
- expectedFunctionTypes = expectedFunctionTypes.filter((functionType) => {
9648
- const functionParamCount = functionType.details.parameters.filter((param) => !!param.name && !param.hasDefault).length;
9649
- const hasVarArgs = functionType.details.parameters.some((param) => !!param.name && param.category !== 0 /* Simple */);
9650
- const hasParamSpec = !!functionType.details.paramSpec;
9651
- return (hasVarArgs ||
9652
- hasParamSpec ||
9653
- (functionParamCount >= minLambdaParamCount && functionParamCount <= maxLambdaParamCount));
9654
- });
9655
9650
  }
9656
- // For now, use only the first expected type.
9657
- const expectedFunctionType = expectedFunctionTypes.length > 0 ? expectedFunctionTypes[0] : undefined;
9651
+ if (expectedFunctionTypes.length <= 1) {
9652
+ return getTypeOfLambdaWithExpectedType(node, expectedFunctionTypes.length > 0 ? expectedFunctionTypes[0] : undefined, inferenceContext,
9653
+ /* forceSpeculative */ false);
9654
+ }
9655
+ // Sort the expected types for deterministic results.
9656
+ expectedFunctionTypes = (0, typeUtils_1.sortTypes)(expectedFunctionTypes);
9657
+ // If there's more than one type, try each in turn until we find one that works.
9658
+ for (const expectedFunctionType of expectedFunctionTypes) {
9659
+ const result = getTypeOfLambdaWithExpectedType(node, expectedFunctionType, inferenceContext,
9660
+ /* forceSpeculative */ true);
9661
+ if (!result.typeErrors) {
9662
+ return getTypeOfLambdaWithExpectedType(node, expectedFunctionType, inferenceContext,
9663
+ /* forceSpeculative */ false);
9664
+ }
9665
+ }
9666
+ return getTypeOfLambdaWithExpectedType(node, expectedFunctionTypes[0], inferenceContext,
9667
+ /* forceSpeculative */ true);
9668
+ }
9669
+ function getTypeOfLambdaWithExpectedType(node, expectedType, inferenceContext, forceSpeculative) {
9670
+ let isIncomplete = !!(inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete);
9658
9671
  let paramsArePositionOnly = true;
9659
- const expectedParamDetails = expectedFunctionType ? (0, parameterUtils_1.getParameterListDetails)(expectedFunctionType) : undefined;
9672
+ const expectedParamDetails = expectedType ? (0, parameterUtils_1.getParameterListDetails)(expectedType) : undefined;
9673
+ const functionType = types_1.FunctionType.createInstance('', '', '', 131072 /* PartiallyEvaluated */);
9674
+ functionType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
9675
+ // Pre-cache the incomplete function type in case the evaluation of the
9676
+ // lambda depends on itself.
9677
+ writeTypeCache(node, { type: functionType, isIncomplete: true }, 0 /* None */);
9660
9678
  node.parameters.forEach((param, index) => {
9661
9679
  let paramType;
9662
9680
  if (expectedParamDetails) {
@@ -9721,9 +9739,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9721
9739
  type: types_1.UnknownType.create(),
9722
9740
  });
9723
9741
  }
9724
- const expectedReturnType = expectedFunctionType
9725
- ? getFunctionEffectiveReturnType(expectedFunctionType)
9726
- : undefined;
9742
+ const expectedReturnType = expectedType ? getFunctionEffectiveReturnType(expectedType) : undefined;
9743
+ let typeErrors = false;
9727
9744
  // If we're speculatively evaluating the lambda, create another speculative
9728
9745
  // evaluation scope for the return expression and do not allow retention
9729
9746
  // of the cached types.
@@ -9731,19 +9748,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
9731
9748
  // cache the type of the lambda return expression because it depends on
9732
9749
  // the parameter types that we set above, and the speculative type cache
9733
9750
  // doesn't know about that context.
9734
- useSpeculativeMode(isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete) ? node.expression : undefined, () => {
9751
+ useSpeculativeMode(forceSpeculative || isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete)
9752
+ ? node.expression
9753
+ : undefined, () => {
9735
9754
  const returnTypeResult = getTypeOfExpression(node.expression,
9736
9755
  /* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
9737
9756
  functionType.inferredReturnType = returnTypeResult.type;
9738
9757
  if (returnTypeResult.isIncomplete) {
9739
9758
  isIncomplete = true;
9740
9759
  }
9760
+ if (returnTypeResult.typeErrors) {
9761
+ typeErrors = true;
9762
+ }
9741
9763
  }, {
9742
- dependentType: inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType,
9764
+ dependentType: expectedType,
9743
9765
  });
9744
9766
  // Mark the function type as no longer being evaluated.
9745
9767
  functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
9746
- return { type: functionType, isIncomplete };
9768
+ // Is the resulting function compatible with the expected type?
9769
+ if (expectedType && !assignType(expectedType, functionType)) {
9770
+ typeErrors = true;
9771
+ }
9772
+ return { type: functionType, isIncomplete, typeErrors };
9747
9773
  }
9748
9774
  function getTypeOfListComprehension(node, inferenceContext) {
9749
9775
  var _a;
@@ -11328,8 +11354,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11328
11354
  metaclassNode = arg.valueExpression;
11329
11355
  }
11330
11356
  }
11331
- else if (types_1.ClassType.isTypedDictClass(classType) &&
11332
- (arg.name.value === 'total' || arg.name.value === 'readonly')) {
11357
+ else if (types_1.ClassType.isTypedDictClass(classType) && arg.name.value === 'total') {
11333
11358
  // The "total" and "readonly" parameters apply only for TypedDict classes.
11334
11359
  // PEP 589 specifies that the parameter must be either True or False.
11335
11360
  const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
@@ -11339,9 +11364,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11339
11364
  else if (arg.name.value === 'total' && !constArgValue) {
11340
11365
  classType.details.flags |= 256 /* CanOmitDictValues */;
11341
11366
  }
11342
- else if (arg.name.value === 'readonly' && constArgValue) {
11343
- classType.details.flags |= 512 /* DictValuesReadOnly */;
11344
- }
11345
11367
  }
11346
11368
  else {
11347
11369
  // Collect arguments that will be passed to the `__init_subclass__`
@@ -14234,6 +14256,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14234
14256
  .getDeclarations()
14235
14257
  .find((decl) => decl.type === 2 /* Parameter */);
14236
14258
  }
14259
+ const parameterDetails = (0, parameterUtils_1.getParameterListDetails)(type);
14260
+ if (parameterDetails.unpackedKwargsTypedDictType) {
14261
+ const lookupResults = (0, typeUtils_1.lookUpClassMember)(parameterDetails.unpackedKwargsTypedDictType, paramName);
14262
+ if (lookupResults) {
14263
+ return lookupResults.symbol
14264
+ .getDeclarations()
14265
+ .find((decl) => decl.type === 1 /* Variable */);
14266
+ }
14267
+ }
14237
14268
  }
14238
14269
  }
14239
14270
  }
@@ -14574,13 +14605,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14574
14605
  if (cachedTypeVarType && (0, types_1.isTypeVar)(cachedTypeVarType)) {
14575
14606
  return cachedTypeVarType;
14576
14607
  }
14577
- let typeVar = types_1.TypeVarType.createInstantiable(node.name.value);
14578
- typeVar.details.isTypeParamSyntax = true;
14608
+ let runtimeClassName = 'TypeVar';
14579
14609
  if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
14580
- typeVar.details.isVariadic = true;
14610
+ runtimeClassName = 'TypeVarTuple';
14581
14611
  }
14582
14612
  else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec) {
14583
- typeVar.details.isParamSpec = true;
14613
+ runtimeClassName = 'ParamSpec';
14614
+ }
14615
+ const runtimeType = getTypingType(node, runtimeClassName);
14616
+ const runtimeClass = runtimeType && (0, types_1.isInstantiableClass)(runtimeType) ? runtimeType : undefined;
14617
+ let typeVar = types_1.TypeVarType.createInstantiable(node.name.value, node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec, runtimeClass);
14618
+ typeVar.details.isTypeParamSyntax = true;
14619
+ if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
14620
+ typeVar.details.isVariadic = true;
14584
14621
  }
14585
14622
  // Cache the value before we evaluate the bound or the default type in
14586
14623
  // case it refers to itself in a circular manner.
@@ -14909,7 +14946,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14909
14946
  return getEffectiveTypeOfSymbolForUsage(symbol).type;
14910
14947
  }
14911
14948
  function getEffectiveTypeOfSymbolForUsage(symbol, usageNode, useLastDecl = false) {
14912
- var _a, _b;
14913
14949
  let declaredTypeInfo;
14914
14950
  // If there's a declared type, it takes precedence over inferred types.
14915
14951
  if (symbol.hasTypedDeclarations()) {
@@ -14942,13 +14978,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
14942
14978
  let cacheEntries = effectiveTypeCache.get(symbol.id);
14943
14979
  const usageNodeId = usageNode ? usageNode.id : undefined;
14944
14980
  const effectiveTypeCacheKey = `${usageNodeId === undefined ? '.' : usageNodeId.toString()}${useLastDecl ? '*' : ''}`;
14945
- if (cacheEntries) {
14946
- const result = cacheEntries.get(effectiveTypeCacheKey);
14947
- if (result) {
14948
- if (!result.isIncomplete) {
14949
- return result;
14950
- }
14951
- }
14981
+ const cacheEntry = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey);
14982
+ if (cacheEntry && !cacheEntry.isIncomplete) {
14983
+ return cacheEntry;
14952
14984
  }
14953
14985
  // Infer the type.
14954
14986
  const decls = symbol.getDeclarations();
@@ -15037,8 +15069,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15037
15069
  }
15038
15070
  declsToConsider.push(resolvedDecl);
15039
15071
  });
15040
- const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(effectiveTypeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
15041
- const result = getTypeOfSymbolForDecls(symbol, declsToConsider, evaluationAttempts);
15072
+ const result = getTypeOfSymbolForDecls(symbol, declsToConsider, effectiveTypeCacheKey);
15042
15073
  // Add the result to the effective type cache if it doesn't include speculative results.
15043
15074
  if (!result.includesSpeculativeResult) {
15044
15075
  addToEffectiveTypeCache(result);
@@ -15054,7 +15085,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15054
15085
  }
15055
15086
  }
15056
15087
  // Returns the type of a symbol based on a subset of its declarations.
15057
- function getTypeOfSymbolForDecls(symbol, decls, evaluationAttempts) {
15088
+ function getTypeOfSymbolForDecls(symbol, decls, typeCacheKey) {
15089
+ var _a, _b;
15058
15090
  const typesToCombine = [];
15059
15091
  let isIncomplete = false;
15060
15092
  let sawPendingEvaluation = false;
@@ -15122,6 +15154,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15122
15154
  sawPendingEvaluation = true;
15123
15155
  }
15124
15156
  });
15157
+ // How many times have we already attempted to evaluate this declaration already?
15158
+ const cacheEntries = effectiveTypeCache.get(symbol.id);
15159
+ const evaluationAttempts = ((_b = (_a = cacheEntries === null || cacheEntries === void 0 ? void 0 : cacheEntries.get(typeCacheKey)) === null || _a === void 0 ? void 0 : _a.evaluationAttempts) !== null && _b !== void 0 ? _b : 0) + 1;
15125
15160
  let type;
15126
15161
  if (typesToCombine.length > 0) {
15127
15162
  // Ignore the pending evaluation flag if we've already attempted the