@zzzen/pyright-internal 1.2.0-dev.20230528 → 1.2.0-dev.20230611
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.
- package/dist/analyzer/checker.js +42 -29
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -1
- package/dist/analyzer/constraintSolver.js +31 -16
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructors.js +35 -10
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +2 -0
- package/dist/analyzer/importResolver.js +57 -35
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +2 -0
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/patternMatching.js +2 -1
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.js +19 -12
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +182 -183
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +13 -0
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +3 -2
- package/dist/analyzer/sourceFile.js +204 -194
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +128 -70
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -0
- package/dist/analyzer/typeGuards.js +1 -1
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +13 -14
- package/dist/analyzer/typeUtils.js +126 -100
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +12 -1
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typeWalker.d.ts +22 -0
- package/dist/analyzer/typeWalker.js +164 -0
- package/dist/analyzer/typeWalker.js.map +1 -0
- package/dist/analyzer/types.d.ts +3 -2
- package/dist/analyzer/types.js +19 -12
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +5 -3
- package/dist/backgroundAnalysisBase.js +2 -2
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +12 -9
- package/dist/backgroundThreadBase.js +28 -20
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/charCodes.d.ts +147 -0
- package/dist/common/charCodes.js +164 -0
- package/dist/common/charCodes.js.map +1 -0
- package/dist/common/fileSystem.d.ts +1 -0
- package/dist/common/fileSystem.js.map +1 -1
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.js +3 -0
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/languageServerBase.d.ts +3 -3
- package/dist/languageServerBase.js +2 -2
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -0
- package/dist/languageService/definitionProvider.js +82 -74
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +16 -8
- package/dist/languageService/hoverProvider.js +53 -53
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/localization/localize.d.ts +10 -6
- package/dist/localization/localize.js +4 -3
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +4 -3
- package/dist/parser/characterStream.js.map +1 -1
- package/dist/parser/characters.js.map +1 -1
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.js +10 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +1 -0
- package/dist/pyrightFileSystem.js +3 -0
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -0
- package/dist/readonlyAugmentedFileSystem.js +3 -0
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/checker.test.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +1 -0
- package/dist/tests/harness/fourslash/testLanguageService.js +3 -0
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -2
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +12 -1
- package/dist/tests/harness/vfs/filesystem.js +33 -6
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/service.test.js +10 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +13 -2
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +5 -1
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +21 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +4 -0
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +2 -0
- package/dist/workspaceFactory.js +11 -2
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -2
@@ -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.
|
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.
|
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.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";
|
@@ -99,22 +100,30 @@ var AssignTypeFlags;
|
|
99
100
|
// employing narrowing or widening, and don't strip literals.
|
100
101
|
AssignTypeFlags[AssignTypeFlags["PopulatingExpectedType"] = 1024] = "PopulatingExpectedType";
|
101
102
|
})(AssignTypeFlags = exports.AssignTypeFlags || (exports.AssignTypeFlags = {}));
|
103
|
+
// Tracks whether a function signature has been seen before within
|
104
|
+
// an expression. For example, in the expression "foo(foo, foo)", the
|
105
|
+
// signature for "foo" will be seen three times at three different
|
106
|
+
// file offsets. If the signature is generic, we need to create unique
|
107
|
+
// type variables for each instance because they are independent of
|
108
|
+
// each other.
|
102
109
|
class UniqueSignatureTracker {
|
103
110
|
constructor() {
|
104
|
-
this.
|
111
|
+
this._signaturesSeen = [];
|
105
112
|
}
|
106
113
|
findSignature(signature) {
|
107
|
-
return this.
|
114
|
+
return this._signaturesSeen.find((s) => {
|
108
115
|
return (0, types_1.isTypeSame)(signature, s.type);
|
109
116
|
});
|
110
117
|
}
|
111
|
-
addSignature(signature) {
|
118
|
+
addSignature(signature, offset) {
|
112
119
|
const existingSignature = this.findSignature(signature);
|
113
120
|
if (existingSignature) {
|
114
|
-
existingSignature.
|
121
|
+
if (!existingSignature.expressionOffsets.some((o) => o === offset)) {
|
122
|
+
existingSignature.expressionOffsets.push(offset);
|
123
|
+
}
|
115
124
|
}
|
116
125
|
else {
|
117
|
-
this.
|
126
|
+
this._signaturesSeen.push({ type: signature, expressionOffsets: [offset] });
|
118
127
|
}
|
119
128
|
}
|
120
129
|
}
|
@@ -160,11 +169,11 @@ function isTypeVarSame(type1, type2) {
|
|
160
169
|
return isCompatible;
|
161
170
|
}
|
162
171
|
exports.isTypeVarSame = isTypeVarSame;
|
163
|
-
function makeInferenceContext(expectedType, isTypeIncomplete) {
|
172
|
+
function makeInferenceContext(expectedType, isTypeIncomplete, signatureTracker) {
|
164
173
|
if (!expectedType) {
|
165
174
|
return undefined;
|
166
175
|
}
|
167
|
-
return { expectedType, isTypeIncomplete };
|
176
|
+
return { expectedType, isTypeIncomplete, signatureTracker };
|
168
177
|
}
|
169
178
|
exports.makeInferenceContext = makeInferenceContext;
|
170
179
|
// Calls a callback for each subtype and combines the results
|
@@ -579,49 +588,28 @@ function isLiteralTypeOrUnion(type) {
|
|
579
588
|
return false;
|
580
589
|
}
|
581
590
|
exports.isLiteralTypeOrUnion = isLiteralTypeOrUnion;
|
582
|
-
function
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
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));
|
591
|
+
function containsLiteralType(type, includeTypeArgs = false) {
|
592
|
+
class ContainsLiteralTypeWalker extends typeWalker_1.TypeWalker {
|
593
|
+
constructor(_includeTypeArgs) {
|
594
|
+
super();
|
595
|
+
this._includeTypeArgs = _includeTypeArgs;
|
596
|
+
this.foundLiteral = false;
|
595
597
|
}
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
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;
|
598
|
+
visitClass(classType) {
|
599
|
+
if ((0, types_1.isClassInstance)(classType)) {
|
600
|
+
if (isLiteralType(classType) || types_1.ClassType.isBuiltIn(classType, 'LiteralString')) {
|
601
|
+
this.foundLiteral = true;
|
602
|
+
this.cancelWalk();
|
603
|
+
}
|
604
|
+
}
|
605
|
+
if (this._includeTypeArgs) {
|
606
|
+
super.visitClass(classType);
|
612
607
|
}
|
613
608
|
}
|
614
609
|
}
|
615
|
-
|
616
|
-
|
617
|
-
|
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);
|
610
|
+
const walker = new ContainsLiteralTypeWalker(includeTypeArgs);
|
611
|
+
walker.walk(type);
|
612
|
+
return walker.foundLiteral;
|
625
613
|
}
|
626
614
|
exports.containsLiteralType = containsLiteralType;
|
627
615
|
// If all of the subtypes are literals with the same built-in class (e.g.
|
@@ -746,8 +734,8 @@ function populateTypeVarContextForSelfType(typeVarContext, contextClassType, sel
|
|
746
734
|
exports.populateTypeVarContextForSelfType = populateTypeVarContextForSelfType;
|
747
735
|
// Looks for duplicate function types within the type and ensures that
|
748
736
|
// if they are generic, they have unique type variables.
|
749
|
-
function ensureFunctionSignaturesAreUnique(type, signatureTracker) {
|
750
|
-
const transformer = new UniqueFunctionSignatureTransformer(signatureTracker);
|
737
|
+
function ensureFunctionSignaturesAreUnique(type, signatureTracker, expressionOffset) {
|
738
|
+
const transformer = new UniqueFunctionSignatureTransformer(signatureTracker, expressionOffset);
|
751
739
|
return transformer.apply(type, 0);
|
752
740
|
}
|
753
741
|
exports.ensureFunctionSignaturesAreUnique = ensureFunctionSignaturesAreUnique;
|
@@ -841,8 +829,8 @@ exports.validateTypeVarDefault = validateTypeVarDefault;
|
|
841
829
|
// expected type uses TypeVars that are not part of the context of the
|
842
830
|
// class we are constructing. We'll replace these type variables with dummy
|
843
831
|
// type variables.
|
844
|
-
function transformExpectedType(expectedType, liveTypeVarScopes) {
|
845
|
-
const transformer = new ExpectedTypeTransformer(liveTypeVarScopes);
|
832
|
+
function transformExpectedType(expectedType, liveTypeVarScopes, usageOffset) {
|
833
|
+
const transformer = new ExpectedTypeTransformer(liveTypeVarScopes, usageOffset);
|
846
834
|
return transformer.apply(expectedType, 0);
|
847
835
|
}
|
848
836
|
exports.transformExpectedType = transformExpectedType;
|
@@ -1679,31 +1667,42 @@ function getMembersForModule(moduleType, symbolTable) {
|
|
1679
1667
|
});
|
1680
1668
|
}
|
1681
1669
|
exports.getMembersForModule = getMembersForModule;
|
1682
|
-
// Determines if the type
|
1683
|
-
//
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1670
|
+
// Determines if the type contains an Any or Unknown type. If so,
|
1671
|
+
// it returns the Any or Unknown type. Unknowns are preferred over
|
1672
|
+
// Any if both are present. If recurse is true, it will recurse
|
1673
|
+
// through type arguments and parameters.
|
1674
|
+
function containsAnyOrUnknown(type, recurse) {
|
1675
|
+
class AnyOrUnknownWalker extends typeWalker_1.TypeWalker {
|
1676
|
+
constructor(_recurse) {
|
1677
|
+
super();
|
1678
|
+
this._recurse = _recurse;
|
1689
1679
|
}
|
1690
|
-
|
1691
|
-
|
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;
|
1680
|
+
visitUnknown(type) {
|
1681
|
+
this.anyOrUnknownType = this.anyOrUnknownType ? preserveUnknown(this.anyOrUnknownType, type) : type;
|
1701
1682
|
}
|
1702
|
-
|
1703
|
-
|
1683
|
+
visitAny(type) {
|
1684
|
+
this.anyOrUnknownType = this.anyOrUnknownType ? preserveUnknown(this.anyOrUnknownType, type) : type;
|
1685
|
+
}
|
1686
|
+
visitClass(type) {
|
1687
|
+
if (this._recurse) {
|
1688
|
+
super.visitClass(type);
|
1689
|
+
}
|
1690
|
+
}
|
1691
|
+
visitFunction(type) {
|
1692
|
+
if (this._recurse) {
|
1693
|
+
super.visitFunction(type);
|
1694
|
+
}
|
1695
|
+
}
|
1696
|
+
}
|
1697
|
+
const walker = new AnyOrUnknownWalker(recurse);
|
1698
|
+
walker.walk(type);
|
1699
|
+
return walker.anyOrUnknownType;
|
1704
1700
|
}
|
1705
|
-
exports.
|
1701
|
+
exports.containsAnyOrUnknown = containsAnyOrUnknown;
|
1706
1702
|
// Determines if any part of the type contains "Unknown", including any type arguments.
|
1703
|
+
// This function does not use the TypeWalker because it is called very frequently,
|
1704
|
+
// and allocating a memory walker object for every call significantly increases
|
1705
|
+
// peak memory usage.
|
1707
1706
|
function isPartlyUnknown(type, allowUnknownTypeArgsForClasses = false, recursionCount = 0) {
|
1708
1707
|
var _a, _b;
|
1709
1708
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
@@ -1956,13 +1955,30 @@ function requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf =
|
|
1956
1955
|
return false;
|
1957
1956
|
}
|
1958
1957
|
recursionCount++;
|
1958
|
+
// Is the answer cached?
|
1959
|
+
const canUseCache = !ignorePseudoGeneric && !ignoreSelf;
|
1960
|
+
if (canUseCache && ((_a = type.cached) === null || _a === void 0 ? void 0 : _a.requiresSpecialization) !== undefined) {
|
1961
|
+
return type.cached.requiresSpecialization;
|
1962
|
+
}
|
1963
|
+
const result = _requiresSpecialization(type, ignorePseudoGeneric, ignoreSelf, recursionCount);
|
1964
|
+
if (canUseCache) {
|
1965
|
+
if (type.cached === undefined) {
|
1966
|
+
type.cached = {};
|
1967
|
+
}
|
1968
|
+
type.cached.requiresSpecialization = result;
|
1969
|
+
}
|
1970
|
+
return result;
|
1971
|
+
}
|
1972
|
+
exports.requiresSpecialization = requiresSpecialization;
|
1973
|
+
function _requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf = false, recursionCount = 0) {
|
1974
|
+
var _a;
|
1959
1975
|
switch (type.category) {
|
1960
1976
|
case 7 /* Class */: {
|
1961
1977
|
if (types_1.ClassType.isPseudoGenericClass(type) && ignorePseudoGeneric) {
|
1962
1978
|
return false;
|
1963
1979
|
}
|
1964
1980
|
if (type.typeArguments) {
|
1965
|
-
return
|
1981
|
+
return type.typeArguments.some((typeArg) => requiresSpecialization(typeArg, ignorePseudoGeneric, ignoreSelf, recursionCount));
|
1966
1982
|
}
|
1967
1983
|
return types_1.ClassType.getTypeParameters(type).length > 0;
|
1968
1984
|
}
|
@@ -1991,10 +2007,10 @@ function requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf =
|
|
1991
2007
|
return false;
|
1992
2008
|
}
|
1993
2009
|
case 6 /* OverloadedFunction */: {
|
1994
|
-
return
|
2010
|
+
return type.overloads.some((overload) => requiresSpecialization(overload, ignorePseudoGeneric, ignoreSelf, recursionCount));
|
1995
2011
|
}
|
1996
2012
|
case 9 /* Union */: {
|
1997
|
-
return
|
2013
|
+
return type.subtypes.some((subtype) => requiresSpecialization(subtype, ignorePseudoGeneric, ignoreSelf, recursionCount));
|
1998
2014
|
}
|
1999
2015
|
case 10 /* TypeVar */: {
|
2000
2016
|
// Most TypeVar types need to be specialized.
|
@@ -2013,7 +2029,6 @@ function requiresSpecialization(type, ignorePseudoGeneric = false, ignoreSelf =
|
|
2013
2029
|
}
|
2014
2030
|
return false;
|
2015
2031
|
}
|
2016
|
-
exports.requiresSpecialization = requiresSpecialization;
|
2017
2032
|
// Combines two variances to produce a resulting variance.
|
2018
2033
|
function combineVariances(variance1, variance2) {
|
2019
2034
|
if (variance1 === 1 /* Unknown */) {
|
@@ -2141,17 +2156,8 @@ function computeMroLinearization(classType) {
|
|
2141
2156
|
// entries of the specified class. This is used once the class has been
|
2142
2157
|
// added to the MRO.
|
2143
2158
|
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
2159
|
for (let i = 0; i < classLists.length; i++) {
|
2151
2160
|
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
2161
|
return !(0, types_1.isInstantiableClass)(value) || !types_1.ClassType.isSameGenericClass(value, classToFilter);
|
2156
2162
|
});
|
2157
2163
|
}
|
@@ -2480,14 +2486,14 @@ class TypeVarTransformer {
|
|
2480
2486
|
: type;
|
2481
2487
|
}
|
2482
2488
|
transformTypeVarsInClassType(classType, recursionCount) {
|
2489
|
+
const typeParams = types_1.ClassType.getTypeParameters(classType);
|
2483
2490
|
// Handle the common case where the class has no type parameters.
|
2484
|
-
if (
|
2491
|
+
if (typeParams.length === 0 && !types_1.ClassType.isSpecialBuiltIn(classType)) {
|
2485
2492
|
return classType;
|
2486
2493
|
}
|
2487
2494
|
let newTypeArgs;
|
2488
2495
|
let newTupleTypeArgs;
|
2489
2496
|
let specializationNeeded = false;
|
2490
|
-
const typeParams = types_1.ClassType.getTypeParameters(classType);
|
2491
2497
|
const transformParamSpec = (paramSpec) => {
|
2492
2498
|
const paramSpecValue = this.transformParamSpec(paramSpec, recursionCount);
|
2493
2499
|
if (paramSpecValue) {
|
@@ -2779,9 +2785,18 @@ class TypeVarDefaultValidator extends TypeVarTransformer {
|
|
2779
2785
|
}
|
2780
2786
|
}
|
2781
2787
|
class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
2782
|
-
constructor(_signatureTracker) {
|
2788
|
+
constructor(_signatureTracker, _expressionOffset) {
|
2783
2789
|
super();
|
2784
2790
|
this._signatureTracker = _signatureTracker;
|
2791
|
+
this._expressionOffset = _expressionOffset;
|
2792
|
+
}
|
2793
|
+
transformGenericTypeAlias(type, recursionCount) {
|
2794
|
+
// Don't transform type aliases.
|
2795
|
+
return type;
|
2796
|
+
}
|
2797
|
+
transformTypeVarsInClassType(classType, recursionCount) {
|
2798
|
+
// Don't transform classes.
|
2799
|
+
return classType;
|
2785
2800
|
}
|
2786
2801
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
2787
2802
|
// If this function is not generic, there's no need to check for uniqueness.
|
@@ -2792,15 +2807,25 @@ class UniqueFunctionSignatureTransformer extends TypeVarTransformer {
|
|
2792
2807
|
const existingSignature = this._signatureTracker.findSignature(sourceType);
|
2793
2808
|
if (existingSignature) {
|
2794
2809
|
const typeVarContext = new typeVarContext_1.TypeVarContext(getTypeVarScopeId(sourceType));
|
2795
|
-
|
2796
|
-
|
2797
|
-
|
2798
|
-
|
2799
|
-
|
2810
|
+
let offsetIndex = existingSignature.expressionOffsets.findIndex((offset) => offset === this._expressionOffset);
|
2811
|
+
if (offsetIndex < 0) {
|
2812
|
+
offsetIndex = existingSignature.expressionOffsets.length;
|
2813
|
+
}
|
2814
|
+
if (offsetIndex > 0) {
|
2815
|
+
// Create new type variables with the same scope but with
|
2816
|
+
// different (unique) names.
|
2817
|
+
sourceType.details.typeParameters.forEach((typeParam) => {
|
2818
|
+
let replacement = types_1.TypeVarType.cloneForNewName(typeParam, `${typeParam.details.name}(${offsetIndex})`);
|
2819
|
+
if (replacement.details.isParamSpec) {
|
2820
|
+
replacement = convertTypeToParamSpecValue(replacement);
|
2821
|
+
}
|
2822
|
+
typeVarContext.setTypeVarType(typeParam, replacement);
|
2823
|
+
});
|
2800
2824
|
updatedSourceType = applySolvedTypeVars(sourceType, typeVarContext);
|
2801
|
-
|
2825
|
+
(0, debug_1.assert)((0, types_1.isFunction)(updatedSourceType) || (0, types_1.isOverloadedFunction)(updatedSourceType));
|
2826
|
+
}
|
2802
2827
|
}
|
2803
|
-
this._signatureTracker.addSignature(sourceType);
|
2828
|
+
this._signatureTracker.addSignature(sourceType, this._expressionOffset);
|
2804
2829
|
return updatedSourceType;
|
2805
2830
|
}
|
2806
2831
|
}
|
@@ -3014,19 +3039,20 @@ class ApplySolvedTypeVarsTransformer extends TypeVarTransformer {
|
|
3014
3039
|
}
|
3015
3040
|
}
|
3016
3041
|
class ExpectedTypeTransformer extends TypeVarTransformer {
|
3017
|
-
constructor(_liveTypeVarScopes) {
|
3042
|
+
constructor(_liveTypeVarScopes, _usageOffset) {
|
3018
3043
|
super();
|
3019
3044
|
this._liveTypeVarScopes = _liveTypeVarScopes;
|
3045
|
+
this._usageOffset = _usageOffset;
|
3020
3046
|
}
|
3021
3047
|
transformTypeVar(typeVar) {
|
3022
3048
|
if (!this._isTypeVarLive(typeVar)) {
|
3023
|
-
return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar);
|
3049
|
+
return types_1.TypeVarType.cloneAsInScopePlaceholder(typeVar, this._usageOffset);
|
3024
3050
|
}
|
3025
3051
|
return typeVar;
|
3026
3052
|
}
|
3027
3053
|
transformParamSpec(paramSpec) {
|
3028
3054
|
if (!this._isTypeVarLive(paramSpec)) {
|
3029
|
-
return convertTypeToParamSpecValue(types_1.TypeVarType.cloneAsInScopePlaceholder(paramSpec));
|
3055
|
+
return convertTypeToParamSpecValue(types_1.TypeVarType.cloneAsInScopePlaceholder(paramSpec, this._usageOffset));
|
3030
3056
|
}
|
3031
3057
|
return undefined;
|
3032
3058
|
}
|
@@ -3042,7 +3068,7 @@ class InScopePlaceholderTransformer extends TypeVarTransformer {
|
|
3042
3068
|
transformTypeVar(typeVar) {
|
3043
3069
|
var _a;
|
3044
3070
|
if (typeVar.isInScopePlaceholder) {
|
3045
|
-
return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a :
|
3071
|
+
return (_a = this._signatureContext.getTypeVarType(typeVar)) !== null && _a !== void 0 ? _a : typeVar;
|
3046
3072
|
}
|
3047
3073
|
return typeVar;
|
3048
3074
|
}
|