@zzzen/pyright-internal 1.2.0-dev.20230528 → 1.2.0-dev.20230604

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 (41) hide show
  1. package/dist/analyzer/constraintSolver.d.ts +1 -1
  2. package/dist/analyzer/constraintSolver.js +18 -6
  3. package/dist/analyzer/constraintSolver.js.map +1 -1
  4. package/dist/analyzer/constructors.js +35 -10
  5. package/dist/analyzer/constructors.js.map +1 -1
  6. package/dist/analyzer/patternMatching.js +2 -1
  7. package/dist/analyzer/patternMatching.js.map +1 -1
  8. package/dist/analyzer/program.js +9 -4
  9. package/dist/analyzer/program.js.map +1 -1
  10. package/dist/analyzer/sourceFile.d.ts +3 -2
  11. package/dist/analyzer/sourceFile.js +204 -194
  12. package/dist/analyzer/sourceFile.js.map +1 -1
  13. package/dist/analyzer/typeEvaluator.js +103 -46
  14. package/dist/analyzer/typeEvaluator.js.map +1 -1
  15. package/dist/analyzer/typeGuards.js +1 -1
  16. package/dist/analyzer/typeGuards.js.map +1 -1
  17. package/dist/analyzer/typeUtils.d.ts +5 -6
  18. package/dist/analyzer/typeUtils.js +126 -142
  19. package/dist/analyzer/typeUtils.js.map +1 -1
  20. package/dist/analyzer/typeVarContext.js +12 -1
  21. package/dist/analyzer/typeVarContext.js.map +1 -1
  22. package/dist/analyzer/typeWalker.d.ts +22 -0
  23. package/dist/analyzer/typeWalker.js +164 -0
  24. package/dist/analyzer/typeWalker.js.map +1 -0
  25. package/dist/analyzer/types.d.ts +3 -2
  26. package/dist/analyzer/types.js +19 -12
  27. package/dist/analyzer/types.js.map +1 -1
  28. package/dist/backgroundAnalysisBase.d.ts +4 -2
  29. package/dist/localization/localize.d.ts +4 -0
  30. package/dist/localization/localize.js +2 -0
  31. package/dist/localization/localize.js.map +1 -1
  32. package/dist/localization/package.nls.en-us.json +2 -0
  33. package/dist/tests/service.test.js +10 -0
  34. package/dist/tests/service.test.js.map +1 -1
  35. package/dist/tests/typeEvaluator2.test.js +9 -1
  36. package/dist/tests/typeEvaluator2.test.js.map +1 -1
  37. package/dist/tests/typeEvaluator3.test.js +16 -0
  38. package/dist/tests/typeEvaluator3.test.js.map +1 -1
  39. package/dist/tests/typeEvaluator4.test.js +4 -0
  40. package/dist/tests/typeEvaluator4.test.js.map +1 -1
  41. package/package.json +1 -1
@@ -8,14 +8,15 @@
8
8
  * Functions that operate on Type objects.
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.containsType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = 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.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
12
- exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsUnknown = exports.containsAnyOrUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = void 0;
11
+ exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isUnboundedTupleClass = 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.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSubtype = exports.sortTypes = exports.mapSubtypes = exports.makeInferenceContext = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.ClassMemberLookupFlags = void 0;
12
+ exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.removeParamSpecVariadicsFromFunction = exports.removeParamSpecVariadicsFromSignature = exports.getCommonErasedType = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.isTypeVarLimitedToCallable = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = void 0;
13
13
  const collectionUtils_1 = require("../common/collectionUtils");
14
14
  const debug_1 = require("../common/debug");
15
15
  const symbol_1 = require("./symbol");
16
16
  const symbolUtils_1 = require("./symbolUtils");
17
17
  const types_1 = require("./types");
18
18
  const typeVarContext_1 = require("./typeVarContext");
19
+ const typeWalker_1 = require("./typeWalker");
19
20
  var ClassMemberLookupFlags;
