@zzzen/pyright-internal 1.2.0-dev.20230917 → 1.2.0-dev.20231001

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/checker.d.ts +1 -0
  2. package/dist/analyzer/checker.js +64 -4
  3. package/dist/analyzer/checker.js.map +1 -1
  4. package/dist/analyzer/codeFlowEngine.js +8 -1
  5. package/dist/analyzer/codeFlowEngine.js.map +1 -1
  6. package/dist/analyzer/constructors.js +6 -0
  7. package/dist/analyzer/constructors.js.map +1 -1
  8. package/dist/analyzer/decorators.js +5 -2
  9. package/dist/analyzer/decorators.js.map +1 -1
  10. package/dist/analyzer/operations.js +4 -2
  11. package/dist/analyzer/operations.js.map +1 -1
  12. package/dist/analyzer/parseTreeUtils.js +3 -0
  13. package/dist/analyzer/parseTreeUtils.js.map +1 -1
  14. package/dist/analyzer/patternMatching.js +48 -16
  15. package/dist/analyzer/patternMatching.js.map +1 -1
  16. package/dist/analyzer/program.d.ts +2 -3
  17. package/dist/analyzer/program.js +6 -6
  18. package/dist/analyzer/program.js.map +1 -1
  19. package/dist/analyzer/protocols.js +7 -5
  20. package/dist/analyzer/protocols.js.map +1 -1
  21. package/dist/analyzer/service.d.ts +4 -4
  22. package/dist/analyzer/service.js +4 -18
  23. package/dist/analyzer/service.js.map +1 -1
  24. package/dist/analyzer/sourceFile.d.ts +3 -1
  25. package/dist/analyzer/sourceFile.js +9 -5
  26. package/dist/analyzer/sourceFile.js.map +1 -1
  27. package/dist/analyzer/sourceMapper.d.ts +1 -0
  28. package/dist/analyzer/sourceMapper.js +9 -4
  29. package/dist/analyzer/sourceMapper.js.map +1 -1
  30. package/dist/analyzer/typeEvaluator.js +119 -20
  31. package/dist/analyzer/typeEvaluator.js.map +1 -1
  32. package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -1
  33. package/dist/analyzer/typeGuards.d.ts +1 -1
  34. package/dist/analyzer/typeGuards.js +4 -3
  35. package/dist/analyzer/typeGuards.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +1 -0
  37. package/dist/analyzer/typeUtils.js +21 -2
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typedDicts.js +20 -16
  40. package/dist/analyzer/typedDicts.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +2 -0
  42. package/dist/analyzer/types.js +11 -2
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.js +1 -23
  45. package/dist/backgroundAnalysisBase.js.map +1 -1
  46. package/dist/common/configOptions.d.ts +1 -0
  47. package/dist/common/configOptions.js +4 -0
  48. package/dist/common/configOptions.js.map +1 -1
  49. package/dist/common/diagnosticRules.d.ts +1 -0
  50. package/dist/common/diagnosticRules.js +1 -0
  51. package/dist/common/diagnosticRules.js.map +1 -1
  52. package/dist/common/extensibility.d.ts +9 -24
  53. package/dist/common/extensibility.js +1 -91
  54. package/dist/common/extensibility.js.map +1 -1
  55. package/dist/common/pathUtils.d.ts +3 -0
  56. package/dist/common/pathUtils.js +14 -9
  57. package/dist/common/pathUtils.js.map +1 -1
  58. package/dist/common/realFileSystem.js +3 -3
  59. package/dist/common/realFileSystem.js.map +1 -1
  60. package/dist/common/serviceProvider.d.ts +23 -4
  61. package/dist/common/serviceProvider.js +92 -7
  62. package/dist/common/serviceProvider.js.map +1 -1
  63. package/dist/common/serviceProviderExtensions.d.ts +4 -1
  64. package/dist/common/serviceProviderExtensions.js +4 -2
  65. package/dist/common/serviceProviderExtensions.js.map +1 -1
  66. package/dist/languageServerBase.js +0 -3
  67. package/dist/languageServerBase.js.map +1 -1
  68. package/dist/languageService/autoImporter.d.ts +4 -1
  69. package/dist/languageService/autoImporter.js +12 -1
  70. package/dist/languageService/autoImporter.js.map +1 -1
  71. package/dist/languageService/definitionProvider.d.ts +3 -2
  72. package/dist/languageService/definitionProvider.js +13 -10
  73. package/dist/languageService/definitionProvider.js.map +1 -1
  74. package/dist/languageService/documentSymbolCollector.js +16 -14
  75. package/dist/languageService/documentSymbolCollector.js.map +1 -1
  76. package/dist/languageService/hoverProvider.js +7 -7
  77. package/dist/languageService/hoverProvider.js.map +1 -1
  78. package/dist/localization/localize.d.ts +8 -1
  79. package/dist/localization/localize.js +4 -1
  80. package/dist/localization/localize.js.map +1 -1
  81. package/dist/localization/package.nls.cs.json +10 -6
  82. package/dist/localization/package.nls.de.json +13 -9
  83. package/dist/localization/package.nls.en-us.json +4 -1
  84. package/dist/localization/package.nls.es.json +10 -6
  85. package/dist/localization/package.nls.fr.json +10 -6
  86. package/dist/localization/package.nls.it.json +10 -6
  87. package/dist/localization/package.nls.ja.json +10 -6
  88. package/dist/localization/package.nls.ko.json +10 -6
  89. package/dist/localization/package.nls.pl.json +9 -5
  90. package/dist/localization/package.nls.pt-br.json +10 -6
  91. package/dist/localization/package.nls.qps-ploc.json +8 -4
  92. package/dist/localization/package.nls.ru.json +9 -5
  93. package/dist/localization/package.nls.tr.json +10 -6
  94. package/dist/localization/package.nls.zh-cn.json +10 -6
  95. package/dist/localization/package.nls.zh-tw.json +10 -6
  96. package/dist/tests/importResolver.test.js +654 -481
  97. package/dist/tests/importResolver.test.js.map +1 -1
  98. package/dist/tests/pathUtils.test.js +64 -4
  99. package/dist/tests/pathUtils.test.js.map +1 -1
  100. package/dist/tests/sourceFile.test.js +2 -1
  101. package/dist/tests/sourceFile.test.js.map +1 -1
  102. package/dist/tests/typeEvaluator1.test.js +2 -2
  103. package/dist/tests/typeEvaluator1.test.js.map +1 -1
  104. package/dist/tests/typeEvaluator2.test.js +3 -1
  105. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  106. package/dist/tests/typeEvaluator3.test.js +7 -1
  107. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  108. package/dist/tests/typeEvaluator4.test.js +5 -0
  109. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  110. package/dist/tests/typeEvaluator5.test.js +1 -1
  111. package/package.json +3 -2
