@zzzen/pyright-internal 1.2.0-dev.20250330 → 1.2.0-dev.20250413

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 (75) hide show
  1. package/dist/analyzer/binder.js +1 -0
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +19 -8
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/codeFlowEngine.js +1 -1
  6. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  7. package/dist/analyzer/constructors.js +2 -2
  8. package/dist/analyzer/constructors.js.map +1 -1
  9. package/dist/analyzer/dataClasses.js +4 -4
  10. package/dist/analyzer/dataClasses.js.map +1 -1
  11. package/dist/analyzer/enums.js +1 -1
  12. package/dist/analyzer/enums.js.map +1 -1
  13. package/dist/analyzer/operations.js +1 -1
  14. package/dist/analyzer/operations.js.map +1 -1
  15. package/dist/analyzer/parseTreeUtils.d.ts +1 -1
  16. package/dist/analyzer/parseTreeUtils.js +18 -3
  17. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  18. package/dist/analyzer/program.js +6 -1
  19. package/dist/analyzer/program.js.map +1 -1
  20. package/dist/analyzer/protocols.js +2 -2
  21. package/dist/analyzer/protocols.js.map +1 -1
  22. package/dist/analyzer/sourceFile.js +1 -0
  23. package/dist/analyzer/sourceFile.js.map +1 -1
  24. package/dist/analyzer/typeEvaluator.js +103 -79
  25. package/dist/analyzer/typeEvaluator.js.map +1 -1
  26. package/dist/analyzer/typeGuards.js +91 -52
  27. package/dist/analyzer/typeGuards.js.map +1 -1
  28. package/dist/analyzer/typeUtils.js +2 -2
  29. package/dist/analyzer/typeUtils.js.map +1 -1
  30. package/dist/analyzer/types.d.ts +1 -0
  31. package/dist/analyzer/types.js +4 -0
  32. package/dist/analyzer/types.js.map +1 -1
  33. package/dist/common/extensibility.d.ts +1 -0
  34. package/dist/common/extensibility.js.map +1 -1
  35. package/dist/languageService/completionProvider.js +1 -1
  36. package/dist/languageService/completionProvider.js.map +1 -1
  37. package/dist/languageService/completionProviderUtils.js +1 -1
  38. package/dist/languageService/completionProviderUtils.js.map +1 -1
  39. package/dist/languageService/hoverProvider.js +1 -1
  40. package/dist/languageService/hoverProvider.js.map +1 -1
  41. package/dist/languageService/tooltipUtils.js +2 -2
  42. package/dist/languageService/tooltipUtils.js.map +1 -1
  43. package/dist/localization/localize.d.ts +1 -0
  44. package/dist/localization/localize.js +1 -0
  45. package/dist/localization/localize.js.map +1 -1
  46. package/dist/localization/package.nls.cs.json +1 -0
  47. package/dist/localization/package.nls.de.json +1 -0
  48. package/dist/localization/package.nls.en-us.json +4 -0
  49. package/dist/localization/package.nls.es.json +1 -0
  50. package/dist/localization/package.nls.fr.json +1 -0
  51. package/dist/localization/package.nls.it.json +1 -0
  52. package/dist/localization/package.nls.ja.json +1 -0
  53. package/dist/localization/package.nls.ko.json +1 -0
  54. package/dist/localization/package.nls.pl.json +1 -0
  55. package/dist/localization/package.nls.pt-br.json +1 -0
  56. package/dist/localization/package.nls.qps-ploc.json +1 -0
  57. package/dist/localization/package.nls.ru.json +1 -0
  58. package/dist/localization/package.nls.tr.json +1 -0
  59. package/dist/localization/package.nls.zh-cn.json +1 -0
  60. package/dist/localization/package.nls.zh-tw.json +1 -0
  61. package/dist/parser/parser.d.ts +2 -0
  62. package/dist/parser/parser.js +4 -0
  63. package/dist/parser/parser.js.map +1 -1
  64. package/dist/parser/tokenizer.js +0 -2
  65. package/dist/parser/tokenizer.js.map +1 -1
  66. package/dist/tests/checker.test.js +1 -1
  67. package/dist/tests/tokenizer.test.js +5 -15
  68. package/dist/tests/tokenizer.test.js.map +1 -1
  69. package/dist/tests/typeEvaluator2.test.js +3 -3
  70. package/dist/tests/typeEvaluator6.test.js +1 -1
  71. package/dist/tests/typeEvaluator7.test.js +14 -1
  72. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  73. package/dist/tests/typeEvaluator8.test.js +6 -2
  74. package/dist/tests/typeEvaluator8.test.js.map +1 -1
  75. package/package.json +1 -1
