@zzzen/pyright-internal 1.2.0-dev.20240602 → 1.2.0-dev.20240616
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/binder.d.ts +3 -1
- package/dist/analyzer/binder.js +23 -11
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.js +50 -33
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +27 -38
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +1 -1
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +2 -7
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.d.ts +0 -1
- package/dist/analyzer/dataClasses.js +52 -78
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.d.ts +2 -1
- package/dist/analyzer/decorators.js +34 -39
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/docStringUtils.d.ts +0 -1
- package/dist/analyzer/docStringUtils.js +1 -6
- package/dist/analyzer/docStringUtils.js.map +1 -1
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +20 -17
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +11 -9
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +3 -3
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.js +6 -7
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +1 -13
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -1
- package/dist/analyzer/patternMatching.js +4 -4
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/properties.js +4 -4
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +16 -5
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.js +27 -48
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +2 -1
- package/dist/analyzer/sourceFile.js +7 -5
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.d.ts +1 -0
- package/dist/analyzer/typeDocStringUtils.js +8 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +746 -667
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +2 -3
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +25 -16
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +3 -5
- package/dist/analyzer/typeUtils.js +96 -144
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +4 -0
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +6 -6
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +51 -54
- package/dist/analyzer/types.js +221 -260
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +1 -1
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/commands/dumpFileDebugInfoCommand.js +17 -25
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/cancellationUtils.d.ts +1 -0
- package/dist/common/cancellationUtils.js +15 -1
- package/dist/common/cancellationUtils.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +13 -4
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/docStringService.d.ts +15 -0
- package/dist/common/docStringService.js +38 -0
- package/dist/common/docStringService.js.map +1 -0
- package/dist/common/envVarUtils.js +3 -1
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/common/extensibility.d.ts +1 -7
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/languageServerInterface.d.ts +1 -2
- package/dist/common/languageServerInterface.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +3 -3
- package/dist/common/realFileSystem.js +6 -6
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceKeys.d.ts +2 -0
- package/dist/common/serviceKeys.js +1 -0
- package/dist/common/serviceKeys.js.map +1 -1
- package/dist/common/serviceProvider.js +3 -0
- package/dist/common/serviceProvider.js.map +1 -1
- package/dist/common/serviceProviderExtensions.d.ts +2 -0
- package/dist/common/serviceProviderExtensions.js +8 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -1
- package/dist/common/stringUtils.d.ts +1 -0
- package/dist/common/stringUtils.js +5 -1
- package/dist/common/stringUtils.js.map +1 -1
- package/dist/common/uri/uriUtils.d.ts +1 -1
- package/dist/common/uri/uriUtils.js +1 -1
- package/dist/common/uri/uriUtils.js.map +1 -1
- package/dist/languageServerBase.d.ts +1 -1
- package/dist/languageServerBase.js +3 -3
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +1 -0
- package/dist/languageService/completionProvider.js +16 -7
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/completionProviderUtils.d.ts +2 -1
- package/dist/languageService/completionProviderUtils.js +6 -4
- package/dist/languageService/completionProviderUtils.js.map +1 -1
- package/dist/languageService/definitionProvider.d.ts +2 -1
- package/dist/languageService/definitionProvider.js.map +1 -1
- package/dist/languageService/hoverProvider.d.ts +2 -1
- package/dist/languageService/hoverProvider.js +7 -5
- package/dist/languageService/hoverProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.d.ts +3 -1
- package/dist/languageService/signatureHelpProvider.js +8 -6
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/localization/localize.d.ts +6 -0
- package/dist/localization/localize.js +3 -0
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +4 -3
- package/dist/localization/package.nls.de.json +4 -3
- package/dist/localization/package.nls.en-us.json +3 -0
- package/dist/localization/package.nls.es.json +3 -2
- package/dist/localization/package.nls.fr.json +4 -3
- package/dist/localization/package.nls.it.json +4 -3
- package/dist/localization/package.nls.ja.json +4 -3
- package/dist/localization/package.nls.ko.json +5 -4
- package/dist/localization/package.nls.pl.json +4 -3
- package/dist/localization/package.nls.pt-br.json +4 -3
- package/dist/localization/package.nls.qps-ploc.json +4 -3
- package/dist/localization/package.nls.ru.json +4 -3
- package/dist/localization/package.nls.tr.json +4 -3
- package/dist/localization/package.nls.zh-cn.json +4 -3
- package/dist/localization/package.nls.zh-tw.json +4 -3
- package/dist/pyright.js +3 -0
- package/dist/pyright.js.map +1 -1
- package/dist/tests/checker.test.js +8 -0
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +3 -3
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/diagnosticOverrides.test.js +7 -6
- package/dist/tests/diagnosticOverrides.test.js.map +1 -1
- package/dist/tests/docStringConversion.test.d.ts +2 -1
- package/dist/tests/docStringConversion.test.js +300 -293
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js +2 -2
- package/dist/tests/fourslash/rename.externallyHidden.fourslash.js.map +1 -1
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js +1 -1
- package/dist/tests/fourslash/rename.externallyHidden.params.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +2 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/pathUtils.test.js +6 -0
- package/dist/tests/pathUtils.test.js.map +1 -1
- package/dist/tests/signatureHelp.test.js +2 -1
- package/dist/tests/signatureHelp.test.js.map +1 -1
- package/dist/tests/testState.test.js +1 -1
- package/dist/tests/testState.test.js.map +1 -1
- package/dist/tests/testUtils.js +1 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +4 -0
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +8 -0
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -3
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator7.test.js +15 -9
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +2 -2
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/tests/uri.test.js +6 -0
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/workspaceFactory.d.ts +1 -1
- package/package.json +1 -1
- package/dist/tests/docStringUtils.test.d.ts +0 -1
- package/dist/tests/docStringUtils.test.js +0 -74
- package/dist/tests/docStringUtils.test.js.map +0 -1
@@ -8,9 +8,9 @@
|
|
8
8
|
* Functions that operate on Type objects.
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
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.
|
12
|
-
exports.
|
13
|
-
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType =
|
11
|
+
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.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.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
|
12
|
+
exports.computeMroLinearization = 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 = void 0;
|
13
|
+
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = 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");
|
@@ -239,22 +239,6 @@ function isTypeVarSame(type1, type2) {
|
|
239
239
|
return isCompatible;
|
240
240
|
}
|
241
241
|
exports.isTypeVarSame = isTypeVarSame;
|
242
|
-
// The `deprecated` type has been defined as a function, an overloaded function,
|
243
|
-
// and a class in various versions of typeshed. This function checks for all of
|
244
|
-
// these variants to determine whether the type is the built-in `deprecated` type.
|
245
|
-
function isBuiltInDeprecatedType(type) {
|
246
|
-
if ((0, types_1.isFunction)(type)) {
|
247
|
-
return type.details.builtInName === 'deprecated';
|
248
|
-
}
|
249
|
-
if ((0, types_1.isOverloadedFunction)(type)) {
|
250
|
-
return type.overloads.length > 0 && type.overloads[0].details.builtInName === 'deprecated';
|
251
|
-
}
|
252
|
-
if ((0, types_1.isInstantiableClass)(type)) {
|
253
|
-
return types_1.ClassType.isBuiltIn(type, 'deprecated');
|
254
|
-
}
|
255
|
-
return false;
|
256
|
-
}
|
257
|
-
exports.isBuiltInDeprecatedType = isBuiltInDeprecatedType;
|
258
242
|
function makeInferenceContext(expectedType, isTypeIncomplete) {
|
259
243
|
if (!expectedType) {
|
260
244
|
return undefined;
|
@@ -431,7 +415,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
431
415
|
return typeComparison;
|
432
416
|
}
|
433
417
|
}
|
434
|
-
const returnTypeComparison = compareTypes((_a = types_1.FunctionType.
|
418
|
+
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
419
|
if (returnTypeComparison !== 0) {
|
436
420
|
return returnTypeComparison;
|
437
421
|
}
|
@@ -631,12 +615,12 @@ function derivesFromAnyOrUnknown(type) {
|
|
631
615
|
anyOrUnknown = true;
|
632
616
|
}
|
633
617
|
else if ((0, types_1.isInstantiableClass)(subtype)) {
|
634
|
-
if (types_1.ClassType.
|
618
|
+
if (types_1.ClassType.derivesFromAnyOrUnknown(subtype)) {
|
635
619
|
anyOrUnknown = true;
|
636
620
|
}
|
637
621
|
}
|
638
622
|
else if ((0, types_1.isClassInstance)(subtype)) {
|
639
|
-
if (types_1.ClassType.
|
623
|
+
if (types_1.ClassType.derivesFromAnyOrUnknown(subtype)) {
|
640
624
|
anyOrUnknown = true;
|
641
625
|
}
|
642
626
|
}
|
@@ -788,6 +772,9 @@ function getTypeVarScopeIds(type) {
|
|
788
772
|
if (type.details.higherOrderTypeVarScopeIds) {
|
789
773
|
scopeIds.push(...type.details.higherOrderTypeVarScopeIds);
|
790
774
|
}
|
775
|
+
if (type.boundTypeVarScopeId) {
|
776
|
+
scopeIds.push(type.boundTypeVarScopeId);
|
777
|
+
}
|
791
778
|
}
|
792
779
|
return scopeIds;
|
793
780
|
}
|
@@ -829,14 +816,14 @@ function getUnknownTypeForTypeVar(typeVar) {
|
|
829
816
|
exports.getUnknownTypeForTypeVar = getUnknownTypeForTypeVar;
|
830
817
|
// Returns the "Unknown" equivalent for a ParamSpec.
|
831
818
|
function getUnknownTypeForParamSpec() {
|
832
|
-
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.
|
819
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
833
820
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
834
821
|
return newFunction;
|
835
822
|
}
|
836
823
|
exports.getUnknownTypeForParamSpec = getUnknownTypeForParamSpec;
|
837
824
|
// Returns the equivalent of "Callable[..., Unknown]".
|
838
825
|
function getUnknownTypeForCallable() {
|
839
|
-
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.
|
826
|
+
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
840
827
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
841
828
|
newFunction.details.declaredReturnType = types_1.UnknownType.create();
|
842
829
|
return newFunction;
|
@@ -845,8 +832,11 @@ exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
|
|
845
832
|
// If the class is generic and not already specialized, this function
|
846
833
|
// "self specializes" the class, filling in its own type parameters
|
847
834
|
// as type arguments.
|
848
|
-
function selfSpecializeClass(type) {
|
849
|
-
if (type.details.typeParameters.length === 0
|
835
|
+
function selfSpecializeClass(type, overrideTypeArgs = false) {
|
836
|
+
if (type.details.typeParameters.length === 0) {
|
837
|
+
return type;
|
838
|
+
}
|
839
|
+
if (type.typeArguments && !overrideTypeArgs) {
|
850
840
|
return type;
|
851
841
|
}
|
852
842
|
return types_1.ClassType.cloneForSpecialization(type, type.details.typeParameters, /* isTypeArgumentExplicit */ true);
|
@@ -1216,13 +1206,13 @@ exports.transformExpectedType = transformExpectedType;
|
|
1216
1206
|
// appears in a parent and a child, the child overrides the parent.
|
1217
1207
|
function getProtocolSymbols(classType) {
|
1218
1208
|
const symbolMap = new Map();
|
1219
|
-
if ((classType.details.flags &
|
1220
|
-
getProtocolSymbolsRecursive(classType, symbolMap,
|
1209
|
+
if ((classType.details.flags & 512 /* ClassTypeFlags.ProtocolClass */) !== 0) {
|
1210
|
+
getProtocolSymbolsRecursive(classType, symbolMap, 512 /* ClassTypeFlags.ProtocolClass */);
|
1221
1211
|
}
|
1222
1212
|
return symbolMap;
|
1223
1213
|
}
|
1224
1214
|
exports.getProtocolSymbols = getProtocolSymbols;
|
1225
|
-
function getProtocolSymbolsRecursive(classType, symbolMap, classFlags =
|
1215
|
+
function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 512 /* ClassTypeFlags.ProtocolClass */, recursionCount = 0) {
|
1226
1216
|
if (recursionCount > types_1.maxTypeRecursionCount) {
|
1227
1217
|
return;
|
1228
1218
|
}
|
@@ -1236,6 +1226,7 @@ function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 16384 /*
|
|
1236
1226
|
symbolMap.set(name, {
|
1237
1227
|
symbol,
|
1238
1228
|
classType,
|
1229
|
+
unspecializedClassType: classType,
|
1239
1230
|
isInstanceMember: symbol.isInstanceMember(),
|
1240
1231
|
isClassMember: symbol.isClassMember(),
|
1241
1232
|
isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, /* isDataclass */ false),
|
@@ -1343,6 +1334,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1343
1334
|
for (const [mroClass, specializedMroClass] of classItr) {
|
1344
1335
|
if (!(0, types_1.isInstantiableClass)(mroClass)) {
|
1345
1336
|
if (!declaredTypesOnly) {
|
1337
|
+
const classType = (0, types_1.isAnyOrUnknown)(mroClass) ? mroClass : types_1.UnknownType.create();
|
1346
1338
|
// The class derives from an unknown type, so all bets are off
|
1347
1339
|
// when trying to find a member. Return an unknown symbol.
|
1348
1340
|
const cm = {
|
@@ -1350,7 +1342,8 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1350
1342
|
isInstanceMember: false,
|
1351
1343
|
isClassMember: true,
|
1352
1344
|
isClassVar: false,
|
1353
|
-
classType
|
1345
|
+
classType,
|
1346
|
+
unspecializedClassType: classType,
|
1354
1347
|
isTypeDeclared: false,
|
1355
1348
|
skippedUndeclaredType: false,
|
1356
1349
|
};
|
@@ -1374,6 +1367,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1374
1367
|
isClassMember: symbol.isClassMember(),
|
1375
1368
|
isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, types_1.ClassType.isDataClass(specializedMroClass)),
|
1376
1369
|
classType: specializedMroClass,
|
1370
|
+
unspecializedClassType: mroClass,
|
1377
1371
|
isTypeDeclared: hasDeclaredType,
|
1378
1372
|
skippedUndeclaredType,
|
1379
1373
|
};
|
@@ -1412,6 +1406,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1412
1406
|
isClassMember,
|
1413
1407
|
isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, isDataclass),
|
1414
1408
|
classType: specializedMroClass,
|
1409
|
+
unspecializedClassType: mroClass,
|
1415
1410
|
isTypeDeclared: hasDeclaredType,
|
1416
1411
|
skippedUndeclaredType,
|
1417
1412
|
};
|
@@ -1433,6 +1428,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1433
1428
|
isClassMember: true,
|
1434
1429
|
isClassVar: false,
|
1435
1430
|
classType,
|
1431
|
+
unspecializedClassType: classType,
|
1436
1432
|
isTypeDeclared: false,
|
1437
1433
|
skippedUndeclaredType: false,
|
1438
1434
|
};
|
@@ -1496,6 +1492,7 @@ function getClassFieldsRecursive(classType) {
|
|
1496
1492
|
if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
|
1497
1493
|
memberMap.set(name, {
|
1498
1494
|
classType: specializedMroClass,
|
1495
|
+
unspecializedClassType: mroClass,
|
1499
1496
|
symbol,
|
1500
1497
|
isInstanceMember: symbol.isInstanceMember(),
|
1501
1498
|
isClassMember: symbol.isClassMember(),
|
@@ -1553,7 +1550,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1553
1550
|
}
|
1554
1551
|
// Don't return any P.args or P.kwargs types.
|
1555
1552
|
if ((0, types_1.isParamSpec)(type) && type.paramSpecAccess) {
|
1556
|
-
return [];
|
1553
|
+
return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
|
1557
1554
|
}
|
1558
1555
|
return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
|
1559
1556
|
}
|
@@ -1579,10 +1576,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1579
1576
|
for (let i = 0; i < type.details.parameters.length; i++) {
|
1580
1577
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), recursionCount));
|
1581
1578
|
}
|
1582
|
-
|
1583
|
-
addTypeVarsToListIfUnique(combinedList, [type.details.paramSpec]);
|
1584
|
-
}
|
1585
|
-
const returnType = types_1.FunctionType.getSpecializedReturnType(type);
|
1579
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(type);
|
1586
1580
|
if (returnType) {
|
1587
1581
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
|
1588
1582
|
}
|
@@ -1647,12 +1641,6 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1647
1641
|
setTypeArgumentsRecursive(destType.details.declaredReturnType, srcType, typeVarContext, recursionCount);
|
1648
1642
|
}
|
1649
1643
|
}
|
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
1644
|
break;
|
1657
1645
|
case 5 /* TypeCategory.OverloadedFunction */:
|
1658
1646
|
destType.overloads.forEach((subtype) => {
|
@@ -1674,7 +1662,7 @@ exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
|
|
1674
1662
|
function buildTypeVarContextFromSpecializedClass(classType) {
|
1675
1663
|
const typeParameters = types_1.ClassType.getTypeParameters(classType);
|
1676
1664
|
const typeVarContext = buildTypeVarContext(typeParameters, classType.typeArguments, getTypeVarScopeId(classType));
|
1677
|
-
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments
|
1665
|
+
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments) {
|
1678
1666
|
typeVarContext.setTupleTypeVar(typeParameters[0], classType.tupleTypeArguments);
|
1679
1667
|
}
|
1680
1668
|
return typeVarContext;
|
@@ -1780,7 +1768,7 @@ exports.synthesizeTypeVarForSelfCls = synthesizeTypeVarForSelfCls;
|
|
1780
1768
|
// Returns the declared "return" type (the type returned from a return statement)
|
1781
1769
|
// if it was declared, or undefined otherwise.
|
1782
1770
|
function getDeclaredGeneratorReturnType(functionType) {
|
1783
|
-
const returnType = types_1.FunctionType.
|
1771
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(functionType);
|
1784
1772
|
if (returnType) {
|
1785
1773
|
const generatorTypeArgs = getGeneratorTypeArgs(returnType);
|
1786
1774
|
if (generatorTypeArgs) {
|
@@ -2056,7 +2044,7 @@ function containsAnyOrUnknown(type, recurse) {
|
|
2056
2044
|
visitFunction(type) {
|
2057
2045
|
if (this._recurse) {
|
2058
2046
|
// A function with a "..." type is effectively an "Any".
|
2059
|
-
if (types_1.FunctionType.
|
2047
|
+
if (types_1.FunctionType.isGradualCallableForm(type)) {
|
2060
2048
|
this.anyOrUnknownType = this.anyOrUnknownType
|
2061
2049
|
? preserveUnknown(this.anyOrUnknownType, types_1.AnyType.create())
|
2062
2050
|
: types_1.AnyType.create();
|
@@ -2221,42 +2209,6 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
|
|
2221
2209
|
return clonedClassType;
|
2222
2210
|
}
|
2223
2211
|
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
2212
|
function _expandVariadicUnpackedUnion(type) {
|
2261
2213
|
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.tupleTypeArguments && type.isUnpacked) {
|
2262
2214
|
return (0, types_1.combineTypes)(type.tupleTypeArguments.map((t) => t.type));
|
@@ -2359,9 +2311,6 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2359
2311
|
return types_1.ClassType.getTypeParameters(type).length > 0;
|
2360
2312
|
}
|
2361
2313
|
case 4 /* TypeCategory.Function */: {
|
2362
|
-
if (type.details.paramSpec) {
|
2363
|
-
return true;
|
2364
|
-
}
|
2365
2314
|
for (let i = 0; i < type.details.parameters.length; i++) {
|
2366
2315
|
if (requiresSpecialization(types_1.FunctionType.getEffectiveParameterType(type, i), options, recursionCount)) {
|
2367
2316
|
return true;
|
@@ -2519,7 +2468,9 @@ function computeMroLinearization(classType) {
|
|
2519
2468
|
}));
|
2520
2469
|
// The first class in the MRO is the class itself.
|
2521
2470
|
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
|
2522
|
-
|
2471
|
+
const specializedClassType = applySolvedTypeVars(classType, typeVarContext);
|
2472
|
+
(0, debug_1.assert)((0, types_1.isClass)(specializedClassType) || (0, types_1.isAny)(specializedClassType) || (0, types_1.isUnknown)(specializedClassType));
|
2473
|
+
classType.details.mro.push(specializedClassType);
|
2523
2474
|
// Helper function that returns true if the specified searchClass
|
2524
2475
|
// is found in the "tail" (i.e. in elements 1 through n) of any
|
2525
2476
|
// of the class lists.
|
@@ -2549,6 +2500,7 @@ function computeMroLinearization(classType) {
|
|
2549
2500
|
}
|
2550
2501
|
if (!(0, types_1.isInstantiableClass)(classList[0])) {
|
2551
2502
|
foundValidHead = true;
|
2503
|
+
(0, debug_1.assert)((0, types_1.isClass)(classList[0]) || (0, types_1.isAnyOrUnknown)(classList[0]));
|
2552
2504
|
classType.details.mro.push(classList[0]);
|
2553
2505
|
classList.shift();
|
2554
2506
|
break;
|
@@ -2573,6 +2525,7 @@ function computeMroLinearization(classType) {
|
|
2573
2525
|
// Handle the situation by pull the head off the first empty list.
|
2574
2526
|
// This allows us to make forward progress.
|
2575
2527
|
if (!(0, types_1.isInstantiableClass)(nonEmptyList[0])) {
|
2528
|
+
(0, debug_1.assert)((0, types_1.isClass)(nonEmptyList[0]) || (0, types_1.isAnyOrUnknown)(nonEmptyList[0]));
|
2576
2529
|
classType.details.mro.push(nonEmptyList[0]);
|
2577
2530
|
nonEmptyList.shift();
|
2578
2531
|
}
|
@@ -2631,10 +2584,13 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2631
2584
|
}
|
2632
2585
|
}
|
2633
2586
|
}
|
2587
|
+
// Converts a function into a FunctionType that represents the function's
|
2588
|
+
// input signature and converts a ParamSpec into a FunctionType with the input
|
2589
|
+
// signature (*args: P.args, **kwargs: P.kwargs).
|
2634
2590
|
function convertTypeToParamSpecValue(type) {
|
2635
2591
|
if ((0, types_1.isParamSpec)(type)) {
|
2636
2592
|
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
2637
|
-
|
2593
|
+
types_1.FunctionType.addParamSpecVariadics(newFunction, type);
|
2638
2594
|
newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
|
2639
2595
|
return newFunction;
|
2640
2596
|
}
|
@@ -2655,45 +2611,51 @@ function convertTypeToParamSpecValue(type) {
|
|
2655
2611
|
newFunction.details.higherOrderTypeVarScopeIds = [...type.details.higherOrderTypeVarScopeIds];
|
2656
2612
|
newFunction.details.typeVarScopeId = newFunction.details.higherOrderTypeVarScopeIds.pop();
|
2657
2613
|
}
|
2658
|
-
newFunction.details.paramSpec = type.details.paramSpec;
|
2659
2614
|
return newFunction;
|
2660
2615
|
}
|
2661
2616
|
return getUnknownTypeForParamSpec();
|
2662
2617
|
}
|
2663
2618
|
exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
2664
|
-
|
2665
|
-
|
2666
|
-
|
2619
|
+
// Converts a FunctionType into a ParamSpec if it consists only of
|
2620
|
+
// (* args: P.args, ** kwargs: P.kwargs). Otherwise returns the original type.
|
2621
|
+
function convertParamSpecValueToType(type) {
|
2622
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
2623
|
+
const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
|
2624
|
+
let hasParameters = withoutParamSpec.details.parameters.length > 0;
|
2625
|
+
if (withoutParamSpec.details.parameters.length === 1) {
|
2667
2626
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2668
2627
|
// treat it as though there are no parameters.
|
2669
|
-
const onlyParam =
|
2628
|
+
const onlyParam = withoutParamSpec.details.parameters[0];
|
2670
2629
|
if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
|
2671
2630
|
hasParameters = false;
|
2672
2631
|
}
|
2673
2632
|
}
|
2674
|
-
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2681
|
-
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
2685
|
-
|
2686
|
-
|
2687
|
-
|
2633
|
+
// Can we simplify it to just a paramSpec?
|
2634
|
+
if (!hasParameters && paramSpec) {
|
2635
|
+
return paramSpec;
|
2636
|
+
}
|
2637
|
+
// Create a function type from the param spec entries.
|
2638
|
+
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.details.flags);
|
2639
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.details.typeVarScopeId);
|
2640
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.details.higherOrderTypeVarScopeIds);
|
2641
|
+
withoutParamSpec.details.parameters.forEach((entry) => {
|
2642
|
+
types_1.FunctionType.addParameter(functionType, {
|
2643
|
+
category: entry.category,
|
2644
|
+
name: entry.name,
|
2645
|
+
hasDefault: entry.hasDefault,
|
2646
|
+
defaultValueExpression: entry.defaultValueExpression,
|
2647
|
+
isNameSynthesized: entry.isNameSynthesized,
|
2648
|
+
hasDeclaredType: true,
|
2649
|
+
type: entry.type,
|
2688
2650
|
});
|
2689
|
-
|
2690
|
-
|
2691
|
-
|
2692
|
-
functionType.details.docString = paramSpecValue.details.docString;
|
2693
|
-
functionType.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
|
2694
|
-
return functionType;
|
2651
|
+
});
|
2652
|
+
if (paramSpec) {
|
2653
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
2695
2654
|
}
|
2696
|
-
|
2655
|
+
functionType.details.docString = withoutParamSpec.details.docString;
|
2656
|
+
functionType.details.deprecatedMessage = withoutParamSpec.details.deprecatedMessage;
|
2657
|
+
functionType.details.methodClass = withoutParamSpec.details.methodClass;
|
2658
|
+
return functionType;
|
2697
2659
|
}
|
2698
2660
|
exports.convertParamSpecValueToType = convertParamSpecValueToType;
|
2699
2661
|
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
@@ -2929,11 +2891,19 @@ class TypeVarTransformer {
|
|
2929
2891
|
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
|
2930
2892
|
}
|
2931
2893
|
else {
|
2932
|
-
|
2933
|
-
|
2934
|
-
|
2935
|
-
|
2936
|
-
|
2894
|
+
// Handle the special case where tuple[T, ...] is being specialized
|
2895
|
+
// to tuple[Never, ...]. This is equivalent to tuple[()].
|
2896
|
+
const isEmptyTuple = oldTypeArgType.isUnbounded &&
|
2897
|
+
(0, types_1.isTypeVar)(oldTypeArgType.type) &&
|
2898
|
+
(0, types_1.isNever)(newTypeArgType) &&
|
2899
|
+
classType.tupleTypeArguments.length === 1;
|
2900
|
+
if (!isEmptyTuple) {
|
2901
|
+
newTupleTypeArgs.push({
|
2902
|
+
type: newTypeArgType,
|
2903
|
+
isUnbounded: oldTypeArgType.isUnbounded,
|
2904
|
+
isOptional: oldTypeArgType.isOptional,
|
2905
|
+
});
|
2906
|
+
}
|
2937
2907
|
}
|
2938
2908
|
});
|
2939
2909
|
}
|
@@ -3020,14 +2990,7 @@ class TypeVarTransformer {
|
|
3020
2990
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3021
2991
|
return this.doForEachSignatureContext(() => {
|
3022
2992
|
let functionType = sourceType;
|
3023
|
-
|
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);
|
2993
|
+
const declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionType);
|
3031
2994
|
const specializedReturnType = declaredReturnType
|
3032
2995
|
? this.apply(declaredReturnType, recursionCount)
|
3033
2996
|
: undefined;
|
@@ -3036,26 +2999,15 @@ class TypeVarTransformer {
|
|
3036
2999
|
parameterTypes: [],
|
3037
3000
|
returnType: specializedReturnType,
|
3038
3001
|
};
|
3039
|
-
|
3040
|
-
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3045
|
-
|
3046
|
-
|
3047
|
-
|
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
|
-
}
|
3002
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
3003
|
+
if (paramSpec) {
|
3004
|
+
const paramSpecType = this.transformParamSpec(paramSpec, recursionCount);
|
3005
|
+
if (paramSpecType) {
|
3006
|
+
const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecType);
|
3007
|
+
if (paramSpecType.details.parameters.length > 0 ||
|
3008
|
+
!transformedParamSpec ||
|
3009
|
+
!(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
|
3010
|
+
functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecType);
|
3059
3011
|
}
|
3060
3012
|
}
|
3061
3013
|
}
|