@@ -392,6 +392,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
392
392
  }
393
393
  }
394
394
  }
395
+ if (type) {
396
+ type = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(type);
397
+ }
395
398
  return type;
396
399
  }
397
400
  function getTypeResult(node) {
@@ -659,6 +662,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
659
662
  if (expectingInstantiable) {
660
663
  validateTypeIsInstantiable(typeResult, flags, node);
661
664
  }
665
+ // Should we disable type promotions for bytes?
666
+ if ((0, types_1.isInstantiableClass)(typeResult.type) &&
667
+ typeResult.type.includePromotions &&
668
+ !typeResult.type.includeSubclasses &&
669
+ types_1.ClassType.isBuiltIn(typeResult.type, 'bytes')) {
670
+ if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.disableBytesTypePromotions) {
671
+ typeResult = {
672
+ ...typeResult,
673
+ type: types_1.ClassType.cloneRemoveTypePromotions(typeResult.type),
674
+ };
675
+ }
676
+ }
662
677
  writeTypeCache(node, typeResult, flags, inferenceContext, /* allowSpeculativeCaching */ true);
663
678
  // If there was an expected type, make sure that the result type is compatible.
664
679
  if (inferenceContext &&
@@ -929,6 +944,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
929
944
  type: getBuiltInObject(node, isBytes ? 'bytes' : 'str'),
930
945
  isIncomplete,
931
946
  };
947
+ if ((0, types_1.isClass)(typeResult.type) && typeResult.type.includePromotions) {
948
+ typeResult.type = types_1.ClassType.cloneRemoveTypePromotions(typeResult.type);
949
+ }
932
950
  }
933
951
  }