@@ -851,9 +851,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
851
851
  /* useCoroutine */ false)
852
852
  : undefined;
853
853
  const exprTypeResult = getTypeOfExpression(node.d.expr, flags, (0, typeUtils_1.makeInferenceContext)(expectedType));
854
+ const awaitableResult = getTypeOfAwaitable(exprTypeResult, node.d.expr);
854
855
  const typeResult = {
855
- type: getTypeOfAwaitable(exprTypeResult.type, node.d.expr),
856
- isIncomplete: exprTypeResult.isIncomplete,
856
+ type: awaitableResult.type,
857
+ isIncomplete: exprTypeResult.isIncomplete || awaitableResult.isIncomplete,
857
858
  typeErrors: exprTypeResult.typeErrors,
858
859
  };
859
860
  if (exprTypeResult.isIncomplete) {
@@ -1576,7 +1577,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1576
1577
  if (!boundMethodResult || boundMethodResult.typeErrors) {
1577
1578
  return undefined;
1578
1579
  }
1579
- if ((0, types_1.isFunction)(boundMethodResult.type) || (0, types_1.isOverloaded)(boundMethodResult.type)) {
1580
+ if ((0, types_1.isFunctionOrOverloaded)(boundMethodResult.type)) {
1580
1581
  return boundMethodResult.type;
1581
1582
  }
1582
1583
  if ((0, types_1.isClassInstance)(boundMethodResult.type)) {
@@ -1671,7 +1672,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1671
1672
  const constructorType = (0, constructors_1.createFunctionFromConstructor)(evaluatorInterface, subtype);
1672
1673
  if (constructorType) {
1673
1674
  (0, typeUtils_1.doForEachSubtype)(constructorType, (subtype) => {
1674
- if ((0, types_1.isFunction)(subtype) || (0, types_1.isOverloaded)(subtype)) {
1675
+ if ((0, types_1.isFunctionOrOverloaded)(subtype)) {
1675
1676
  addFunctionToSignature(subtype);
1676
1677
  }
1677
1678
  });
@@ -1867,7 +1868,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1867
1868
  if (memberAccessClass && (0, types_1.isInstantiableClass)(memberAccessClass)) {
1868
1869
  declaredType = (0, typeUtils_1.partiallySpecializeType)(declaredType, memberAccessClass, getTypeClassType(), selfType);
1869
1870
  }
1870
- if ((0, types_1.isFunction)(declaredType) || (0, types_1.isOverloaded)(declaredType)) {
1871
+ if ((0, types_1.isFunctionOrOverloaded)(declaredType)) {
1871
1872
  if (bindFunction) {
1872
1873
  declaredType = bindFunctionToClassOrObject(classOrObjectBase, declaredType,
1873
1874
  /* memberClass */ undefined,
@@ -1884,14 +1885,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1884
1885
  // the result. According to PEP 492, await operates on an Awaitable
1885
1886
  // (object that provides an __await__ that returns a generator object).
1886
1887
  // If errorNode is undefined, no errors are reported.
1887
- function getTypeOfAwaitable(type, errorNode) {
1888
+ function getTypeOfAwaitable(typeResult, errorNode) {
1888
1889
  if (!prefetched?.awaitableClass ||
1889
1890
  !(0, types_1.isInstantiableClass)(prefetched.awaitableClass) ||
1890
1891
  prefetched.awaitableClass.shared.typeParams.length !== 1) {
1891
- return types_1.UnknownType.create();
1892
+ return { type: types_1.UnknownType.create(), isIncomplete: typeResult.isIncomplete };
1892
1893
  }
1893
1894
  const awaitableProtocolObj = types_1.ClassType.cloneAsInstance(prefetched.awaitableClass);
1894
- return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
1895
+ const isIncomplete = !!typeResult.isIncomplete;
1896
+ const type = (0, typeUtils_1.mapSubtypes)(typeResult.type, (subtype) => {
1895
1897
  subtype = makeTopLevelTypeVarsConcrete(subtype);
1896
1898
  if ((0, types_1.isAnyOrUnknown)(subtype)) {
1897
1899
  return subtype;
@@ -1909,11 +1911,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1909
1911
  return types_1.UnknownType.create();
1910
1912
  }
1911
1913
  }
1912
- if (errorNode) {
1914
+ if (errorNode && !typeResult.isIncomplete) {
1913
1915
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotAwaitable().format({ type: printType(subtype) }) + diag?.getString(), errorNode);
1914
1916
  }
1915
1917
  return types_1.UnknownType.create();
1916
1918
  });
1919
+ return { type, isIncomplete };
1917
1920
  }
1918
1921
  // Validates that the type is an iterator and returns the iterated type
1919
1922
  // (i.e. the type returned from the '__next__' or '__anext__' method).
@@ -1921,6 +1924,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1921
1924
  const iterMethodName = isAsync ? '__aiter__' : '__iter__';
1922
1925
  const nextMethodName = isAsync ? '__anext__' : '__next__';
1923
1926
  let isValidIterator = true;
1927
+ let isIncomplete = typeResult.isIncomplete;
1924
1928
  let type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(typeResult.type);
1925
1929
  type = makeTopLevelTypeVarsConcrete(type);
1926
1930
  type = (0, types_1.removeUnbound)(type);
@@ -1989,7 +1993,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1989
1993
  }
1990
1994
  // If it's an async iteration, there's an implicit
1991
1995
  // 'await' operator applied.
1992
- return getTypeOfAwaitable(nextReturnType, errorNode);
1996
+ const awaitableResult = getTypeOfAwaitable({ type: nextReturnType, isIncomplete: typeResult.isIncomplete }, errorNode);
1997
+ if (awaitableResult.isIncomplete) {
1998
+ isIncomplete = true;
1999
+ }
2000
+ return awaitableResult.type;
1993
2001
  }
1994
2002
  return undefined;
1995
2003
  });
@@ -1999,13 +2007,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
1999
2007
  diag.addAddendum(iterReturnTypeDiag);
2000
2008
  }
2001
2009
  }
2002
- if (!typeResult.isIncomplete && emitNotIterableError) {
2010
+ if (!isIncomplete && emitNotIterableError) {
2003
2011
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotIterable().format({ type: printType(subtype) }) + diag.getString(), errorNode);
2004
2012
  }
2005
2013
  isValidIterator = false;
2006
2014
  return undefined;
2007
2015
  });
2008
- return isValidIterator ? { type: iterableType, isIncomplete: typeResult.isIncomplete } : undefined;
2016
+ return isValidIterator ? { type: iterableType, isIncomplete } : undefined;
2009
2017
  }
