@zzzen/pyright-internal 1.2.0-dev.20240602 → 1.2.0-dev.20240609

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 (95) hide show
  1. package/dist/analyzer/binder.js +14 -8
  2. package/dist/analyzer/binder.js.map +1 -1
  3. package/dist/analyzer/checker.js +47 -30
  4. package/dist/analyzer/checker.js.map +1 -1
  5. package/dist/analyzer/constraintSolver.js +26 -34
  6. package/dist/analyzer/constraintSolver.js.map +1 -1
  7. package/dist/analyzer/constructorTransform.js +1 -1
  8. package/dist/analyzer/constructorTransform.js.map +1 -1
  9. package/dist/analyzer/constructors.js +2 -5
  10. package/dist/analyzer/constructors.js.map +1 -1
  11. package/dist/analyzer/dataClasses.js +1 -1
  12. package/dist/analyzer/dataClasses.js.map +1 -1
  13. package/dist/analyzer/enums.d.ts +1 -1
  14. package/dist/analyzer/enums.js +19 -16
  15. package/dist/analyzer/enums.js.map +1 -1
  16. package/dist/analyzer/operations.js +6 -7
  17. package/dist/analyzer/operations.js.map +1 -1
  18. package/dist/analyzer/parameterUtils.js +1 -13
  19. package/dist/analyzer/parameterUtils.js.map +1 -1
  20. package/dist/analyzer/patternMatching.js +4 -4
  21. package/dist/analyzer/patternMatching.js.map +1 -1
  22. package/dist/analyzer/properties.js +2 -2
  23. package/dist/analyzer/properties.js.map +1 -1
  24. package/dist/analyzer/protocols.js +2 -2
  25. package/dist/analyzer/protocols.js.map +1 -1
  26. package/dist/analyzer/sourceFile.js +3 -3
  27. package/dist/analyzer/sourceFile.js.map +1 -1
  28. package/dist/analyzer/typeEvaluator.js +279 -209
  29. package/dist/analyzer/typeEvaluator.js.map +1 -1
  30. package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
  31. package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
  32. package/dist/analyzer/typeGuards.js +3 -2
  33. package/dist/analyzer/typeGuards.js.map +1 -1
  34. package/dist/analyzer/typePrinter.js +21 -14
  35. package/dist/analyzer/typePrinter.js.map +1 -1
  36. package/dist/analyzer/typeUtils.d.ts +3 -4
  37. package/dist/analyzer/typeUtils.js +89 -124
  38. package/dist/analyzer/typeUtils.js.map +1 -1
  39. package/dist/analyzer/typeVarContext.js +4 -0
  40. package/dist/analyzer/typeVarContext.js.map +1 -1
  41. package/dist/analyzer/types.d.ts +11 -12
  42. package/dist/analyzer/types.js +137 -169
  43. package/dist/analyzer/types.js.map +1 -1
  44. package/dist/backgroundAnalysisBase.d.ts +1 -1
  45. package/dist/backgroundAnalysisBase.js +3 -3
  46. package/dist/commands/dumpFileDebugInfoCommand.js +1 -1
  47. package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
  48. package/dist/common/configOptions.d.ts +2 -1
  49. package/dist/common/configOptions.js +12 -3
  50. package/dist/common/configOptions.js.map +1 -1
  51. package/dist/common/realFileSystem.d.ts +3 -3
  52. package/dist/common/realFileSystem.js +6 -6
  53. package/dist/common/realFileSystem.js.map +1 -1
  54. package/dist/languageServerBase.js +1 -1
  55. package/dist/languageServerBase.js.map +1 -1
  56. package/dist/languageService/workspaceSymbolProvider.js +1 -1
  57. package/dist/localization/localize.d.ts +6 -0
  58. package/dist/localization/localize.js +3 -0
  59. package/dist/localization/localize.js.map +1 -1
  60. package/dist/localization/package.nls.cs.json +2 -2
  61. package/dist/localization/package.nls.de.json +2 -2
  62. package/dist/localization/package.nls.en-us.json +3 -0
  63. package/dist/localization/package.nls.es.json +2 -2
  64. package/dist/localization/package.nls.fr.json +2 -2
  65. package/dist/localization/package.nls.it.json +2 -2
  66. package/dist/localization/package.nls.ja.json +2 -2
  67. package/dist/localization/package.nls.ko.json +3 -3
  68. package/dist/localization/package.nls.pl.json +2 -2
  69. package/dist/localization/package.nls.pt-br.json +2 -2
  70. package/dist/localization/package.nls.qps-ploc.json +2 -2
  71. package/dist/localization/package.nls.ru.json +2 -2
  72. package/dist/localization/package.nls.tr.json +2 -2
  73. package/dist/localization/package.nls.zh-cn.json +2 -2
  74. package/dist/localization/package.nls.zh-tw.json +2 -2
  75. package/dist/pyright.js +3 -0
  76. package/dist/pyright.js.map +1 -1
  77. package/dist/tests/config.test.js +2 -2
  78. package/dist/tests/config.test.js.map +1 -1
  79. package/dist/tests/diagnosticOverrides.test.js +7 -6
  80. package/dist/tests/diagnosticOverrides.test.js.map +1 -1
  81. package/dist/tests/testState.test.js +1 -1
  82. package/dist/tests/testState.test.js.map +1 -1
  83. package/dist/tests/testUtils.js +1 -1
  84. package/dist/tests/testUtils.js.map +1 -1
  85. package/dist/tests/typeEvaluator2.test.js +4 -0
  86. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  87. package/dist/tests/typeEvaluator3.test.js +8 -0
  88. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  89. package/dist/tests/typeEvaluator4.test.js +7 -3
  90. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  91. package/dist/tests/typeEvaluator7.test.js +15 -9
  92. package/dist/tests/typeEvaluator7.test.js.map +1 -1
  93. package/dist/tests/typePrinter.test.js +2 -2
  94. package/dist/tests/typePrinter.test.js.map +1 -1
  95. package/package.json +1 -1