934
952
  else {
@@ -1295,7 +1313,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
1295
1313
  !types_1.ClassType.isBuiltIn(metaclass, 'type') &&
1296
1314
  !types_1.ClassType.isSameGenericClass(metaclass, classType)) {
1297
1315
  const metaclassMemberInfo = getTypeOfClassMemberName(errorNode, metaclass,
1298
- /* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags, classType);
1316
+ /* isAccessedThroughObject */ false, memberName, usage, metaclassDiag, memberAccessFlags | 128 /* SkipAttributeAccessOverride */, classType);
1299
1317
  if (metaclassMemberInfo && (0, typeUtils_1.isDescriptorInstance)(metaclassMemberInfo.type)) {
1300
1318
  considerMetaclassOnly = true;
1301
1319
  }
@@ -2326,6 +2344,34 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2326
2344
  });
2327
2345
  writeTypeCache(target, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
2328
2346
  }
2347
+ // If the type includes promotion types, expand these to their constituent types.
2348
+ function expandPromotionTypes(node, type, excludeBytes = false) {
2349
+ return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
2350
+ if (!(0, types_1.isClass)(subtype) || !subtype.includePromotions) {
2351
+ return subtype;
2352
+ }
2353
+ if (excludeBytes && types_1.ClassType.isBuiltIn(subtype, 'bytes')) {
2354
+ return subtype;
2355
+ }
2356
+ const typesToCombine = [types_1.ClassType.cloneRemoveTypePromotions(subtype)];
2357
+ const promotionTypeNames = typePromotions.get(subtype.details.fullName);
2358
+ if (promotionTypeNames) {
2359
+ for (const promotionTypeName of promotionTypeNames) {
2360
+ const nameSplit = promotionTypeName.split('.');
2361
+ let promotionSubtype = getBuiltInType(node, nameSplit[nameSplit.length - 1]);
2362
+ if (promotionSubtype && (0, types_1.isInstantiableClass)(promotionSubtype)) {
2363
+ promotionSubtype = types_1.ClassType.cloneRemoveTypePromotions(promotionSubtype);
2364
+ if ((0, types_1.isClassInstance)(subtype)) {
2365
+ promotionSubtype = types_1.ClassType.cloneAsInstance(promotionSubtype);
2366
+ }
2367
+ promotionSubtype = (0, typeUtils_1.addConditionToType)(promotionSubtype, subtype.condition);
2368
+ typesToCombine.push(promotionSubtype);
2369
+ }
2370
+ }
2371
+ }
2372
+ return (0, types_1.combineTypes)(typesToCombine);
2373
+ });
2374
+ }
2329
2375
  // Replaces all of the top-level TypeVars (as opposed to TypeVars
2330
2376
  // used as type arguments in other types) with their concrete form.
2331
2377
  // If conditionFilter is specified and the TypeVar is a constrained
@@ -2537,6 +2583,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
2537
2583
  inferTypeParameterVarianceForClass(type);
2538
2584
  let typeWasTransformed = false;
2539
2585
  const filteredTypeArgs = type.typeArguments.map((typeArg, index) => {
2586
+ if (index > type.details.typeParameters.length) {
2587
+ return typeArg;
2588
+ }
2540
2589
  const variance = types_1.TypeVarType.getVariance(type.details.typeParameters[index]);
2541
2590
  if (variance !== 3 /* Covariant */) {
2542
2591
  return typeArg;
@@ -3410,7 +3459,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
3410
3459
  const isNotRequired = false;
3411
3460
  // If the base type was incomplete and unbound, don't proceed
3412
3461
  // because false positive errors will be generated.
3413
- if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseTypeResult.type)) {
3462
+ if (baseTypeResult.isIncomplete && (0, types_1.isUnbound)(baseType)) {
3414
3463
  return { type: types_1.UnknownType.create(/* isIncomplete */ true), isIncomplete: true };
3415
3464
  }
3416
3465
  // Handle the special case where the expression is an actual
@@ -6109,6 +6158,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6109
6158
  function validateOverloadedFunctionArguments(errorNode, argList, typeResult, typeVarContext, skipUnknownArgCheck, inferenceContext) {
6110
6159
  let filteredMatchResults = [];
6111
6160
  let contextFreeArgTypes;
6161
+ let isTypeIncomplete = !!typeResult.isIncomplete;
6112
6162
  // Start by evaluating the types of the arguments without any expected
6113
6163
  // type. Also, filter the list of overloads based on the number of
6114
6164
  // positional and named arguments that are present. We do all of this
@@ -6122,6 +6172,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6122
6172
  // intended behavior according to PEP 484.
6123
6173
  const matchResults = matchFunctionArgumentsToParameters(errorNode, argList, { type: overload, isIncomplete: typeResult.isIncomplete }, overloadIndex);
6124
6174
  if (!matchResults.argumentErrors) {
6175
+ // If there is an expected return type, see if it's potentially compatible
6176
+ // with this overload's return type. If not, we'll de-emphasize this overload.
6177
+ if (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType) {
6178
+ const returnType = getFunctionEffectiveReturnType(matchResults.overload);
6179
+ if (!assignType((0, typeUtils_1.replaceTypeVarsWithAny)(inferenceContext.expectedType), (0, typeUtils_1.replaceTypeVarsWithAny)(returnType),
6180
+ /* diag */ undefined,
6181
+ /* destTypeVarContext */ undefined,
6182
+ /* srcTypeVarContext */ undefined, 8 /* SkipSolveTypeVars */)) {
6183
+ matchResults.relevance += -0.5;
6184
+ }
6185
+ }
6125
6186
  filteredMatchResults.push(matchResults);
6126
6187
  }
6127
6188
  overloadIndex++;
@@ -6149,7 +6210,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6149
6210
  diagAddendum.addMessage(localize_1.Localizer.DiagnosticAddendum.argumentTypes().format({ types: argTypes.join(', ') }));
6150
6211
  addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.noOverload().format({ name: functionName }) + diagAddendum.getString(), errorNode);
6151
6212
  }
6152
- return { argumentErrors: true, isTypeIncomplete: false, overloadsUsedForCall: [] };
6213
+ return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall: [] };
6153
6214
  }