2010
2018
  // Validates that the type is an iterable and returns the iterable type argument.
2011
2019
  function getTypeOfIterable(typeResult, isAsync, errorNode, emitNotIterableError = true) {
@@ -2393,7 +2401,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2393
2401
  }
2394
2402
  }
2395
2403
  if (!typeResult.isIncomplete) {
2396
- reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, destType, nameNode, ignoreEmptyContainers);
2404
+ reportPossibleUnknownAssignment(fileInfo.diagnosticRuleSet.reportUnknownVariableType, diagnosticRules_1.DiagnosticRule.reportUnknownVariableType, nameNode, typeResult.type, nameNode, ignoreEmptyContainers);
2397
2405
  }
2398
2406
  writeTypeCache(nameNode, { type: destType, isIncomplete: typeResult.isIncomplete }, 0 /* EvalFlags.None */);
2399
2407
  }
@@ -2934,31 +2942,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
2934
2942
  break;
2935
2943
  }
2936
2944
  case 54 /* ParseNodeType.TypeAnnotation */: {
2937
- let annotationType = getTypeOfAnnotation(target.d.annotation, {
2945
+ getTypeOfAnnotation(target.d.annotation, {
2938
2946
  varTypeAnnotation: true,
2939
2947
  allowFinal: isFinalAllowedForAssignmentTarget(target.d.valueExpr),
2940
2948
  allowClassVar: isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
2941
2949
  });
2942
- if (annotationType) {
2943
- const liveScopeIds = ParseTreeUtils.getTypeVarScopesForNode(target);
2944
- annotationType = (0, typeUtils_1.makeTypeVarsBound)(annotationType, liveScopeIds);
2945
- }
2946
- // Handle a bare "Final" or "ClassVar" in a special manner.
2947
- const isBareFinalOrClassVar = (0, types_1.isClassInstance)(annotationType) &&
2948
- (types_1.ClassType.isBuiltIn(annotationType, 'Final') || types_1.ClassType.isBuiltIn(annotationType, 'ClassVar'));
2949
- if (!isBareFinalOrClassVar) {
2950
- const isTypeAliasAnnotation = (0, types_1.isClassInstance)(annotationType) && types_1.ClassType.isBuiltIn(annotationType, 'TypeAlias');
2951
- if (!isTypeAliasAnnotation) {
2952
- if (assignType(annotationType, typeResult.type)) {
2953
- // Don't attempt to narrow based on the annotated type if the type
2954
- // is a enum because the annotated type in an enum doesn't reflect
2955
- // the type of the symbol.
2956
- if (!(0, types_1.isClassInstance)(typeResult.type) || !types_1.ClassType.isEnumClass(typeResult.type)) {
2957
- typeResult = narrowTypeBasedOnAssignment(annotationType, typeResult);
2958
- }
2959
- }
2960
- }
2961
- }
2962
2950
  assignTypeToExpression(target.d.valueExpr, typeResult, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
2963
2951
  break;
2964
2952
  }
@@ -4065,8 +4053,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4065
4053
  // If type is undefined, emit a general error message indicating that the
4066
4054
  // member could not be accessed.
4067
4055
  if (!type) {
4068
- const isFunctionRule = (0, types_1.isFunction)(baseType) ||
4069
- (0, types_1.isOverloaded)(baseType) ||
4056
+ const isFunctionRule = (0, types_1.isFunctionOrOverloaded)(baseType) ||
4070
4057
  ((0, types_1.isClassInstance)(baseType) && types_1.ClassType.isBuiltIn(baseType, 'function'));
4071
4058
  if (!baseTypeResult.isIncomplete) {
4072
4059
  let diagMessage = localize_1.LocMessage.memberAccess();
@@ -4260,7 +4247,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4260
4247
  }
4261
4248
  resultType = descResult.type;
4262
4249
  }
4263
- else if ((0, types_1.isFunction)(concreteSubtype) || (0, types_1.isOverloaded)(concreteSubtype)) {
4250
+ else if ((0, types_1.isFunctionOrOverloaded)(concreteSubtype) && types_1.TypeBase.isInstance(concreteSubtype)) {
4264
4251
  const typeResult = bindMethodForMemberAccess(subtype, concreteSubtype, memberInfo, classType, selfType, flags, memberName, usage, diag, recursionCount);
4265
4252
  resultType = typeResult.type;
4266
4253
  if (typeResult.typeErrors) {
@@ -4389,7 +4376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4389
4376
  }
4390
4377
  return { type: types_1.UnknownType.create(), typeErrors: true };
4391
4378
  }
4392
- if (!(0, types_1.isFunction)(methodType) && !(0, types_1.isOverloaded)(methodType)) {
4379
+ if (!(0, types_1.isFunctionOrOverloaded)(methodType)) {
4393
4380
  if ((0, types_1.isAnyOrUnknown)(methodType)) {
4394
4381
  return { type: methodType };
4395
4382
  }
@@ -4433,7 +4420,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4433
4420
  /* diag */ undefined, constraints);
4434
4421
  accessMethodClass = solveAndApplyConstraints(accessMethodClass, constraints);
4435
4422
  const specializedType = (0, typeUtils_1.partiallySpecializeType)(methodType, accessMethodClass, getTypeClassType(), selfType ? (0, typeUtils_1.convertToInstantiable)(selfType) : classType);
4436
- if ((0, types_1.isFunction)(specializedType) || (0, types_1.isOverloaded)(specializedType)) {
4423
+ if ((0, types_1.isFunctionOrOverloaded)(specializedType)) {
4437
4424
  methodType = specializedType;
4438
4425
  }
4439
4426
  }
@@ -4693,7 +4680,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4693
4680
  },
4694
4681
  });
4695
4682
  }
4696
- if (!(0, types_1.isFunction)(accessMemberType) && !(0, types_1.isOverloaded)(accessMemberType)) {
4683
+ if (!(0, types_1.isFunctionOrOverloaded)(accessMemberType)) {
4697
4684
  if ((0, types_1.isAnyOrUnknown)(accessMemberType)) {
4698
4685
  return { type: accessMemberType };
4699
4686
  }
@@ -4796,16 +4783,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
4796
4783
  const variadicIndex = typeParams.findIndex((param) => (0, types_1.isTypeVarTuple)(param));
4797
4784
  // Is there a *tuple[T, ...] somewhere in the type arguments that we can expand if needed?
4798
4785
  let srcUnboundedTupleType;
4799
- let srcUnboundedTupleIndex = typeArgs.findIndex((arg) => {
4800
- if ((0, types_1.isUnpackedClass)(arg.type) &&
4801
- arg.type.priv.tupleTypeArgs &&
4802
- arg.type.priv.tupleTypeArgs.length === 1 &&
4803
- arg.type.priv.tupleTypeArgs[0].isUnbounded) {
4804
- srcUnboundedTupleType = arg.type.priv.tupleTypeArgs[0].type;
4805
- return true;
4786
+ const findUnboundedTupleIndex = (startArgIndex) => {
4787
+ return typeArgs.findIndex((arg, index) => {
4788
+ if (index < startArgIndex) {
4789
+ return false;
4790
+ }
4791
+ if ((0, types_1.isUnpackedClass)(arg.type) &&
4792
+ arg.type.priv.tupleTypeArgs &&
4793
+ arg.type.priv.tupleTypeArgs.length === 1 &&
4794
+ arg.type.priv.tupleTypeArgs[0].isUnbounded) {
4795
+ srcUnboundedTupleType = arg.type.priv.tupleTypeArgs[0].type;
4796
+ return true;
4797
+ }
4798
+ return false;
4799
+ });
4800
+ };
4801
+ let srcUnboundedTupleIndex = findUnboundedTupleIndex(0);
4802
+ // Allow only one unpacked tuple that maps to a TypeVarTuple.
4803
+ if (srcUnboundedTupleIndex >= 0) {
4804
+ const secondUnboundedTupleIndex = findUnboundedTupleIndex(srcUnboundedTupleIndex + 1);
4805
+ if (secondUnboundedTupleIndex >= 0) {
4806
+ addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.variadicTypeArgsTooMany(), typeArgs[secondUnboundedTupleIndex].node);
4806
4807
  }
4807
- return false;
4808
- });
4808
+ }
4809
4809
  if (srcUnboundedTupleType &&
4810
4810
  srcUnboundedTupleIndex >= 0 &&
4811
4811
  variadicIndex >= 0 &&
@@ -8500,7 +8500,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
8500
8500
  // If the function is returning a callable, don't eliminate unsolved
8501
8501
  // type vars within a union. There are legit uses for unsolved type vars
8502
8502
  // within a callable.
8503
- if ((0, types_1.isFunction)(returnType) || (0, types_1.isOverloaded)(returnType)) {
8503
+ if ((0, types_1.isFunctionOrOverloaded)(returnType)) {
8504
8504
  eliminateUnsolvedInUnions = false;
8505
8505
  }
8506
8506
  let specializedReturnType = solveAndApplyConstraints(returnType, constraints, {
@@ -11334,7 +11334,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
11334
11334
  validateTypeVarTupleIsUnpacked(typeArg.type, typeArg.node);
11335
11335
  }
11336
11336
  else if (paramLimit === undefined && (0, types_1.isUnpackedClass)(typeArg.type)) {
11337
- if (typeArg.type.priv.tupleTypeArgs?.some((typeArg) => (0, types_1.isTypeVarTuple)(typeArg.type) || typeArg.isUnbounded)) {
11337
+ if ((0, typeUtils_1.isUnboundedTupleClass)(typeArg.type)) {
11338
11338
  noteSawUnpacked(typeArg);
11339
11339
  }
11340
11340
  validateTypeArg(typeArg, { allowUnpackedTuples: true });
@@ -13482,7 +13482,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13482
13482
  }
13483
13483
  else {
13484
13484
  let skipInference = false;
13485
- if ((0, types_1.isFunction)(defaultValueType) || (0, types_1.isOverloaded)(defaultValueType)) {
13485
+ if ((0, types_1.isFunctionOrOverloaded)(defaultValueType)) {
13486
13486
  // Do not infer parameter types that use a lambda or another function as a
13487
13487
  // default value. We're likely to generate false positives in this case.
13488
13488
  // It's not clear whether parameters should be positional-only or not.
@@ -13893,6 +13893,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13893
13893
  return;
13894
13894
  }
13895
13895
  const exprTypeResult = getTypeOfExpression(node.d.expr);
13896
+ let isIncomplete = exprTypeResult.isIncomplete;
13896
13897
  let exprType = exprTypeResult.type;
13897
13898
  const isAsync = node.parent && node.parent.nodeType === 58 /* ParseNodeType.With */ && !!node.parent.d.isAsync;
13898
13899
  if ((0, typeUtils_1.isOptionalType)(exprType)) {
@@ -13911,7 +13912,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13911
13912
  const enterTypeResult = getTypeOfMagicMethodCall(subtype, enterMethodName, [], node.d.expr,
13912
13913
  /* inferenceContext */ undefined, enterDiag.createAddendum());
13913
13914
  if (enterTypeResult) {
13914
- return isAsync ? getTypeOfAwaitable(enterTypeResult.type, node.d.expr) : enterTypeResult.type;
13915
+ if (isAsync) {
13916
+ if (enterTypeResult.isIncomplete) {
13917
+ isIncomplete = true;
13918
+ }
13919
+ const asyncResult = getTypeOfAwaitable({ type: enterTypeResult.type }, node.d.expr);
13920
+ if (asyncResult.isIncomplete) {
13921
+ isIncomplete = true;
13922
+ }
13923
+ return asyncResult.type;
13924
+ }
13925
+ return enterTypeResult.type;
13915
13926
  }
13916
13927
  if (!isAsync) {
13917
13928
  if (getTypeOfMagicMethodCall(subtype, '__aenter__', [], node.d.expr,
@@ -13937,7 +13948,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13937
13948
  const exitTypeResult = getTypeOfMagicMethodCall(subtype, exitMethodName, [anyArg, anyArg, anyArg], node.d.expr,
13938
13949
  /* inferenceContext */ undefined, exitDiag);
13939
13950
  if (exitTypeResult) {
13940
- return isAsync ? getTypeOfAwaitable(exitTypeResult.type, node.d.expr) : exitTypeResult.type;
13951
+ if (exitTypeResult.isIncomplete) {
13952
+ isIncomplete = true;
13953
+ }
13954
+ if (isAsync) {
13955
+ const asyncResult = getTypeOfAwaitable({ type: exitTypeResult.type }, node.d.expr);
13956
+ if (asyncResult.isIncomplete) {
13957
+ isIncomplete = true;
13958
+ }
13959
+ return asyncResult.type;
13960
+ }
13961
+ return exitTypeResult.type;
13941
13962
  }
13942
13963
  }
13943
13964
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeNotUsableWith().format({ type: printType(subtype), method: exitMethodName }) +
@@ -13945,9 +13966,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
13945
13966
  return types_1.UnknownType.create();
13946
13967
  });
13947
13968
  if (node.d.target) {
13948
- assignTypeToExpression(node.d.target, { type: scopedType, isIncomplete: exprTypeResult.isIncomplete }, node.d.target);
13969
+ assignTypeToExpression(node.d.target, { type: scopedType, isIncomplete }, node.d.target);
13949
13970
  }
13950
- writeTypeCache(node, { type: scopedType, isIncomplete: !!exprTypeResult.isIncomplete }, 0 /* EvalFlags.None */);
13971
+ writeTypeCache(node, { type: scopedType, isIncomplete }, 0 /* EvalFlags.None */);
13951
13972
  }
13952
13973
  function evaluateTypesForImportAs(node) {
13953
13974
  if (isTypeCached(node)) {
@@ -14869,7 +14890,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
14869
14890
  if (types_1.ClassType.isBuiltIn(classType, 'type') && typeArgs) {
14870
14891
  if (typeArgs.length >= 1) {
14871
14892
  // Treat type[function] as illegal.
14872
- if ((0, types_1.isFunction)(typeArgs[0].type) || (0, types_1.isOverloaded)(typeArgs[0].type)) {
14893
+ if ((0, types_1.isFunctionOrOverloaded)(typeArgs[0].type)) {
14873
14894
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportInvalidTypeForm, localize_1.LocMessage.typeAnnotationWithCallable(), typeArgs[0].node);
14874
14895
  return { type: types_1.UnknownType.create() };
14875
14896
  }
@@ -15421,7 +15442,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
15421
15442
  if (!tracker) {
15422
15443
  return type;
15423
15444
  }
15424
- if ((0, types_1.isFunction)(type) || (0, types_1.isOverloaded)(type)) {
15445
+ if ((0, types_1.isFunctionOrOverloaded)(type)) {
15425
15446
  return (0, typeUtils_1.ensureSignaturesAreUnique)(type, tracker, node.start);
15426
15447
  }
15427
15448
  return type;
@@ -16931,13 +16952,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
16931
16952
  if (errorNode &&
16932
16953
  selfClass &&
16933
16954
  (0, types_1.isClass)(selfClass) &&
16955
+ !selfClass.priv.includeSubclasses &&
16934
16956
  member.isInstanceMember &&
16935
16957
  (0, types_1.isClass)(member.unspecializedClassType) &&
16936
16958
  (flags & 1024 /* MemberAccessFlags.DisallowGenericInstanceVariableAccess */) !== 0 &&
16937
16959
  (0, typeUtils_1.requiresSpecialization)(typeResult.type, { ignoreSelf: true, ignoreImplicitTypeArgs: true })) {
16938
16960
  const specializedType = (0, typeUtils_1.partiallySpecializeType)(typeResult.type, member.unspecializedClassType, getTypeClassType(), (0, typeUtils_1.selfSpecializeClass)(selfClass, { overrideTypeArgs: true }));
16939
- if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunction)(subtype) &&
16940
- !(0, types_1.isOverloaded)(subtype) &&
16961
+ if ((0, types_1.findSubtype)(specializedType, (subtype) => !(0, types_1.isFunctionOrOverloaded)(subtype) &&
16941
16962
  (0, typeUtils_1.requiresSpecialization)(subtype, { ignoreSelf: true, ignoreImplicitTypeArgs: true }))) {
16942
16963
  addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.genericInstanceVariableAccess(), errorNode);
16943
16964
  }
@@ -17770,7 +17791,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17770
17791
  }
17771
17792
  return true;
17772
17793
  }
17773
- else if ((0, types_1.isFunction)(concreteSrcType) || (0, types_1.isOverloaded)(concreteSrcType)) {
17794
+ else if ((0, types_1.isFunctionOrOverloaded)(concreteSrcType)) {
17774
17795
  // Is the destination a callback protocol (defined in PEP 544)?
17775
17796
  const destCallbackType = getCallbackProtocolType(destType, recursionCount);
17776
17797
  if (destCallbackType) {
@@ -17805,13 +17826,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
17805
17826
  // Determine if the metaclass can be assigned to the object.
17806
17827
  const metaclass = concreteSrcType.shared.effectiveMetaclass;
17807
17828
  if (metaclass) {
17808
- if ((0, types_1.isAnyOrUnknown)(metaclass)) {
17809
- return true;
17810
- }
17811
- if (assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass,
17812
- /* diag */ undefined, constraints, flags, recursionCount,
17813
- /* reportErrorsUsingObjType */ true)) {
17814
- return true;
17829
+ if (!(0, types_1.isAnyOrUnknown)(metaclass)) {
17830
+ if (assignClass(types_1.ClassType.cloneAsInstantiable(destType), metaclass,
17831
+ /* diag */ undefined, constraints, flags, recursionCount,
17832
+ /* reportErrorsUsingObjType */ true)) {
17833
+ return true;
17834
+ }
17815
17835
  }
17816
17836
  }
17817
17837
  }
@@ -18083,10 +18103,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18083
18103
  }
18084
18104
  }
18085
18105
  }
18086
- if ((0, types_1.isFunction)(srcSubtype) || (0, types_1.isOverloaded)(srcSubtype)) {
18087
- if ((0, types_1.isFunction)(destSubtype) || (0, types_1.isOverloaded)(destSubtype)) {
18088
- return true;
18089
- }
18106
+ if ((0, types_1.isFunctionOrOverloaded)(srcSubtype) && (0, types_1.isFunctionOrOverloaded)(destSubtype)) {
18107
+ return true;
18090
18108
  }
18091
18109
  return false;
18092
18110
  });
@@ -18287,10 +18305,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
18287
18305
  if ((0, types_1.isModule)(leftType) || (0, types_1.isModule)(rightType)) {
18288
18306
  return (0, types_1.isTypeSame)(leftType, rightType, { ignoreConditions: true });
18289
18307
  }
18290
- const isLeftCallable = (0, types_1.isFunction)(leftType) || (0, types_1.isOverloaded)(leftType);
18291
- const isRightCallable = (0, types_1.isFunction)(rightType) || (0, types_1.isOverloaded)(rightType);
18292
- if (isLeftCallable !== isRightCallable) {
18293
- return false;
18308
+ const isLeftCallable = (0, types_1.isFunctionOrOverloaded)(leftType);
18309
+ const isRightCallable = (0, types_1.isFunctionOrOverloaded)(rightType);
18310
+ // If either type is a function, assume that it may be comparable. The other
18311
+ // operand might be a callable object, an 'object' instance, etc. We could
18312
+ // make this more precise for specific cases (e.g. if the other operand is
18313
+ // None or a literal or an instance of a nominal class that doesn't override
18314
+ // __call__ and is marked final, etc.), but coming up with a comprehensive
18315
+ // list is probably not feasible.
18316
+ if (isLeftCallable || isRightCallable) {
18317
+ return true;
18294
18318
  }
18295
18319
  if ((0, types_1.isInstantiableClass)(leftType) || ((0, types_1.isClassInstance)(leftType) && types_1.ClassType.isBuiltIn(leftType, 'type'))) {
18296
18320
  if ((0, types_1.isInstantiableClass)(rightType) ||
@@ -19281,7 +19305,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19281
19305
  }
19282
19306
  // We also need to be careful with callback protocols.
19283
19307
  if ((0, types_1.isClassInstance)(declaredSubtype) && types_1.ClassType.isProtocolClass(declaredSubtype)) {
19284
- if ((0, types_1.isFunction)(assignedSubtype) || (0, types_1.isOverloaded)(assignedSubtype)) {
19308
+ if ((0, types_1.isFunctionOrOverloaded)(assignedSubtype)) {
19285
19309
  return assignedSubtype;
19286
19310
  }
19287
19311
  }
@@ -19312,7 +19336,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19312
19336
  function validateOverrideMethod(baseMethod, overrideMethod, baseClass, diag, enforceParamNames = true) {
19313
19337
  // If we're overriding a non-method with a method, report it as an error.
19314
19338
  // This occurs when a non-property overrides a property.
19315
- if (!(0, types_1.isFunction)(baseMethod) && !(0, types_1.isOverloaded)(baseMethod)) {
19339
+ if (!(0, types_1.isFunctionOrOverloaded)(baseMethod)) {
19316
19340
  diag.addMessage(localize_1.LocAddendum.overrideType().format({ type: printType(baseMethod) }));
19317
19341
  return false;
19318
19342
  }
@@ -19892,7 +19916,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
19892
19916
  // bound to its own __call__ method but the first parameter
19893
19917
  // is annotated with its own callable type. This can lead to
19894
19918
  // infinite recursion.
19895
- if ((0, types_1.isFunction)(memberTypeFirstParamType) || (0, types_1.isOverloaded)(memberTypeFirstParamType)) {
19919
+ if ((0, types_1.isFunctionOrOverloaded)(memberTypeFirstParamType)) {
19896
19920
  if ((0, types_1.isClassInstance)(firstParamType) && types_1.ClassType.isProtocolClass(firstParamType)) {
19897
19921
  if (subDiag) {
19898
19922
  subDiag.addMessage(localize_1.LocMessage.bindTypeMismatch().format({