@@ -4,6 +4,7 @@ import { TypeVarContext, TypeVarSignatureContext } from './typeVarContext';
4
4
  export interface ClassMember {
5
5
  symbol: Symbol;
6
6
  classType: ClassType | UnknownType | AnyType;
7
+ unspecializedClassType: ClassType | UnknownType | AnyType;
7
8
  isInstanceMember: boolean;
8
9
  isClassMember: boolean;
9
10
  isClassVar: boolean;
@@ -112,7 +113,7 @@ export declare function specializeWithUnknownTypeArgs(type: ClassType): ClassTyp
112
113
  export declare function getUnknownTypeForTypeVar(typeVar: TypeVarType): Type;
113
114
  export declare function getUnknownTypeForParamSpec(): FunctionType;
114
115
  export declare function getUnknownTypeForCallable(): FunctionType;
115
- export declare function selfSpecializeClass(type: ClassType): ClassType;
116
+ export declare function selfSpecializeClass(type: ClassType, overrideTypeArgs?: boolean): ClassType;
116
117
  export declare function getSpecializedTupleType(type: Type): ClassType | undefined;
117
118
  export declare function isLiteralType(type: ClassType): boolean;
118
119
  export declare function isLiteralTypeOrUnion(type: Type, allowNone?: boolean): boolean;
@@ -172,8 +173,6 @@ export declare function isPartlyUnknown(type: Type, recursionCount?: number): bo
172
173
  export declare function explodeGenericClass(classType: ClassType): Type;
173
174
  export declare function combineSameSizedTuples(type: Type, tupleType: Type | undefined): Type;
174
175
  export declare function specializeTupleClass(classType: ClassType, typeArgs: TupleTypeArgument[], isTypeArgumentExplicit?: boolean, isUnpackedTuple?: boolean): ClassType;
175
- export declare function removeParamSpecVariadicsFromSignature(type: FunctionType | OverloadedFunctionType): FunctionType | OverloadedFunctionType;
176
- export declare function removeParamSpecVariadicsFromFunction(type: FunctionType): FunctionType;
177
176
  export declare function getGeneratorTypeArgs(returnType: Type): Type[] | undefined;
178
177
  export declare function requiresTypeArguments(classType: ClassType): boolean;
179
178
  export declare function requiresSpecialization(type: Type, options?: RequiresSpecializationOptions, recursionCount?: number): boolean;
@@ -182,4 +181,4 @@ export declare function isVarianceOfTypeArgumentCompatible(type: Type, typeParam
182
181
  export declare function computeMroLinearization(classType: ClassType): boolean;
183
182
  export declare function getDeclaringModulesForType(type: Type): string[];
184
183
  export declare function convertTypeToParamSpecValue(type: Type): FunctionType;
185
- export declare function convertParamSpecValueToType(paramSpecValue: FunctionType, omitParamSpec?: boolean): Type;
184
+ export declare function convertParamSpecValueToType(type: FunctionType): Type;
@@ -9,8 +9,8 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.selfSpecializeClass = exports.getUnknownTypeForCallable = exports.getUnknownTypeForParamSpec = exports.getUnknownTypeForTypeVar = exports.specializeWithUnknownTypeArgs = exports.specializeWithDefaultTypeArgs = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSignature = exports.allSubtypes = exports.someSubtypes = exports.doForEachSubtype = exports.sortTypes = exports.cleanIncompleteUnknown = exports.mapSignatures = exports.mapSubtypes = exports.makeInferenceContext = exports.isBuiltInDeprecatedType = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
12
- exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = void 0;
13
- exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = void 0;
12
+ exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = void 0;
13
+ exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = void 0;
14
14
  const collectionUtils_1 = require("../common/collectionUtils");
15
15
  const debug_1 = require("../common/debug");
16
16
  const symbol_1 = require("./symbol");
@@ -431,7 +431,7 @@ function compareTypes(a, b, recursionCount = 0) {
431
431
  return typeComparison;
432
432
  }
433
433
  }
434
- const returnTypeComparison = compareTypes((_a = types_1.FunctionType.getSpecializedReturnType(a)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(), (_b = types_1.FunctionType.getSpecializedReturnType(bFunc)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create());
434
+ const returnTypeComparison = compareTypes((_a = types_1.FunctionType.getEffectiveReturnType(a)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(), (_b = types_1.FunctionType.getEffectiveReturnType(bFunc)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create());
435
435
  if (returnTypeComparison !== 0) {
436
436
  return returnTypeComparison;
437
437
  }
@@ -631,12 +631,12 @@ function derivesFromAnyOrUnknown(type) {
631
631
  anyOrUnknown = true;
632
632
  }
633
633
  else if ((0, types_1.isInstantiableClass)(subtype)) {
634
- if (types_1.ClassType.hasUnknownBaseClass(subtype)) {
634
+ if (types_1.ClassType.derivesFromAnyOrUnknown(subtype)) {
635
635
  anyOrUnknown = true;
636
636
  }
637
637
  }
638
638
  else if ((0, types_1.isClassInstance)(subtype)) {
639
- if (types_1.ClassType.hasUnknownBaseClass(subtype)) {
639
+ if (types_1.ClassType.derivesFromAnyOrUnknown(subtype)) {
640
640
  anyOrUnknown = true;
641
641
  }
642
642
  }
@@ -829,14 +829,14 @@ function getUnknownTypeForTypeVar(typeVar) {
829
829
  exports.getUnknownTypeForTypeVar = getUnknownTypeForTypeVar;
830
830
  // Returns the "Unknown" equivalent for a ParamSpec.
831
831
  function getUnknownTypeForParamSpec() {
832
- const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */);
832
+ const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
833
833
  types_1.FunctionType.addDefaultParameters(newFunction);
834
834
  return newFunction;
835
835
  }
836
836
  exports.getUnknownTypeForParamSpec = getUnknownTypeForParamSpec;
837
837
  // Returns the equivalent of "Callable[..., Unknown]".
838
838
  function getUnknownTypeForCallable() {
839
- const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck */);
839
+ const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
840
840
  types_1.FunctionType.addDefaultParameters(newFunction);
841
841
  newFunction.details.declaredReturnType = types_1.UnknownType.create();
842
842
  return newFunction;
@@ -845,8 +845,11 @@ exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
845
845
  // If the class is generic and not already specialized, this function
846
846
  // "self specializes" the class, filling in its own type parameters
847
847
  // as type arguments.
848
- function selfSpecializeClass(type) {
849
- if (type.details.typeParameters.length === 0 || type.typeArguments) {
848
+ function selfSpecializeClass(type, overrideTypeArgs = false) {
849
+ if (type.details.typeParameters.length === 0) {
850
+ return type;
851
+ }
852
+ if (type.typeArguments && !overrideTypeArgs) {
850
853
  return type;
851
854
  }
852
855
  return types_1.ClassType.cloneForSpecialization(type, type.details.typeParameters, /* isTypeArgumentExplicit */ true);
@@ -1236,6 +1239,7 @@ function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 16384 /*
1236
1239
  symbolMap.set(name, {
1237
1240
  symbol,
1238
1241
  classType,
1242
+ unspecializedClassType: classType,
1239
1243
  isInstanceMember: symbol.isInstanceMember(),
1240
1244
  isClassMember: symbol.isClassMember(),
1241
1245
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, /* isDataclass */ false),
@@ -1343,6 +1347,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1343
1347
  for (const [mroClass, specializedMroClass] of classItr) {
1344
1348
  if (!(0, types_1.isInstantiableClass)(mroClass)) {
1345
1349
  if (!declaredTypesOnly) {
1350
+ const classType = (0, types_1.isAnyOrUnknown)(mroClass) ? mroClass : types_1.UnknownType.create();
1346
1351
  // The class derives from an unknown type, so all bets are off
1347
1352
  // when trying to find a member. Return an unknown symbol.
1348
1353
  const cm = {
@@ -1350,7 +1355,8 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1350
1355
  isInstanceMember: false,
1351
1356
  isClassMember: true,
1352
1357
  isClassVar: false,
1353
- classType: (0, types_1.isAnyOrUnknown)(mroClass) ? mroClass : types_1.UnknownType.create(),
1358
+ classType,
1359
+ unspecializedClassType: classType,
1354
1360
  isTypeDeclared: false,
1355
1361
  skippedUndeclaredType: false,
1356
1362
  };
@@ -1374,6 +1380,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1374
1380
  isClassMember: symbol.isClassMember(),
1375
1381
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, types_1.ClassType.isDataClass(specializedMroClass)),
1376
1382
  classType: specializedMroClass,
1383
+ unspecializedClassType: mroClass,
1377
1384
  isTypeDeclared: hasDeclaredType,
1378
1385
  skippedUndeclaredType,
1379
1386
  };
@@ -1412,6 +1419,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1412
1419
  isClassMember,
1413
1420
  isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, isDataclass),
1414
1421
  classType: specializedMroClass,
1422
+ unspecializedClassType: mroClass,
1415
1423
  isTypeDeclared: hasDeclaredType,
1416
1424
  skippedUndeclaredType,
1417
1425
  };
@@ -1433,6 +1441,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
1433
1441
  isClassMember: true,
1434
1442
  isClassVar: false,
1435
1443
  classType,
1444
+ unspecializedClassType: classType,
1436
1445
  isTypeDeclared: false,
1437
1446
  skippedUndeclaredType: false,
1438
1447
  };
@@ -1496,6 +1505,7 @@ function getClassFieldsRecursive(classType) {
1496
1505
  if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
1497
1506
  memberMap.set(name, {
1498
1507
  classType: specializedMroClass,
1508
+ unspecializedClassType: mroClass,
1499
1509
  symbol,
1500
1510
  isInstanceMember: symbol.isInstanceMember(),
1501
1511
  isClassMember: symbol.isClassMember(),
@@ -1553,7 +1563,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
1553
1563
  }
1554
1564
  // Don't return any P.args or P.kwargs types.
1555
1565
  if ((0, types_1.isParamSpec)(type) && type.paramSpecAccess) {
1556
- return [];
1566
+ return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
1557
1567
  }
1558
1568
  return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
1559
1569
  }
@@ -1579,10 +1589,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
1579
1589
  for (let i = 0; i < type.details.parameters.length; i++) {
1580
1590
  addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), recursionCount));
1581
1591
  }
1582
- if (type.details.paramSpec) {
1583
- addTypeVarsToListIfUnique(combinedList, [type.details.paramSpec]);
1584
- }
1585
- const returnType = types_1.FunctionType.getSpecializedReturnType(type);
1592
+ const returnType = types_1.FunctionType.getEffectiveReturnType(type);
1586
1593
  if (returnType) {
1587
1594
  addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
1588
1595
  }
@@ -1647,12 +1654,6 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
1647
1654
  setTypeArgumentsRecursive(destType.details.declaredReturnType, srcType, typeVarContext, recursionCount);
1648
1655
  }
1649
1656
  }
1650
- if (destType.details.paramSpec) {
1651
- // Fill in an empty signature for a ParamSpec.
1652
- if (!typeVarContext.getPrimarySignature().getTypeVar(destType.details.paramSpec)) {
1653
- typeVarContext.setTypeVarType(destType.details.paramSpec, getUnknownTypeForParamSpec());
1654
- }
1655
- }
1656
1657
  break;
1657
1658
  case 5 /* TypeCategory.OverloadedFunction */:
1658
1659
  destType.overloads.forEach((subtype) => {
@@ -1674,7 +1675,7 @@ exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
1674
1675
  function buildTypeVarContextFromSpecializedClass(classType) {
1675
1676
  const typeParameters = types_1.ClassType.getTypeParameters(classType);
1676
1677
  const typeVarContext = buildTypeVarContext(typeParameters, classType.typeArguments, getTypeVarScopeId(classType));
1677
- if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments && typeParameters.length >= 1) {
1678
+ if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments) {
1678
1679
  typeVarContext.setTupleTypeVar(typeParameters[0], classType.tupleTypeArguments);
1679
1680
  }
1680
1681
  return typeVarContext;
@@ -1780,7 +1781,7 @@ exports.synthesizeTypeVarForSelfCls = synthesizeTypeVarForSelfCls;
1780
1781
  // Returns the declared "return" type (the type returned from a return statement)
1781
1782
  // if it was declared, or undefined otherwise.
1782
1783
  function getDeclaredGeneratorReturnType(functionType) {
1783
- const returnType = types_1.FunctionType.getSpecializedReturnType(functionType);
1784
+ const returnType = types_1.FunctionType.getEffectiveReturnType(functionType);
1784
1785
  if (returnType) {
1785
1786
  const generatorTypeArgs = getGeneratorTypeArgs(returnType);
1786
1787
  if (generatorTypeArgs) {
@@ -2056,7 +2057,7 @@ function containsAnyOrUnknown(type, recurse) {
2056
2057
  visitFunction(type) {
2057
2058
  if (this._recurse) {
2058
2059
  // A function with a "..." type is effectively an "Any".
2059
- if (types_1.FunctionType.shouldSkipArgsKwargsCompatibilityCheck(type)) {
2060
+ if (types_1.FunctionType.isGradualCallableForm(type)) {
2060
2061
  this.anyOrUnknownType = this.anyOrUnknownType
2061
2062
  ? preserveUnknown(this.anyOrUnknownType, types_1.AnyType.create())
2062
2063
  : types_1.AnyType.create();
@@ -2221,42 +2222,6 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
2221
2222
  return clonedClassType;
2222
2223
  }
2223
2224
  exports.specializeTupleClass = specializeTupleClass;
2224
- // If the type is a function or overloaded function that has a paramSpec
2225
- // associated with it and P.args and P.kwargs at the end of the signature,
2226
- // it removes these parameters from the function.
2227
- function removeParamSpecVariadicsFromSignature(type) {
2228
- if ((0, types_1.isFunction)(type)) {
2229
- return removeParamSpecVariadicsFromFunction(type);
2230
- }
2231
- const newOverloads = [];
2232
- let newTypeNeeded = false;
2233
- for (const overload of type.overloads) {
2234
- const newOverload = removeParamSpecVariadicsFromFunction(overload);
2235
- newOverloads.push(newOverload);
2236
- if (newOverload !== overload) {
2237
- newTypeNeeded = true;
2238
- }
2239
- }
2240
- return newTypeNeeded ? types_1.OverloadedFunctionType.create(newOverloads) : type;
2241
- }
2242
- exports.removeParamSpecVariadicsFromSignature = removeParamSpecVariadicsFromSignature;
2243
- function removeParamSpecVariadicsFromFunction(type) {
2244
- const paramCount = type.details.parameters.length;
2245
- if (paramCount < 2) {
2246
- return type;
2247
- }
2248
- const argsParam = type.details.parameters[paramCount - 2];
2249
- const kwargsParam = type.details.parameters[paramCount - 1];
2250
- if (argsParam.category !== 1 /* ParameterCategory.ArgsList */ ||
2251
- kwargsParam.category !== 2 /* ParameterCategory.KwargsDict */ ||
2252
- !(0, types_1.isParamSpec)(argsParam.type) ||
2253
- !(0, types_1.isParamSpec)(kwargsParam.type) ||
2254
- !(0, types_1.isTypeSame)(argsParam.type, kwargsParam.type)) {
2255
- return type;
2256
- }
2257
- return types_1.FunctionType.cloneRemoveParamSpecVariadics(type, types_1.TypeVarType.cloneForParamSpecAccess(argsParam.type, /* access */ undefined));
2258
- }
2259
- exports.removeParamSpecVariadicsFromFunction = removeParamSpecVariadicsFromFunction;
2260
2225
  function _expandVariadicUnpackedUnion(type) {
2261
2226
  if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.tupleTypeArguments && type.isUnpacked) {
2262
2227
  return (0, types_1.combineTypes)(type.tupleTypeArguments.map((t) => t.type));
@@ -2359,9 +2324,6 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
2359
2324
  return types_1.ClassType.getTypeParameters(type).length > 0;
2360
2325
  }
2361
2326
  case 4 /* TypeCategory.Function */: {
2362
- if (type.details.paramSpec) {
2363
- return true;
2364
- }
2365
2327
  for (let i = 0; i < type.details.parameters.length; i++) {
2366
2328
  if (requiresSpecialization(types_1.FunctionType.getEffectiveParameterType(type, i), options, recursionCount)) {
2367
2329
  return true;
@@ -2519,7 +2481,9 @@ function computeMroLinearization(classType) {
2519
2481
  }));
2520
2482
  // The first class in the MRO is the class itself.
2521
2483
  const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
2522
- classType.details.mro.push(applySolvedTypeVars(classType, typeVarContext));
2484
+ const specializedClassType = applySolvedTypeVars(classType, typeVarContext);
2485
+ (0, debug_1.assert)((0, types_1.isClass)(specializedClassType) || (0, types_1.isAny)(specializedClassType) || (0, types_1.isUnknown)(specializedClassType));
2486
+ classType.details.mro.push(specializedClassType);
2523
2487
  // Helper function that returns true if the specified searchClass
2524
2488
  // is found in the "tail" (i.e. in elements 1 through n) of any
2525
2489
  // of the class lists.
@@ -2549,6 +2513,7 @@ function computeMroLinearization(classType) {
2549
2513
  }
2550
2514
  if (!(0, types_1.isInstantiableClass)(classList[0])) {
2551
2515
  foundValidHead = true;
2516
+ (0, debug_1.assert)((0, types_1.isClass)(classList[0]) || (0, types_1.isAnyOrUnknown)(classList[0]));
2552
2517
  classType.details.mro.push(classList[0]);
2553
2518
  classList.shift();
2554
2519
  break;
@@ -2573,6 +2538,7 @@ function computeMroLinearization(classType) {
2573
2538
  // Handle the situation by pull the head off the first empty list.
2574
2539
  // This allows us to make forward progress.
2575
2540
  if (!(0, types_1.isInstantiableClass)(nonEmptyList[0])) {
2541
+ (0, debug_1.assert)((0, types_1.isClass)(nonEmptyList[0]) || (0, types_1.isAnyOrUnknown)(nonEmptyList[0]));
2576
2542
  classType.details.mro.push(nonEmptyList[0]);
2577
2543
  nonEmptyList.shift();
2578
2544
  }
@@ -2631,10 +2597,13 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
2631
2597
  }
2632
2598
  }
2633
2599
  }
2600
+ // Converts a function into a FunctionType that represents the function's
2601
+ // input signature and converts a ParamSpec into a FunctionType with the input
2602
+ // signature (*args: P.args, **kwargs: P.kwargs).
2634
2603
  function convertTypeToParamSpecValue(type) {
2635
2604
  if ((0, types_1.isParamSpec)(type)) {
2636
2605
  const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */);
2637
- newFunction.details.paramSpec = type;
2606
+ types_1.FunctionType.addParamSpecVariadics(newFunction, type);
2638
2607
  newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
2639
2608
  return newFunction;
2640
2609
  }
@@ -2655,45 +2624,51 @@ function convertTypeToParamSpecValue(type) {
2655
2624
  newFunction.details.higherOrderTypeVarScopeIds = [...type.details.higherOrderTypeVarScopeIds];
2656
2625
  newFunction.details.typeVarScopeId = newFunction.details.higherOrderTypeVarScopeIds.pop();
2657
2626
  }
2658
- newFunction.details.paramSpec = type.details.paramSpec;
2659
2627
  return newFunction;
2660
2628
  }
2661
2629
  return getUnknownTypeForParamSpec();
2662
2630
  }
2663
2631
  exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
2664
- function convertParamSpecValueToType(paramSpecValue, omitParamSpec = false) {
2665
- let hasParameters = paramSpecValue.details.parameters.length > 0;
2666
- if (paramSpecValue.details.parameters.length === 1) {
2632
+ // Converts a FunctionType into a ParamSpec if it consists only of
2633
+ // (* args: P.args, ** kwargs: P.kwargs). Otherwise returns the original type.
2634
+ function convertParamSpecValueToType(type) {
2635
+ const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
2636
+ const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
2637
+ let hasParameters = withoutParamSpec.details.parameters.length > 0;
2638
+ if (withoutParamSpec.details.parameters.length === 1) {
2667
2639
  // If the ParamSpec has a position-only separator as its only parameter,
2668
2640
  // treat it as though there are no parameters.
2669
- const onlyParam = paramSpecValue.details.parameters[0];
2641
+ const onlyParam = withoutParamSpec.details.parameters[0];
2670
2642
  if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
2671
2643
  hasParameters = false;
2672
2644
  }
2673
2645
  }
2674
- if (hasParameters || !paramSpecValue.details.paramSpec || omitParamSpec) {
2675
- // Create a function type from the param spec entries.
2676
- const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | paramSpecValue.details.flags);
2677
- types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, paramSpecValue.details.typeVarScopeId);
2678
- paramSpecValue.details.parameters.forEach((entry) => {
2679
- types_1.FunctionType.addParameter(functionType, {
2680
- category: entry.category,
2681
- name: entry.name,
2682
- hasDefault: entry.hasDefault,
2683
- defaultValueExpression: entry.defaultValueExpression,
2684
- isNameSynthesized: entry.isNameSynthesized,
2685
- hasDeclaredType: true,
2686
- type: entry.type,
2687
- });
2646
+ // Can we simplify it to just a paramSpec?
2647
+ if (!hasParameters && paramSpec) {
2648
+ return paramSpec;
2649
+ }
2650
+ // Create a function type from the param spec entries.
2651
+ const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.details.flags);
2652
+ types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.details.typeVarScopeId);
2653
+ types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.details.higherOrderTypeVarScopeIds);
2654
+ withoutParamSpec.details.parameters.forEach((entry) => {
2655
+ types_1.FunctionType.addParameter(functionType, {
2656
+ category: entry.category,
2657
+ name: entry.name,
2658
+ hasDefault: entry.hasDefault,
2659
+ defaultValueExpression: entry.defaultValueExpression,
2660
+ isNameSynthesized: entry.isNameSynthesized,
2661
+ hasDeclaredType: true,
2662
+ type: entry.type,
2688
2663
  });
2689
- if (!omitParamSpec) {
2690
- functionType.details.paramSpec = paramSpecValue.details.paramSpec;
2691
- }
2692
- functionType.details.docString = paramSpecValue.details.docString;
2693
- functionType.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
2694
- return functionType;
2664
+ });
2665
+ if (paramSpec) {
2666
+ types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
2695
2667
  }
2696
- return paramSpecValue.details.paramSpec;
2668
+ functionType.details.docString = withoutParamSpec.details.docString;
2669
+ functionType.details.deprecatedMessage = withoutParamSpec.details.deprecatedMessage;
2670
+ functionType.details.methodClass = withoutParamSpec.details.methodClass;
2671
+ return functionType;
2697
2672
  }
2698
2673
  exports.convertParamSpecValueToType = convertParamSpecValueToType;
2699
2674
  // Recursively walks a type and calls a callback for each TypeVar, allowing
@@ -2929,11 +2904,19 @@ class TypeVarTransformer {
2929
2904
  (0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
2930
2905
  }
2931
2906
  else {
2932
- newTupleTypeArgs.push({
2933
- type: newTypeArgType,
2934
- isUnbounded: oldTypeArgType.isUnbounded,
2935
- isOptional: oldTypeArgType.isOptional,
2936
- });
2907
+ // Handle the special case where tuple[T, ...] is being specialized
2908
+ // to tuple[Never, ...]. This is equivalent to tuple[()].
2909
+ const isEmptyTuple = oldTypeArgType.isUnbounded &&
2910
+ (0, types_1.isTypeVar)(oldTypeArgType.type) &&
2911
+ (0, types_1.isNever)(newTypeArgType) &&
2912
+ classType.tupleTypeArguments.length === 1;
2913
+ if (!isEmptyTuple) {
2914
+ newTupleTypeArgs.push({
2915
+ type: newTypeArgType,
2916
+ isUnbounded: oldTypeArgType.isUnbounded,
2917
+ isOptional: oldTypeArgType.isOptional,
2918
+ });
2919
+ }
2937
2920
  }
2938
2921
  });
2939
2922
  }
@@ -3020,14 +3003,7 @@ class TypeVarTransformer {
3020
3003
  transformTypeVarsInFunctionType(sourceType, recursionCount) {
3021
3004
  return this.doForEachSignatureContext(() => {
3022
3005
  let functionType = sourceType;
3023
- // Handle functions with a parameter specification in a special manner.
3024
- if (functionType.details.paramSpec) {
3025
- const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
3026
- if (paramSpec) {
3027
- functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
3028
- }
3029
- }
3030
- const declaredReturnType = types_1.FunctionType.getSpecializedReturnType(functionType);
3006
+ const declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionType);
3031
3007
  const specializedReturnType = declaredReturnType
3032
3008
  ? this.apply(declaredReturnType, recursionCount)
3033
3009
  : undefined;
@@ -3036,26 +3012,15 @@ class TypeVarTransformer {
3036
3012
  parameterTypes: [],
3037
3013
  returnType: specializedReturnType,
3038
3014
  };
3039
- // Does this function end with *args: P.args, **args: P.kwargs? If so, we'll
3040
- // modify the function and replace these parameters with the signature captured
3041
- // by the ParamSpec.
3042
- if (functionType.details.parameters.length >= 2) {
3043
- const argsParam = functionType.details.parameters[functionType.details.parameters.length - 2];
3044
- const kwargsParam = functionType.details.parameters[functionType.details.parameters.length - 1];
3045
- const argsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 2);
3046
- const kwargsParamType = types_1.FunctionType.getEffectiveParameterType(functionType, functionType.details.parameters.length - 1);
3047
- if (argsParam.category === 1 /* ParameterCategory.ArgsList */ &&
3048
- kwargsParam.category === 2 /* ParameterCategory.KwargsDict */ &&
3049
- (0, types_1.isParamSpec)(argsParamType) &&
3050
- (0, types_1.isParamSpec)(kwargsParamType) &&
3051
- (0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
3052
- const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
3053
- if (paramSpecType) {
3054
- if (paramSpecType.details.parameters.length > 0 ||
3055
- paramSpecType.details.paramSpec === undefined ||
3056
- !(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
3057
- functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
3058
- }
3015
+ const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
3016
+ if (paramSpec) {
3017
+ const paramSpecType = this.transformParamSpec(paramSpec, recursionCount);
3018
+ if (paramSpecType) {
3019
+ const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecType);
3020
+ if (paramSpecType.details.parameters.length > 0 ||
3021
+ !transformedParamSpec ||
3022
+ !(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
3023
+ functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecType);
3059
3024
  }
3060
3025
  }
3061
3026
  }