6154
6215
  // Create a helper function that evaluates the overload that best
6155
6216
  // matches the arg/param lists.
@@ -6175,7 +6236,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6175
6236
  return evaluateUsingBestMatchingOverload(/* skipUnknownArgCheck */ false);
6176
6237
  }
6177
6238
  let expandedArgTypes = [argList.map((arg) => undefined)];
6178
- let isTypeIncomplete = !!typeResult.isIncomplete;
6179
6239
  while (true) {
6180
6240
  const callResult = validateOverloadsWithExpandedTypes(errorNode, expandedArgTypes, filteredMatchResults, typeVarContext, skipUnknownArgCheck, inferenceContext);
6181
6241
  if (callResult.isTypeIncomplete) {
@@ -6221,7 +6281,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
6221
6281
  result.returnType = types_1.UnknownType.create();
6222
6282
  return { ...result, argumentErrors: true };
6223
6283
  }
6224
- return { argumentErrors: true, isTypeIncomplete: false, overloadsUsedForCall: [] };
6284
+ return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall: [] };
6225
6285
  }
6226
6286
  // Replaces each item in the expandedArgTypes with n items where n is
6227
6287
  // the number of subtypes in a union. The contextFreeArgTypes parameter
@@ -10133,7 +10193,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
10133
10193
  function cloneBuiltinObjectWithLiteral(node, builtInName, value) {
10134
10194
  const type = getBuiltInObject(node, builtInName);
10135
10195
  if ((0, types_1.isClassInstance)(type)) {
10136
- return types_1.ClassType.cloneWithLiteral(type, value);
10196
+ return types_1.ClassType.cloneWithLiteral(types_1.ClassType.cloneRemoveTypePromotions(type), value);
10137
10197
  }
10138
10198
  return types_1.UnknownType.create();
10139
10199
  }
@@ -11145,6 +11205,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11145
11205
  /* declaredMetaclass */ undefined,
11146
11206
  /* effectiveMetaclass */ undefined, ParseTreeUtils.getDocString(node.suite.statements));
11147
11207
  classType.details.typeVarScopeId = ParseTreeUtils.getScopeIdForNode(node);
11208
+ // Is this a special type that supports type promotions according to PEP 484?
11209
+ if (typePromotions.has(classType.details.fullName)) {
11210
+ classType.includePromotions = true;
11211
+ }
11148
11212
  // Some classes refer to themselves within type arguments used within
11149
11213
  // base classes. We'll register the partially-constructed class type
11150
11214
  // to allow these to be resolved.