20
21
  (function (ClassMemberLookupFlags) {
21
22
  ClassMemberLookupFlags[ClassMemberLookupFlags["Default"] = 0] = "Default";
@@ -579,49 +580,28 @@ function isLiteralTypeOrUnion(type) {
579
580
  return false;
580
581
  }
581
582
  exports.isLiteralTypeOrUnion = isLiteralTypeOrUnion;
582
- function containsType(type, predicate, includeTypeArgs = false, recursionCount = 0) {
583
- var _a;
584
- if (recursionCount > types_1.maxTypeRecursionCount) {
585
- return false;
586
- }
587
- recursionCount++;
588
- if (predicate(type)) {
589
- return true;
590
- }
591
- if (includeTypeArgs && (0, types_1.isClass)(type)) {
592
- const typeArgs = ((_a = type.tupleTypeArguments) === null || _a === void 0 ? void 0 : _a.map((t) => t.type)) || type.typeArguments;
593
- if (typeArgs) {
594
- return typeArgs.some((typeArg) => containsType(typeArg, predicate, includeTypeArgs, recursionCount));
583
+ function containsLiteralType(type, includeTypeArgs = false) {
584
+ class ContainsLiteralTypeWalker extends typeWalker_1.TypeWalker {
585
+ constructor(_includeTypeArgs) {
586
+ super();
587
+ this._includeTypeArgs = _includeTypeArgs;
588
+ this.foundLiteral = false;
595
589
  }
596
- }
597
- if ((0, types_1.isUnion)(type)) {
598
- return type.subtypes.some((subtype) => containsType(subtype, predicate, includeTypeArgs, recursionCount));
599
- }
600
- if ((0, types_1.isOverloadedFunction)(type)) {
601
- return type.overloads.some((overload) => containsType(overload, predicate, includeTypeArgs, recursionCount));
602
- }
603
- if ((0, types_1.isFunction)(type)) {
604
- const returnType = types_1.FunctionType.getSpecializedReturnType(type);
605
- if (returnType && containsType(returnType, predicate, includeTypeArgs, recursionCount)) {
606
- return true;
607
- }
608
- for (let i = 0; i < type.details.parameters.length; i++) {
609
- const paramType = types_1.FunctionType.getEffectiveParameterType(type, i);
610
- if (containsType(paramType, predicate, includeTypeArgs, recursionCount)) {
611
- return true;
590
+ visitClass(classType) {
591
+ if ((0, types_1.isClassInstance)(classType)) {
592
+ if (isLiteralType(classType) || types_1.ClassType.isBuiltIn(classType, 'LiteralString')) {
593
+ this.foundLiteral = true;
594
+ this.cancelWalk();
595
+ }
596
+ }
597
+ if (this._includeTypeArgs) {
598
+ super.visitClass(classType);
612
599
  }
613
600
  }
614
601
  }
615
- return false;
616
- }
617
- exports.containsType = containsType;
618
- function containsLiteralType(type, includeTypeArgs = false, recursionCount = 0) {
619
- return containsType(type, (t) => {
620
- if (!(0, types_1.isClassInstance)(t)) {
621
- return false;
622
- }
623
- return isLiteralType(t) || types_1.ClassType.isBuiltIn(t, 'LiteralString');
624
- }, includeTypeArgs, recursionCount);
602
+ const walker = new ContainsLiteralTypeWalker(includeTypeArgs);
603
+ walker.walk(type);
604
+ return walker.foundLiteral;
625
605
  }
626
606
  exports.containsLiteralType = containsLiteralType;
627
607
  // If all of the subtypes are literals with the same built-in class (e.g.
@@ -841,8 +821,8 @@ exports.validateTypeVarDefault = validateTypeVarDefault;
841
821
  // expected type uses TypeVars that are not part of the context of the
842
822
  // class we are constructing. We'll replace these type variables with dummy
843
823
  // type variables.
844
- function transformExpectedType(expectedType, liveTypeVarScopes) {
845
- const transformer = new ExpectedTypeTransformer(liveTypeVarScopes);
824
+ function transformExpectedType(expectedType, liveTypeVarScopes, usageOffset) {
825
+ const transformer = new ExpectedTypeTransformer(liveTypeVarScopes, usageOffset);
846
826
  return transformer.apply(expectedType, 0);
847
827
  }
848
828
  exports.transformExpectedType = transformExpectedType;
@@ -1679,93 +1659,60 @@ function getMembersForModule(moduleType, symbolTable) {
1679
1659
  });
1680
1660
  }
1681
1661
  exports.getMembersForModule = getMembersForModule;
1682
- // Determines if the type is an Any or Unknown or a union that
1683
- // contains one of these. It does not look at type arguments.
1684
- function containsAnyOrUnknown(type) {
1685
- let foundAnyOrUnknown = false;
1686
- doForEachSubtype(type, (subtype) => {
1687
- if ((0, types_1.isAnyOrUnknown)(subtype)) {
1688
- foundAnyOrUnknown = true;
1662
+ // Determines if the type contains an Any or Unknown type. If so,
1663
+ // it returns the Any or Unknown type. Unknowns are preferred over
1664
+ // Any if both are present. If recurse is true, it will recurse
1665
+ // through type arguments and parameters.
1666
+ function containsAnyOrUnknown(type, recurse) {
1667
+ class AnyOrUnknownWalker extends typeWalker_1.TypeWalker {
1668
+ constructor(_recurse) {
1669
+ super();
1670
+ this._recurse = _recurse;
1689
1671
  }
1690
- });
1691
- return foundAnyOrUnknown;
1692
- }
1693
- exports.containsAnyOrUnknown = containsAnyOrUnknown;
1694
- // Determines if the type is an Unknown or a union that contains an Unknown.
1695
- // It does not look at type arguments.
1696
- function containsUnknown(type) {
1697
- let foundUnknown = false;
1698
- doForEachSubtype(type, (subtype) => {
1699
- if ((0, types_1.isUnknown)(subtype)) {
1700
- foundUnknown = true;
1672
+ visitUnknown(type) {
1673
+ this.anyOrUnknownType = this.anyOrUnknownType ? preserveUnknown(this.anyOrUnknownType, type) : type;
1701
1674
  }
1702
- });
1703
- return foundUnknown;
1704
- }
1705
- exports.containsUnknown = containsUnknown;
1706
- // Determines if any part of the type contains "Unknown", including any type arguments.
1707
- function isPartlyUnknown(type, allowUnknownTypeArgsForClasses = false, recursionCount = 0) {
1708
- var _a, _b;
1709
- if (recursionCount > types_1.maxTypeRecursionCount) {
1710
- return false;
1711
- }
1712
- recursionCount++;
1713
- if ((0, types_1.isUnknown)(type)) {
1714
- return true;
1715
- }
1716
- // If this is a generic type alias, see if any of its type arguments
1717
- // are either unspecified or are partially known.
1718
- if ((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.typeArguments) {
1719
- if (type.typeAliasInfo.typeArguments.some((typeArg) => isPartlyUnknown(typeArg, allowUnknownTypeArgsForClasses, recursionCount))) {
1720
- return true;
1675
+ visitAny(type) {
1676
+ this.anyOrUnknownType = this.anyOrUnknownType ? preserveUnknown(this.anyOrUnknownType, type) : type;
1721
1677
  }
1722
- }
1723
- // See if a union contains an unknown type.
1724
- if ((0, types_1.isUnion)(type)) {
1725
- return ((0, types_1.findSubtype)(type, (subtype) => isPartlyUnknown(subtype, allowUnknownTypeArgsForClasses, recursionCount)) !==
1726
- undefined);
1727
- }
1728
- // See if an object or class has an unknown type argument.
1729
- if ((0, types_1.isClass)(type)) {
1730
- if (types_1.TypeBase.isInstance(type)) {
1731
- allowUnknownTypeArgsForClasses = false;
1732
- }
1733
- if (!allowUnknownTypeArgsForClasses && !types_1.ClassType.isPseudoGenericClass(type)) {
1734
- const typeArgs = ((_b = type.tupleTypeArguments) === null || _b === void 0 ? void 0 : _b.map((t) => t.type)) || type.typeArguments;
1735
- if (typeArgs) {
1736
- for (const argType of typeArgs) {
1737
- if (isPartlyUnknown(argType, allowUnknownTypeArgsForClasses, recursionCount)) {
1738
- return true;
1739
- }
1740
- }
1678
+ visitClass(type) {
1679
+ if (this._recurse) {
1680
+ super.visitClass(type);
1741
1681
  }
1742
1682
  }
1743
- return false;
1744
- }
1745
- // See if a function has an unknown type.
1746
- if ((0, types_1.isOverloadedFunction)(type)) {
1747
- return types_1.OverloadedFunctionType.getOverloads(type).some((overload) => {
1748
- return isPartlyUnknown(overload, /* allowUnknownTypeArgsForClasses */ false, recursionCount);
1749
- });
1750
- }
1751
- if ((0, types_1.isFunction)(type)) {
1752
- for (let i = 0; i < type.details.parameters.length; i++) {
1753
- // Ignore parameters such as "*" that have no name.
1754
- if (type.details.parameters[i].name) {
1755
- const paramType = types_1.FunctionType.getEffectiveParameterType(type, i);
1756
- if (isPartlyUnknown(paramType, /* allowUnknownTypeArgsForClasses */ false, recursionCount)) {
1757
- return true;
1758
- }
1683
+ visitFunction(type) {
1684
+ if (this._recurse) {
1685
+ super.visitFunction(type);
1759
1686
  }
1760
1687
  }
1761
- if (type.details.declaredReturnType &&
1762
- !types_1.FunctionType.isParamSpecValue(type) &&
1763
- isPartlyUnknown(type.details.declaredReturnType, /* allowUnknownTypeArgsForClasses */ false, recursionCount)) {
1764
- return true;
1688
+ }
1689
+ const walker = new AnyOrUnknownWalker(recurse);
1690
+ walker.walk(type);
1691
+ return walker.anyOrUnknownType;
1692
+ }
1693
+ exports.containsAnyOrUnknown = containsAnyOrUnknown;
1694
+ // Determines if any part of the type contains "Unknown", including any type arguments.
1695
+ function isPartlyUnknown(type, allowUnknownTypeArgsForClasses = false) {
1696
+ class PartlyUnknownWalker extends typeWalker_1.TypeWalker {
1697
+ constructor(_allowUnknownTypeArgsForClasses) {
1698
+ super();
1699
+ this._allowUnknownTypeArgsForClasses = _allowUnknownTypeArgsForClasses;
1700
+ this.isPartlyUnknown = false;
1701
+ }
1702
+ visitUnknown(type) {
1703
+ this.isPartlyUnknown = true;
1704
+ // No need to keep walking.
1705
+ this.cancelWalk();
1706
+ }
1707
+ visitClass(type) {
1708
+ if (!this._allowUnknownTypeArgsForClasses || !types_1.TypeBase.isInstantiable(type)) {
1709
+ super.visitClass(type);
1710
+ }
1765
1711
  }
1766
- return false;
1767
1712
  }
1768
- return false;
1713
+ const walker = new PartlyUnknownWalker(allowUnknownTypeArgsForClasses);
1714
+ walker.walk(type);
1715
+ return walker.isPartlyUnknown;
1769
1716
  }
1770
1717
  exports.isPartlyUnknown = isPartlyUnknown;
1771
1718
  // If the specified type is a generic class with a single type argument
@@ -1853,6 +1800,31 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
1853
1800
  return clonedClassType;
1854
1801
  }
1855
1802
  exports.specializeTupleClass = specializeTupleClass;
1803
+ // If the array contains two or more class types that are all the same
1804
+ // generic type, return the common "erased" type — a type that
1805
+ // replaces all of the type arguments with Unknown.
1806
+ function getCommonErasedType(types) {
1807
+ if (types.length < 2) {
1808
+ return undefined;
1809
+ }
1810
+ if (!(0, types_1.isClass)(types[0])) {
1811
+ return undefined;
1812
+ }
1813
+ for (let i = 1; i < types.length; i++) {
1814
+ const candidate = types[i];
1815
+ if (!(0, types_1.isClass)(candidate) ||
1816
+ types_1.TypeBase.isInstance(candidate) !== types_1.TypeBase.isInstance(types[0]) ||
1817
+ !types_1.ClassType.isSameGenericClass(types[0], candidate)) {
1818
+ return undefined;
1819
+ }
1820
+ }
1821
+ if (isTupleClass(types[0])) {
1822
+ return specializeTupleClass(types[0], [{ type: types_1.UnknownType.create(), isUnbounded: true }]);
1823
+ }
1824
+ return types_1.ClassType.cloneForSpecialization(types[0], types[0].details.typeParameters.map((t) => types_1.UnknownType.create()),
1825
+ /* isTypeArgumentExplicit */ true);
1826
+ }
1827
+ exports.getCommonErasedType = getCommonErasedType;
1856
1828
  // If the type is a function or overloaded function that has a paramSpec
1857
1829
  // associated with it and P.args and P.kwargs at the end of the signature,
1858
1830
  // it removes these parameters from the function.
@@ -1956,13 +1928,30 @@ function requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf =
1956
1928
  return false;
1957
1929
  }
1958
1930
  recursionCount++;
1931
+ // Is the answer cached?
1932
+ const canUseCache = !ignorePseudoGeneric && !ignoreSelf;
1933
+ if (canUseCache && ((_a = type.cached) === null || _a === void 0 ? void 0 : _a.requiresSpecialization) !== undefined) {
1934
+ return type.cached.requiresSpecialization;
1935
+ }
1936
+ const result = _requiresSpecialization(type, ignorePseudoGeneric, ignoreSelf, recursionCount);
1937
+ if (canUseCache) {
1938
+ if (type.cached === undefined) {
1939
+ type.cached = {};
1940
+ }
1941
+ type.cached.requiresSpecialization = result;
1942
+ }
1943
+ return result;
1944
+ }
1945
+ exports.requiresSpecialization = requiresSpecialization;
1946
+ function _requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf = false, recursionCount = 0) {
1947
+ var _a;
1959
1948
  switch (type.category) {
1960
1949
  case 7 /* Class */: {
1961
1950
  if (types_1.ClassType.isPseudoGenericClass(type) && ignorePseudoGeneric) {
1962
1951
  return false;
1963
1952
  }
1964
1953
  if (type.typeArguments) {
1965
- return (type.typeArguments.find((typeArg) => requiresSpecialization(typeArg, ignorePseudoGeneric, ignoreSelf, recursionCount)) !== undefined);
1954
+ return type.typeArguments.some((typeArg) => requiresSpecialization(typeArg, ignorePseudoGeneric, ignoreSelf, recursionCount));
1966
1955
  }
1967
1956
  return types_1.ClassType.getTypeParameters(type).length > 0;
1968
1957
  }
@@ -1991,10 +1980,10 @@ function requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf =
1991
1980
  return false;
1992
1981
  }
1993
1982
  case 6 /* OverloadedFunction */: {
1994
- return (type.overloads.find((overload) => requiresSpecialization(overload, ignorePseudoGeneric, ignoreSelf, recursionCount)) !== undefined);
1983
+ return type.overloads.some((overload) => requiresSpecialization(overload, ignorePseudoGeneric, ignoreSelf, recursionCount));
1995
1984
  }
1996
1985
  case 9 /* Union */: {
1997
- return ((0, types_1.findSubtype)(type, (subtype) => requiresSpecialization(subtype, ignorePseudoGeneric, ignoreSelf, recursionCount)) !== undefined);
1986
+ return type.subtypes.some((subtype) => requiresSpecialization(subtype, ignorePseudoGeneric, ignoreSelf, recursionCount));
1998
1987
  }
1999
1988
  case 10 /* TypeVar */: {
2000
1989
  // Most TypeVar types need to be specialized.
@@ -2013,7 +2002,6 @@ function requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf =
2013
2002
  }
2014
2003
  return false;
2015
2004
  }
2016
- exports.requiresSpecialization = requiresSpecialization;
2017
2005
  // Combines two variances to produce a resulting variance.
2018
2006
  function combineVariances(variance1, variance2) {
2019
2007
  if (variance1 === 1 /* Unknown */) {
@@ -2141,17 +2129,8 @@ function computeMroLinearization(classType) {
2141
2129
  // entries of the specified class. This is used once the class has been
2142
2130
  // added to the MRO.
2143
2131
  function filterClass(classToFilter, classLists) {
2144
- if ((classToFilter === null || classToFilter === void 0 ? void 0 : classToFilter.category) !== 7 /* Class */) {
2145
- // These "fail" calls are in place to diagnose a sporadic crash that
2146
- // we are seeing in the pylance telemetry. Delete these once we
2147
- // fix the underlying problem.
2148
- (0, debug_1.fail)(`Corrupted class type when computing MRO for ${classType.details.name}: ${JSON.stringify(classToFilter)}`);
2149
- }
2150
2132
  for (let i = 0; i < classLists.length; i++) {
2151
2133
  classLists[i] = classLists[i].filter((value) => {
2152
- if ((value === null || value === void 0 ? void 0 : value.category) === undefined) {
2153
- (0, debug_1.fail)(`Unexpected undefined type when computing MRO for ${classType.details.name}: ${JSON.stringify(classLists)}`);
2154
- }
2155
2134
  return !(0, types_1.isInstantiableClass)(value) || !types_1.ClassType.isSameGenericClass(value, classToFilter);
2156
2135
  });
2157
2136
  }
@@ -2480,14 +2459,14 @@ class TypeVarTransformer {
2480
2459
  : type;
2481
2460
  }
2482
2461
  transformTypeVarsInClassType(classType, recursionCount) {
2462
+ const typeParams = types_1.ClassType.getTypeParameters(classType);
2483
2463
  // Handle the common case where the class has no type parameters.
2484
- if (types_1.ClassType.getTypeParameters(classType).length === 0 && !types_1.ClassType.isSpecialBuiltIn(classType)) {
2464
+ if (typeParams.length === 0 && !types_1.ClassType.isSpecialBuiltIn(classType)) {
2485
2465
  return classType;
2486
2466
  }
2487
2467
  let newTypeArgs;
2488
2468
  let newTupleTypeArgs;
2489
2469
  let specializationNeeded = false;
2490
- const typeParams = types_1.ClassType.getTypeParameters(classType);
2491
2470
  const transformParamSpec = (paramSpec) => {
2492
2471
  const paramSpecValue = this.transformParamSpec(paramSpec, recursionCount);
2493
2472
  if (paramSpecValue) {
@@ -2795,10 +2774,14 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
2795
2774
  // Create new type variables with the same scope but with
2796
2775
  // different (unique) names.
2797
2776
  sourceType.details.typeParameters.forEach((typeParam) => {
2798
- const replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.details.name}(${existingSignature.count})`);
2777
+ let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.details.name}(${existingSignature.count})`);
2778
+ if (replacement.details.isParamSpec) {
2779
+ replacement = convertTypeToParamSpecValue(replacement);
2780
+ }
2799
2781
  typeVarContext.setTypeVarType(typeParam, replacement);
2800
- updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
2801
2782
  });
2783
+ updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
2784
+ (0, debug_1.assert)((0, types_1.isFunction)(updatedSourceType) || (0, types_1.isOverloadedFunction)(updatedSourceType));
2802
2785
  }
2803
2786
  this._signatureTracker.addSignature(sourceType);
2804
2787
  return updatedSourceType;
@@ -3014,19 +2997,20 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
3014
2997
  }
3015
2998
  }
3016
2999
  class ExpectedTypeTransformer extends TypeVarTransformer {
3017
- constructor(_liveTypeVarScopes) {
3000
+ constructor(_liveTypeVarScopes, _usageOffset) {
3018
3001
  super();
3019
3002
  this._liveTypeVarScopes = _liveTypeVarScopes;
3003
+ this._usageOffset = _usageOffset;
3020
3004
  }
3021
3005
  transformTypeVar(typeVar) {
3022
3006
  if (!this._isTypeVarLive(typeVar)) {
3023
- return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar);
3007
+ return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar, this._usageOffset);
3024
3008
  }
3025
3009
  return typeVar;
3026
3010
  }
3027
3011
  transformParamSpec(paramSpec) {
3028
3012
  if (!this._isTypeVarLive(paramSpec)) {
3029
- return convertTypeToParamSpecValue(types_1.TypeVarType.cloneAsInScopePlaceholder(paramSpec));
3013
+ return convertTypeToParamSpecValue(types_1.TypeVarType.cloneAsInScopePlaceholder(paramSpec, this._usageOffset));
3030
3014
  }
3031
3015
  return undefined;
3032
3016
  }
@@ -3042,7 +3026,7 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
3042
3026
  transformTypeVar(typeVar) {
3043
3027
  var _a;
3044
3028
  if (typeVar.isInScopePlaceholder) {
3045
- return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
3029
+ return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
3046
3030
  }
3047
3031
  return typeVar;
3048
3032
  }