@@ -11728,7 +11792,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
11728
11792
  node.parameters.forEach((param) => {
11729
11793
  var _a;
11730
11794
  const paramSymbol = AnalyzerNodeInfo.getTypeParameterSymbol(param.name);
11731
- (0, debug_1.assert)(paramSymbol);
11795
+ if (!paramSymbol) {
11796
+ // This can happen if the code is unreachable.
11797
+ return;
11798
+ }
11732
11799
  const typeOfParam = (_a = getDeclaredTypeOfSymbol(paramSymbol, param.name)) === null || _a === void 0 ? void 0 : _a.type;
11733
11800
  if (!typeOfParam || !(0, types_1.isTypeVar)(typeOfParam)) {
11734
11801
  return;
@@ -12157,7 +12224,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
12157
12224
  }
12158
12225
  let defaultValueType;
12159
12226
  if (param.defaultValue) {
12160
- defaultValueType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12227
+ // If this is a stub file, a protocol, an overload, or a class
12228
+ // whose body is a placeholder implementation, treat a "...", as
12229
+ // an "Any" value.
12230
+ let treatEllipsisAsAny = fileInfo.isStubFile || ParseTreeUtils.isSuiteEmpty(node.suite);
12231
+ if (containingClassType && types_1.ClassType.isProtocolClass(containingClassType)) {
12232
+ treatEllipsisAsAny = true;
12233
+ }
12234
+ if (types_1.FunctionType.isOverloaded(functionType) || types_1.FunctionType.isAbstractMethod(functionType)) {
12235
+ treatEllipsisAsAny = true;
12236
+ }
12237
+ defaultValueType = getTypeOfExpression(param.defaultValue, treatEllipsisAsAny ? 1 /* ConvertEllipsisToAny */ : 0 /* None */, (0, typeUtils_1.makeInferenceContext)(annotatedType)).type;
12161
12238
  }
12162
12239
  if (annotatedType) {
12163
12240
  // If there was both a type annotation and a default value, verify
@@ -15526,11 +15603,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15526
15603
  return true;
15527
15604
  }
15528
15605
  // Handle special-case type promotions.
15529
- const promotionList = typePromotions.get(destType.details.fullName);
15530
- if (promotionList &&
15531
- promotionList.some((srcName) => srcType.details.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && srcName === mroClass.details.fullName))) {
15532
- if ((flags & 1 /* EnforceInvariance */) === 0) {
15533
- return true;
15606
+ if (destType.includePromotions) {
15607
+ const promotionList = typePromotions.get(destType.details.fullName);
15608
+ if (promotionList &&
15609
+ promotionList.some((srcName) => srcType.details.mro.some((mroClass) => (0, types_1.isClass)(mroClass) && srcName === mroClass.details.fullName))) {
15610
+ if ((flags & 1 /* EnforceInvariance */) === 0) {
15611
+ return true;
15612
+ }
15534
15613
  }
15535
15614
  }
15536
15615
  // Is it a structural type (i.e. a protocol)? If so, we need to
@@ -15578,6 +15657,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15578
15657
  sourceType: srcErrorTypeText,
15579
15658
  destType: destErrorTypeText,
15580
15659
  }));
15660
+ // Tell the user about the disableBytesTypePromotions if that is involved.
15661
+ if (types_1.ClassType.isBuiltIn(destType, 'bytes')) {
15662
+ const promotions = typePromotions.get(destType.details.fullName);
15663
+ if (promotions && promotions.some((name) => name === srcType.details.fullName)) {
15664
+ diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.bytesTypePromotions());
15665
+ }
15666
+ }
15581
15667
  return false;
15582
15668
  }
15583
15669
  // This function is used to validate or infer the variance of type
@@ -15926,6 +16012,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
15926
16012
  if (includeDiagAddendum) {
15927
16013
  childDiag.addAddendum(assignmentDiag);
15928
16014
  }
16015
+ if (isCompatible && types_1.ClassType.isSameGenericClass(destType, srcType)) {
16016
+ // Add additional notes to help the user if this is a common type mismatch.
16017
+ if (types_1.ClassType.isBuiltIn(destType, 'dict') && srcArgIndex === 1) {
16018
+ childDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.invariantSuggestionDict());
16019
+ }
16020
+ else if (types_1.ClassType.isBuiltIn(destType, 'list')) {
16021
+ childDiag.addMessage(localize_1.Localizer.DiagnosticAddendum.invariantSuggestionList());
16022
+ }
16023
+ }
15929
16024
  }
15930
16025
  else {
15931
16026
  diag.addAddendum(assignmentDiag);
@@ -16310,7 +16405,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16310
16405
  // Handle LiteralString special form.
16311
16406
  if (types_1.ClassType.isBuiltIn(destType, 'LiteralString')) {
16312
16407
  if (types_1.ClassType.isBuiltIn(concreteSrcType, 'str') && concreteSrcType.literalValue !== undefined) {
16313
- return true;
16408
+ return (flags & 1 /* EnforceInvariance */) === 0;
16314
16409
  }
16315
16410
  else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString')) {
16316
16411
  return true;
@@ -16318,7 +16413,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16318
16413
  }
16319
16414
  else if (types_1.ClassType.isBuiltIn(concreteSrcType, 'LiteralString') &&
16320
16415
  strClassType &&
16321
- (0, types_1.isInstantiableClass)(strClassType)) {
16416
+ (0, types_1.isInstantiableClass)(strClassType) &&
16417
+ (flags & 1 /* EnforceInvariance */) === 0) {
16322
16418
  concreteSrcType = types_1.ClassType.cloneAsInstance(strClassType);
16323
16419
  }
16324
16420
  if (!assignClass(types_1.ClassType.cloneAsInstantiable(destType), types_1.ClassType.cloneAsInstantiable(concreteSrcType), diag, destTypeVarContext, srcTypeVarContext, flags, recursionCount,
@@ -16570,7 +16666,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16570
16666
  // If we have no src subtypes remaining but not all dest types have been subsumed
16571
16667
  // by other dest types, then the types are not compatible if we're enforcing invariance.
16572
16668
  if (remainingSrcSubtypes.length === 0) {
16573
- return remainingDestSubtypes.every((destSubtype) => isTypeSubsumedByOtherType(destSubtype, destType.subtypes,
16669
+ return remainingDestSubtypes.every((destSubtype) => isTypeSubsumedByOtherType(destSubtype, destType,
16574
16670
  /* allowAnyToSubsume */ true, recursionCount));
16575
16671
  }
16576
16672
  }
@@ -16627,7 +16723,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16627
16723
  /* diag */ undefined, destTypeVarContext, srcTypeVarContext, flags, recursionCount)) {
16628
16724
  // Determine if the current subtype is subsumed by another subtype
16629
16725
  // in the same union. If so, we can ignore this.
16630
- const isSubtypeSubsumed = isTypeSubsumedByOtherType(subtype, srcType.subtypes,
16726
+ const isSubtypeSubsumed = isTypeSubsumedByOtherType(subtype, srcType,
16631
16727
  /* allowAnyToSubsume */ false, recursionCount);
16632
16728
  // Try again with a concrete version of the subtype.
16633
16729
  if (!isSubtypeSubsumed &&
@@ -16643,9 +16739,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
16643
16739
  return true;
16644
16740
  }
16645
16741
  // Determines whether a type is "subsumed by" (i.e. is a proper subtype of) one
16646
- // of the other types in a list.
16647
- function isTypeSubsumedByOtherType(type, otherTypes, allowAnyToSubsume, recursionCount = 0) {
16742
+ // of the other type.
16743
+ function isTypeSubsumedByOtherType(type, otherType, allowAnyToSubsume, recursionCount = 0) {
16648
16744
  const concreteType = makeTopLevelTypeVarsConcrete(type);
16745
+ const otherTypes = (0, types_1.isUnion)(otherType) ? otherType.subtypes : [otherType];
16649
16746
  for (const otherType of otherTypes) {
16650
16747
  if ((0, types_1.isTypeSame)(otherType, type)) {
16651
16748
  continue;
@@ -18402,7 +18499,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18402
18499
  validateInitSubclassArgs,
18403
18500
  isAfterNodeReachable,
18404
18501
  isNodeReachable,
18405
- isAsymmetricDescriptorAssignment: isAsymmetricAccessorAssignment,
18502
+ isAsymmetricAccessorAssignment,
18406
18503
  suppressDiagnostics,
18407
18504
  getDeclarationsForStringNode,
18408
18505
  getDeclarationsForNameNode,
@@ -18414,8 +18511,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
18414
18511
  getGetterTypeFromProperty,
18415
18512
  getTypeOfArgument,
18416
18513
  markNamesAccessed,
18514
+ expandPromotionTypes,
18417
18515
  makeTopLevelTypeVarsConcrete,
18418
18516
  mapSubtypesExpandTypeVars,
18517
+ isTypeSubsumedByOtherType,
18419
18518
  lookUpSymbolRecursive,
18420
18519
  getDeclaredTypeOfSymbol,
18421
18520
  getEffectiveTypeOfSymbol,