@zzzen/pyright-internal 1.2.0-dev.20240526 → 1.2.0-dev.20240609
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerNodeInfo.d.ts +2 -2
- package/dist/analyzer/binder.d.ts +3 -3
- package/dist/analyzer/binder.js +46 -40
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +3 -3
- package/dist/analyzer/checker.js +82 -65
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +4 -4
- package/dist/analyzer/codeFlowTypes.js +3 -3
- package/dist/analyzer/constraintSolver.js +26 -34
- 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 +12 -8
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +1 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +3 -3
- package/dist/analyzer/enums.d.ts +1 -1
- package/dist/analyzer/enums.js +25 -22
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +1 -0
- package/dist/analyzer/importResolver.js +6 -3
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importStatementUtils.js +6 -6
- package/dist/analyzer/namedTuples.js +2 -2
- package/dist/analyzer/operations.js +8 -9
- 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/parseTreeUtils.js +94 -94
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.d.ts +5 -5
- package/dist/analyzer/parseTreeWalker.js +64 -64
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +5 -5
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +1 -1
- package/dist/analyzer/program.js +23 -29
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/properties.js +2 -2
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/protocols.js +2 -2
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/scope.d.ts +1 -1
- package/dist/analyzer/scope.js +2 -2
- package/dist/analyzer/scope.js.map +1 -1
- package/dist/analyzer/sourceFile.js +3 -3
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +4 -4
- package/dist/analyzer/staticExpressions.js +3 -3
- package/dist/analyzer/testWalker.js +1 -1
- package/dist/analyzer/tracePrinter.js +4 -4
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeEvaluator.js +568 -519
- 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 +9 -8
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +21 -14
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +1 -1
- package/dist/analyzer/typeUtils.d.ts +4 -5
- package/dist/analyzer/typeUtils.js +100 -128
- 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.d.ts +1 -2
- package/dist/analyzer/typedDicts.js +5 -17
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +11 -12
- package/dist/analyzer/types.js +137 -169
- 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.d.ts +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +15 -15
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +2 -1
- package/dist/common/configOptions.js +12 -3
- package/dist/common/configOptions.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/textEditTracker.js +5 -5
- package/dist/common/uri/fileUri.js +1 -0
- package/dist/common/uri/fileUri.js.map +1 -1
- package/dist/common/uri/uri.d.ts +3 -0
- package/dist/common/uri/uri.js +16 -0
- package/dist/common/uri/uri.js.map +1 -1
- package/dist/languageServerBase.js +1 -1
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/autoImporter.js +4 -4
- package/dist/languageService/callHierarchyProvider.js +1 -1
- package/dist/languageService/completionProvider.js +30 -30
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +7 -7
- package/dist/languageService/hoverProvider.js +2 -2
- package/dist/languageService/importSorter.js +1 -1
- package/dist/languageService/referencesProvider.js +4 -4
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.js +3 -3
- package/dist/languageService/tooltipUtils.js +2 -2
- package/dist/languageService/workspaceSymbolProvider.js +1 -1
- package/dist/localization/localize.d.ts +7 -1
- package/dist/localization/localize.js +4 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +5 -3
- package/dist/localization/package.nls.de.json +5 -3
- package/dist/localization/package.nls.en-us.json +4 -1
- package/dist/localization/package.nls.es.json +5 -3
- package/dist/localization/package.nls.fr.json +5 -3
- package/dist/localization/package.nls.it.json +5 -3
- package/dist/localization/package.nls.ja.json +5 -3
- package/dist/localization/package.nls.ko.json +6 -4
- package/dist/localization/package.nls.pl.json +5 -3
- package/dist/localization/package.nls.pt-br.json +5 -3
- package/dist/localization/package.nls.qps-ploc.json +5 -3
- package/dist/localization/package.nls.ru.json +5 -3
- package/dist/localization/package.nls.tr.json +5 -3
- package/dist/localization/package.nls.zh-cn.json +5 -3
- package/dist/localization/package.nls.zh-tw.json +5 -3
- package/dist/parser/parseNodes.d.ts +42 -42
- package/dist/parser/parseNodes.js +69 -69
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -1
- package/dist/parser/parser.js +35 -35
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyright.js +6 -3
- package/dist/pyright.js.map +1 -1
- package/dist/tests/classDeclaration.test.js +1 -1
- package/dist/tests/config.test.js +2 -2
- 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/importResolver.test.js +16 -0
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/parseTreeUtils.test.js +4 -4
- package/dist/tests/parser.test.js +3 -3
- 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 +9 -1
- 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 -15
- 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 +11 -3
- package/dist/tests/uri.test.js.map +1 -1
- package/dist/workspaceFactory.js +16 -14
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -9,8 +9,8 @@
|
|
9
9
|
*/
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
11
11
|
exports.isTupleClass = exports.isMaybeDescriptorInstance = exports.isDescriptorInstance = exports.isCallableType = exports.isProperty = exports.isEllipsisType = exports.getUnionSubtypeCount = exports.getLiteralTypeClassName = exports.containsLiteralType = exports.isLiteralTypeOrUnion = exports.isLiteralType = exports.getSpecializedTupleType = exports.selfSpecializeClass = exports.getUnknownTypeForCallable = exports.getUnknownTypeForParamSpec = exports.getUnknownTypeForTypeVar = exports.specializeWithUnknownTypeArgs = exports.specializeWithDefaultTypeArgs = exports.getTypeVarScopeIds = exports.getTypeVarScopeId = exports.transformPossibleRecursiveTypeAlias = exports.isTypeAliasRecursive = exports.isTypeAliasPlaceholder = exports.getTypeCondition = exports.addConditionToType = exports.getFullNameOfType = exports.derivesFromAnyOrUnknown = exports.isUnionableType = exports.preserveUnknown = exports.areTypesSame = exports.doForEachSignature = exports.allSubtypes = exports.someSubtypes = exports.doForEachSubtype = exports.sortTypes = exports.cleanIncompleteUnknown = exports.mapSignatures = exports.mapSubtypes = exports.makeInferenceContext = exports.isBuiltInDeprecatedType = exports.isTypeVarSame = exports.isIncompleteUnknown = exports.removeNoneFromUnion = exports.isNoneTypeClass = exports.isNoneInstance = exports.isOptionalType = exports.UniqueSignatureTracker = exports.AssignTypeFlags = exports.ClassIteratorFlags = exports.MemberAccessFlags = void 0;
|
12
|
-
exports.
|
13
|
-
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization =
|
12
|
+
exports.isVarianceOfTypeArgumentCompatible = exports.combineVariances = exports.requiresSpecialization = exports.requiresTypeArguments = exports.getGeneratorTypeArgs = exports.specializeTupleClass = exports.combineSameSizedTuples = exports.explodeGenericClass = exports.isPartlyUnknown = exports.containsAnyOrUnknown = exports.containsAnyRecursive = exports.getMembersForModule = exports.getMembersForClass = exports.convertToInstantiable = exports.convertToInstance = exports.isEffectivelyInstantiable = exports.isMetaclassInstance = exports.isInstantiableMetaclass = exports.getGeneratorYieldType = exports.getDeclaredGeneratorReturnType = exports.synthesizeTypeVarForSelfCls = exports.derivesFromClassRecursive = exports.derivesFromStdlibClass = exports.specializeForBaseClass = exports.buildTypeVarContext = exports.buildTypeVarContextFromSpecializedClass = exports.setTypeArgumentsRecursive = exports.specializeClassType = exports.getTypeVarArgumentsRecursive = exports.addTypeVarsToListIfUnique = exports.getClassFieldsRecursive = exports.getClassIterator = exports.getClassMemberIterator = exports.lookUpClassMember = exports.lookUpObjectMember = exports.getContainerDepth = exports.getProtocolSymbolsRecursive = exports.getProtocolSymbols = exports.transformExpectedType = exports.replaceTypeVarsWithAny = exports.validateTypeVarDefault = exports.applyInScopePlaceholders = exports.applySourceContextTypeVarsToSignature = exports.applySourceContextTypeVars = exports.applySolvedTypeVars = exports.ensureFunctionSignaturesAreUnique = exports.populateTypeVarContextForSelfType = exports.partiallySpecializeType = exports.isTupleIndexUnambiguous = exports.isUnboundedTupleClass = void 0;
|
13
|
+
exports.convertParamSpecValueToType = exports.convertTypeToParamSpecValue = exports.getDeclaringModulesForType = exports.computeMroLinearization = void 0;
|
14
14
|
const collectionUtils_1 = require("../common/collectionUtils");
|
15
15
|
const debug_1 = require("../common/debug");
|
16
16
|
const symbol_1 = require("./symbol");
|
@@ -431,7 +431,7 @@ function compareTypes(a, b, recursionCount = 0) {
|
|
431
431
|
return typeComparison;
|
432
432
|
}
|
433
433
|
}
|
434
|
-
const returnTypeComparison = compareTypes((_a = types_1.FunctionType.
|
434
|
+
const returnTypeComparison = compareTypes((_a = types_1.FunctionType.getEffectiveReturnType(a)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create(), (_b = types_1.FunctionType.getEffectiveReturnType(bFunc)) !== null && _b !== void 0 ? _b : types_1.UnknownType.create());
|
435
435
|
if (returnTypeComparison !== 0) {
|
436
436
|
return returnTypeComparison;
|
437
437
|
}
|
@@ -631,12 +631,12 @@ function derivesFromAnyOrUnknown(type) {
|
|
631
631
|
anyOrUnknown = true;
|
632
632
|
}
|
633
633
|
else if ((0, types_1.isInstantiableClass)(subtype)) {
|
634
|
-
if (types_1.ClassType.
|
634
|
+
if (types_1.ClassType.derivesFromAnyOrUnknown(subtype)) {
|
635
635
|
anyOrUnknown = true;
|
636
636
|
}
|
637
637
|
}
|
638
638
|
else if ((0, types_1.isClassInstance)(subtype)) {
|
639
|
-
if (types_1.ClassType.
|
639
|
+
if (types_1.ClassType.derivesFromAnyOrUnknown(subtype)) {
|
640
640
|
anyOrUnknown = true;
|
641
641
|
}
|
642
642
|
}
|
@@ -829,14 +829,14 @@ function getUnknownTypeForTypeVar(typeVar) {
|
|
829
829
|
exports.getUnknownTypeForTypeVar = getUnknownTypeForTypeVar;
|
830
830
|
// Returns the "Unknown" equivalent for a ParamSpec.
|
831
831
|
function getUnknownTypeForParamSpec() {
|
832
|
-
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.
|
832
|
+
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
833
833
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
834
834
|
return newFunction;
|
835
835
|
}
|
836
836
|
exports.getUnknownTypeForParamSpec = getUnknownTypeForParamSpec;
|
837
837
|
// Returns the equivalent of "Callable[..., Unknown]".
|
838
838
|
function getUnknownTypeForCallable() {
|
839
|
-
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.
|
839
|
+
const newFunction = types_1.FunctionType.createSynthesizedInstance('', 32768 /* FunctionTypeFlags.GradualCallableForm */);
|
840
840
|
types_1.FunctionType.addDefaultParameters(newFunction);
|
841
841
|
newFunction.details.declaredReturnType = types_1.UnknownType.create();
|
842
842
|
return newFunction;
|
@@ -845,8 +845,11 @@ exports.getUnknownTypeForCallable = getUnknownTypeForCallable;
|
|
845
845
|
// If the class is generic and not already specialized, this function
|
846
846
|
// "self specializes" the class, filling in its own type parameters
|
847
847
|
// as type arguments.
|
848
|
-
function selfSpecializeClass(type) {
|
849
|
-
if (type.details.typeParameters.length === 0
|
848
|
+
function selfSpecializeClass(type, overrideTypeArgs = false) {
|
849
|
+
if (type.details.typeParameters.length === 0) {
|
850
|
+
return type;
|
851
|
+
}
|
852
|
+
if (type.typeArguments && !overrideTypeArgs) {
|
850
853
|
return type;
|
851
854
|
}
|
852
855
|
return types_1.ClassType.cloneForSpecialization(type, type.details.typeParameters, /* isTypeArgumentExplicit */ true);
|
@@ -1236,6 +1239,7 @@ function getProtocolSymbolsRecursive(classType, symbolMap, classFlags = 16384 /*
|
|
1236
1239
|
symbolMap.set(name, {
|
1237
1240
|
symbol,
|
1238
1241
|
classType,
|
1242
|
+
unspecializedClassType: classType,
|
1239
1243
|
isInstanceMember: symbol.isInstanceMember(),
|
1240
1244
|
isClassMember: symbol.isClassMember(),
|
1241
1245
|
isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, /* isDataclass */ false),
|
@@ -1343,6 +1347,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1343
1347
|
for (const [mroClass, specializedMroClass] of classItr) {
|
1344
1348
|
if (!(0, types_1.isInstantiableClass)(mroClass)) {
|
1345
1349
|
if (!declaredTypesOnly) {
|
1350
|
+
const classType = (0, types_1.isAnyOrUnknown)(mroClass) ? mroClass : types_1.UnknownType.create();
|
1346
1351
|
// The class derives from an unknown type, so all bets are off
|
1347
1352
|
// when trying to find a member. Return an unknown symbol.
|
1348
1353
|
const cm = {
|
@@ -1350,7 +1355,8 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1350
1355
|
isInstanceMember: false,
|
1351
1356
|
isClassMember: true,
|
1352
1357
|
isClassVar: false,
|
1353
|
-
classType
|
1358
|
+
classType,
|
1359
|
+
unspecializedClassType: classType,
|
1354
1360
|
isTypeDeclared: false,
|
1355
1361
|
skippedUndeclaredType: false,
|
1356
1362
|
};
|
@@ -1374,6 +1380,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1374
1380
|
isClassMember: symbol.isClassMember(),
|
1375
1381
|
isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, types_1.ClassType.isDataClass(specializedMroClass)),
|
1376
1382
|
classType: specializedMroClass,
|
1383
|
+
unspecializedClassType: mroClass,
|
1377
1384
|
isTypeDeclared: hasDeclaredType,
|
1378
1385
|
skippedUndeclaredType,
|
1379
1386
|
};
|
@@ -1412,6 +1419,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1412
1419
|
isClassMember,
|
1413
1420
|
isClassVar: (0, symbolUtils_1.isEffectivelyClassVar)(symbol, isDataclass),
|
1414
1421
|
classType: specializedMroClass,
|
1422
|
+
unspecializedClassType: mroClass,
|
1415
1423
|
isTypeDeclared: hasDeclaredType,
|
1416
1424
|
skippedUndeclaredType,
|
1417
1425
|
};
|
@@ -1433,6 +1441,7 @@ function* getClassMemberIterator(classType, memberName, flags = 0 /* MemberAcces
|
|
1433
1441
|
isClassMember: true,
|
1434
1442
|
isClassVar: false,
|
1435
1443
|
classType,
|
1444
|
+
unspecializedClassType: classType,
|
1436
1445
|
isTypeDeclared: false,
|
1437
1446
|
skippedUndeclaredType: false,
|
1438
1447
|
};
|
@@ -1496,6 +1505,7 @@ function getClassFieldsRecursive(classType) {
|
|
1496
1505
|
if (!symbol.isIgnoredForProtocolMatch() && symbol.hasTypedDeclarations()) {
|
1497
1506
|
memberMap.set(name, {
|
1498
1507
|
classType: specializedMroClass,
|
1508
|
+
unspecializedClassType: mroClass,
|
1499
1509
|
symbol,
|
1500
1510
|
isInstanceMember: symbol.isInstanceMember(),
|
1501
1511
|
isClassMember: symbol.isClassMember(),
|
@@ -1553,7 +1563,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1553
1563
|
}
|
1554
1564
|
// Don't return any P.args or P.kwargs types.
|
1555
1565
|
if ((0, types_1.isParamSpec)(type) && type.paramSpecAccess) {
|
1556
|
-
return [];
|
1566
|
+
return [types_1.TypeVarType.cloneForParamSpecAccess(type, /* access */ undefined)];
|
1557
1567
|
}
|
1558
1568
|
return [types_1.TypeBase.isInstantiable(type) ? types_1.TypeVarType.cloneAsInstance(type) : type];
|
1559
1569
|
}
|
@@ -1579,10 +1589,7 @@ function getTypeVarArgumentsRecursive(type, recursionCount = 0) {
|
|
1579
1589
|
for (let i = 0; i < type.details.parameters.length; i++) {
|
1580
1590
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(types_1.FunctionType.getEffectiveParameterType(type, i), recursionCount));
|
1581
1591
|
}
|
1582
|
-
|
1583
|
-
addTypeVarsToListIfUnique(combinedList, [type.details.paramSpec]);
|
1584
|
-
}
|
1585
|
-
const returnType = types_1.FunctionType.getSpecializedReturnType(type);
|
1592
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(type);
|
1586
1593
|
if (returnType) {
|
1587
1594
|
addTypeVarsToListIfUnique(combinedList, getTypeVarArgumentsRecursive(returnType, recursionCount));
|
1588
1595
|
}
|
@@ -1647,12 +1654,6 @@ function setTypeArgumentsRecursive(destType, srcType, typeVarContext, recursionC
|
|
1647
1654
|
setTypeArgumentsRecursive(destType.details.declaredReturnType, srcType, typeVarContext, recursionCount);
|
1648
1655
|
}
|
1649
1656
|
}
|
1650
|
-
if (destType.details.paramSpec) {
|
1651
|
-
// Fill in an empty signature for a ParamSpec.
|
1652
|
-
if (!typeVarContext.getPrimarySignature().getTypeVar(destType.details.paramSpec)) {
|
1653
|
-
typeVarContext.setTypeVarType(destType.details.paramSpec, getUnknownTypeForParamSpec());
|
1654
|
-
}
|
1655
|
-
}
|
1656
1657
|
break;
|
1657
1658
|
case 5 /* TypeCategory.OverloadedFunction */:
|
1658
1659
|
destType.overloads.forEach((subtype) => {
|
@@ -1674,7 +1675,7 @@ exports.setTypeArgumentsRecursive = setTypeArgumentsRecursive;
|
|
1674
1675
|
function buildTypeVarContextFromSpecializedClass(classType) {
|
1675
1676
|
const typeParameters = types_1.ClassType.getTypeParameters(classType);
|
1676
1677
|
const typeVarContext = buildTypeVarContext(typeParameters, classType.typeArguments, getTypeVarScopeId(classType));
|
1677
|
-
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments
|
1678
|
+
if (types_1.ClassType.isTupleClass(classType) && classType.tupleTypeArguments) {
|
1678
1679
|
typeVarContext.setTupleTypeVar(typeParameters[0], classType.tupleTypeArguments);
|
1679
1680
|
}
|
1680
1681
|
return typeVarContext;
|
@@ -1780,7 +1781,7 @@ exports.synthesizeTypeVarForSelfCls = synthesizeTypeVarForSelfCls;
|
|
1780
1781
|
// Returns the declared "return" type (the type returned from a return statement)
|
1781
1782
|
// if it was declared, or undefined otherwise.
|
1782
1783
|
function getDeclaredGeneratorReturnType(functionType) {
|
1783
|
-
const returnType = types_1.FunctionType.
|
1784
|
+
const returnType = types_1.FunctionType.getEffectiveReturnType(functionType);
|
1784
1785
|
if (returnType) {
|
1785
1786
|
const generatorTypeArgs = getGeneratorTypeArgs(returnType);
|
1786
1787
|
if (generatorTypeArgs) {
|
@@ -2009,18 +2010,25 @@ function getMembersForModule(moduleType, symbolTable) {
|
|
2009
2010
|
}
|
2010
2011
|
exports.getMembersForModule = getMembersForModule;
|
2011
2012
|
// Determines if the type contains an Any recursively.
|
2012
|
-
function containsAnyRecursive(type) {
|
2013
|
+
function containsAnyRecursive(type, includeUnknown = true) {
|
2013
2014
|
class AnyWalker extends typeWalker_1.TypeWalker {
|
2014
|
-
constructor() {
|
2015
|
-
super(
|
2015
|
+
constructor(_includeUnknown) {
|
2016
|
+
super();
|
2017
|
+
this._includeUnknown = _includeUnknown;
|
2016
2018
|
this.foundAny = false;
|
2017
2019
|
}
|
2018
2020
|
visitAny(type) {
|
2019
2021
|
this.foundAny = true;
|
2020
2022
|
this.cancelWalk();
|
2021
2023
|
}
|
2024
|
+
visitUnknown(type) {
|
2025
|
+
if (this._includeUnknown) {
|
2026
|
+
this.foundAny = true;
|
2027
|
+
this.cancelWalk();
|
2028
|
+
}
|
2029
|
+
}
|
2022
2030
|
}
|
2023
|
-
const walker = new AnyWalker();
|
2031
|
+
const walker = new AnyWalker(includeUnknown);
|
2024
2032
|
walker.walk(type);
|
2025
2033
|
return walker.foundAny;
|
2026
2034
|
}
|
@@ -2049,7 +2057,7 @@ function containsAnyOrUnknown(type, recurse) {
|
|
2049
2057
|
visitFunction(type) {
|
2050
2058
|
if (this._recurse) {
|
2051
2059
|
// A function with a "..." type is effectively an "Any".
|
2052
|
-
if (types_1.FunctionType.
|
2060
|
+
if (types_1.FunctionType.isGradualCallableForm(type)) {
|
2053
2061
|
this.anyOrUnknownType = this.anyOrUnknownType
|
2054
2062
|
? preserveUnknown(this.anyOrUnknownType, types_1.AnyType.create())
|
2055
2063
|
: types_1.AnyType.create();
|
@@ -2214,42 +2222,6 @@ function specializeTupleClass(classType, typeArgs, isTypeArgumentExplicit = true
|
|
2214
2222
|
return clonedClassType;
|
2215
2223
|
}
|
2216
2224
|
exports.specializeTupleClass = specializeTupleClass;
|
2217
|
-
// If the type is a function or overloaded function that has a paramSpec
|
2218
|
-
// associated with it and P.args and P.kwargs at the end of the signature,
|
2219
|
-
// it removes these parameters from the function.
|
2220
|
-
function removeParamSpecVariadicsFromSignature(type) {
|
2221
|
-
if ((0, types_1.isFunction)(type)) {
|
2222
|
-
return removeParamSpecVariadicsFromFunction(type);
|
2223
|
-
}
|
2224
|
-
const newOverloads = [];
|
2225
|
-
let newTypeNeeded = false;
|
2226
|
-
for (const overload of type.overloads) {
|
2227
|
-
const newOverload = removeParamSpecVariadicsFromFunction(overload);
|
2228
|
-
newOverloads.push(newOverload);
|
2229
|
-
if (newOverload !== overload) {
|
2230
|
-
newTypeNeeded = true;
|
2231
|
-
}
|
2232
|
-
}
|
2233
|
-
return newTypeNeeded ? types_1.OverloadedFunctionType.create(newOverloads) : type;
|
2234
|
-
}
|
2235
|
-
exports.removeParamSpecVariadicsFromSignature = removeParamSpecVariadicsFromSignature;
|
2236
|
-
function removeParamSpecVariadicsFromFunction(type) {
|
2237
|
-
const paramCount = type.details.parameters.length;
|
2238
|
-
if (paramCount < 2) {
|
2239
|
-
return type;
|
2240
|
-
}
|
2241
|
-
const argsParam = type.details.parameters[paramCount - 2];
|
2242
|
-
const kwargsParam = type.details.parameters[paramCount - 1];
|
2243
|
-
if (argsParam.category !== 1 /* ParameterCategory.ArgsList */ ||
|
2244
|
-
kwargsParam.category !== 2 /* ParameterCategory.KwargsDict */ ||
|
2245
|
-
!(0, types_1.isParamSpec)(argsParam.type) ||
|
2246
|
-
!(0, types_1.isParamSpec)(kwargsParam.type) ||
|
2247
|
-
!(0, types_1.isTypeSame)(argsParam.type, kwargsParam.type)) {
|
2248
|
-
return type;
|
2249
|
-
}
|
2250
|
-
return types_1.FunctionType.cloneRemoveParamSpecVariadics(type, types_1.TypeVarType.cloneForParamSpecAccess(argsParam.type, /* access */ undefined));
|
2251
|
-
}
|
2252
|
-
exports.removeParamSpecVariadicsFromFunction = removeParamSpecVariadicsFromFunction;
|
2253
2225
|
function _expandVariadicUnpackedUnion(type) {
|
2254
2226
|
if ((0, types_1.isClassInstance)(type) && isTupleClass(type) && type.tupleTypeArguments && type.isUnpacked) {
|
2255
2227
|
return (0, types_1.combineTypes)(type.tupleTypeArguments.map((t) => t.type));
|
@@ -2352,9 +2324,6 @@ function _requiresSpecialization(type, options, recursionCount = 0) {
|
|
2352
2324
|
return types_1.ClassType.getTypeParameters(type).length > 0;
|
2353
2325
|
}
|
2354
2326
|
case 4 /* TypeCategory.Function */: {
|
2355
|
-
if (type.details.paramSpec) {
|
2356
|
-
return true;
|
2357
|
-
}
|
2358
2327
|
for (let i = 0; i < type.details.parameters.length; i++) {
|
2359
2328
|
if (requiresSpecialization(types_1.FunctionType.getEffectiveParameterType(type, i), options, recursionCount)) {
|
2360
2329
|
return true;
|
@@ -2512,7 +2481,9 @@ function computeMroLinearization(classType) {
|
|
2512
2481
|
}));
|
2513
2482
|
// The first class in the MRO is the class itself.
|
2514
2483
|
const typeVarContext = buildTypeVarContextFromSpecializedClass(classType);
|
2515
|
-
|
2484
|
+
const specializedClassType = applySolvedTypeVars(classType, typeVarContext);
|
2485
|
+
(0, debug_1.assert)((0, types_1.isClass)(specializedClassType) || (0, types_1.isAny)(specializedClassType) || (0, types_1.isUnknown)(specializedClassType));
|
2486
|
+
classType.details.mro.push(specializedClassType);
|
2516
2487
|
// Helper function that returns true if the specified searchClass
|
2517
2488
|
// is found in the "tail" (i.e. in elements 1 through n) of any
|
2518
2489
|
// of the class lists.
|
@@ -2542,6 +2513,7 @@ function computeMroLinearization(classType) {
|
|
2542
2513
|
}
|
2543
2514
|
if (!(0, types_1.isInstantiableClass)(classList[0])) {
|
2544
2515
|
foundValidHead = true;
|
2516
|
+
(0, debug_1.assert)((0, types_1.isClass)(classList[0]) || (0, types_1.isAnyOrUnknown)(classList[0]));
|
2545
2517
|
classType.details.mro.push(classList[0]);
|
2546
2518
|
classList.shift();
|
2547
2519
|
break;
|
@@ -2566,6 +2538,7 @@ function computeMroLinearization(classType) {
|
|
2566
2538
|
// Handle the situation by pull the head off the first empty list.
|
2567
2539
|
// This allows us to make forward progress.
|
2568
2540
|
if (!(0, types_1.isInstantiableClass)(nonEmptyList[0])) {
|
2541
|
+
(0, debug_1.assert)((0, types_1.isClass)(nonEmptyList[0]) || (0, types_1.isAnyOrUnknown)(nonEmptyList[0]));
|
2569
2542
|
classType.details.mro.push(nonEmptyList[0]);
|
2570
2543
|
nonEmptyList.shift();
|
2571
2544
|
}
|
@@ -2624,10 +2597,13 @@ function addDeclaringModuleNamesForType(type, moduleList, recursionCount = 0) {
|
|
2624
2597
|
}
|
2625
2598
|
}
|
2626
2599
|
}
|
2600
|
+
// Converts a function into a FunctionType that represents the function's
|
2601
|
+
// input signature and converts a ParamSpec into a FunctionType with the input
|
2602
|
+
// signature (*args: P.args, **kwargs: P.kwargs).
|
2627
2603
|
function convertTypeToParamSpecValue(type) {
|
2628
2604
|
if ((0, types_1.isParamSpec)(type)) {
|
2629
2605
|
const newFunction = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */);
|
2630
|
-
|
2606
|
+
types_1.FunctionType.addParamSpecVariadics(newFunction, type);
|
2631
2607
|
newFunction.details.typeVarScopeId = getTypeVarScopeId(type);
|
2632
2608
|
return newFunction;
|
2633
2609
|
}
|
@@ -2648,45 +2624,51 @@ function convertTypeToParamSpecValue(type) {
|
|
2648
2624
|
newFunction.details.higherOrderTypeVarScopeIds = [...type.details.higherOrderTypeVarScopeIds];
|
2649
2625
|
newFunction.details.typeVarScopeId = newFunction.details.higherOrderTypeVarScopeIds.pop();
|
2650
2626
|
}
|
2651
|
-
newFunction.details.paramSpec = type.details.paramSpec;
|
2652
2627
|
return newFunction;
|
2653
2628
|
}
|
2654
2629
|
return getUnknownTypeForParamSpec();
|
2655
2630
|
}
|
2656
2631
|
exports.convertTypeToParamSpecValue = convertTypeToParamSpecValue;
|
2657
|
-
|
2658
|
-
|
2659
|
-
|
2632
|
+
// Converts a FunctionType into a ParamSpec if it consists only of
|
2633
|
+
// (* args: P.args, ** kwargs: P.kwargs). Otherwise returns the original type.
|
2634
|
+
function convertParamSpecValueToType(type) {
|
2635
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(type);
|
2636
|
+
const withoutParamSpec = types_1.FunctionType.cloneRemoveParamSpecArgsKwargs(type);
|
2637
|
+
let hasParameters = withoutParamSpec.details.parameters.length > 0;
|
2638
|
+
if (withoutParamSpec.details.parameters.length === 1) {
|
2660
2639
|
// If the ParamSpec has a position-only separator as its only parameter,
|
2661
2640
|
// treat it as though there are no parameters.
|
2662
|
-
const onlyParam =
|
2641
|
+
const onlyParam = withoutParamSpec.details.parameters[0];
|
2663
2642
|
if ((0, types_1.isPositionOnlySeparator)(onlyParam)) {
|
2664
2643
|
hasParameters = false;
|
2665
2644
|
}
|
2666
2645
|
}
|
2667
|
-
|
2668
|
-
|
2669
|
-
|
2670
|
-
|
2671
|
-
|
2672
|
-
|
2673
|
-
|
2674
|
-
|
2675
|
-
|
2676
|
-
|
2677
|
-
|
2678
|
-
|
2679
|
-
|
2680
|
-
|
2646
|
+
// Can we simplify it to just a paramSpec?
|
2647
|
+
if (!hasParameters && paramSpec) {
|
2648
|
+
return paramSpec;
|
2649
|
+
}
|
2650
|
+
// Create a function type from the param spec entries.
|
2651
|
+
const functionType = types_1.FunctionType.createInstance('', '', '', 65536 /* FunctionTypeFlags.ParamSpecValue */ | withoutParamSpec.details.flags);
|
2652
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.details.typeVarScopeId);
|
2653
|
+
types_1.FunctionType.addHigherOrderTypeVarScopeIds(functionType, withoutParamSpec.details.higherOrderTypeVarScopeIds);
|
2654
|
+
withoutParamSpec.details.parameters.forEach((entry) => {
|
2655
|
+
types_1.FunctionType.addParameter(functionType, {
|
2656
|
+
category: entry.category,
|
2657
|
+
name: entry.name,
|
2658
|
+
hasDefault: entry.hasDefault,
|
2659
|
+
defaultValueExpression: entry.defaultValueExpression,
|
2660
|
+
isNameSynthesized: entry.isNameSynthesized,
|
2661
|
+
hasDeclaredType: true,
|
2662
|
+
type: entry.type,
|
2681
2663
|
});
|
2682
|
-
|
2683
|
-
|
2684
|
-
|
2685
|
-
functionType.details.docString = paramSpecValue.details.docString;
|
2686
|
-
functionType.details.deprecatedMessage = paramSpecValue.details.deprecatedMessage;
|
2687
|
-
return functionType;
|
2664
|
+
});
|
2665
|
+
if (paramSpec) {
|
2666
|
+
types_1.FunctionType.addParamSpecVariadics(functionType, paramSpec);
|
2688
2667
|
}
|
2689
|
-
|
2668
|
+
functionType.details.docString = withoutParamSpec.details.docString;
|
2669
|
+
functionType.details.deprecatedMessage = withoutParamSpec.details.deprecatedMessage;
|
2670
|
+
functionType.details.methodClass = withoutParamSpec.details.methodClass;
|
2671
|
+
return functionType;
|
2690
2672
|
}
|
2691
2673
|
exports.convertParamSpecValueToType = convertParamSpecValueToType;
|
2692
2674
|
// Recursively walks a type and calls a callback for each TypeVar, allowing
|
@@ -2922,11 +2904,19 @@ class TypeVarTransformer {
|
|
2922
2904
|
(0, collectionUtils_1.appendArray)(newTupleTypeArgs, newTypeArgType.tupleTypeArguments);
|
2923
2905
|
}
|
2924
2906
|
else {
|
2925
|
-
|
2926
|
-
|
2927
|
-
|
2928
|
-
|
2929
|
-
|
2907
|
+
// Handle the special case where tuple[T, ...] is being specialized
|
2908
|
+
// to tuple[Never, ...]. This is equivalent to tuple[()].
|
2909
|
+
const isEmptyTuple = oldTypeArgType.isUnbounded &&
|
2910
|
+
(0, types_1.isTypeVar)(oldTypeArgType.type) &&
|
2911
|
+
(0, types_1.isNever)(newTypeArgType) &&
|
2912
|
+
classType.tupleTypeArguments.length === 1;
|
2913
|
+
if (!isEmptyTuple) {
|
2914
|
+
newTupleTypeArgs.push({
|
2915
|
+
type: newTypeArgType,
|
2916
|
+
isUnbounded: oldTypeArgType.isUnbounded,
|
2917
|
+
isOptional: oldTypeArgType.isOptional,
|
2918
|
+
});
|
2919
|
+
}
|
2930
2920
|
}
|
2931
2921
|
});
|
2932
2922
|
}
|
@@ -3013,14 +3003,7 @@ class TypeVarTransformer {
|
|
3013
3003
|
transformTypeVarsInFunctionType(sourceType, recursionCount) {
|
3014
3004
|
return this.doForEachSignatureContext(() => {
|
3015
3005
|
let functionType = sourceType;
|
3016
|
-
|
3017
|
-
if (functionType.details.paramSpec) {
|
3018
|
-
const paramSpec = this.transformParamSpec(functionType.details.paramSpec, recursionCount);
|
3019
|
-
if (paramSpec) {
|
3020
|
-
functionType = types_1.FunctionType.cloneForParamSpec(functionType, paramSpec);
|
3021
|
-
}
|
3022
|
-
}
|
3023
|
-
const declaredReturnType = types_1.FunctionType.getSpecializedReturnType(functionType);
|
3006
|
+
const declaredReturnType = types_1.FunctionType.getEffectiveReturnType(functionType);
|
3024
3007
|
const specializedReturnType = declaredReturnType
|
3025
3008
|
? this.apply(declaredReturnType, recursionCount)
|
3026
3009
|
: undefined;
|
@@ -3029,26 +3012,15 @@ class TypeVarTransformer {
|
|
3029
3012
|
parameterTypes: [],
|
3030
3013
|
returnType: specializedReturnType,
|
3031
3014
|
};
|
3032
|
-
|
3033
|
-
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3038
|
-
|
3039
|
-
|
3040
|
-
|
3041
|
-
kwargsParam.category === 2 /* ParameterCategory.KwargsDict */ &&
|
3042
|
-
(0, types_1.isParamSpec)(argsParamType) &&
|
3043
|
-
(0, types_1.isParamSpec)(kwargsParamType) &&
|
3044
|
-
(0, types_1.isTypeSame)(argsParamType, kwargsParamType)) {
|
3045
|
-
const paramSpecType = this.transformParamSpec(argsParamType, recursionCount);
|
3046
|
-
if (paramSpecType) {
|
3047
|
-
if (paramSpecType.details.parameters.length > 0 ||
|
3048
|
-
paramSpecType.details.paramSpec === undefined ||
|
3049
|
-
!(0, types_1.isTypeSame)(argsParamType, paramSpecType.details.paramSpec)) {
|
3050
|
-
functionType = types_1.FunctionType.cloneForParamSpecApplication(functionType, paramSpecType);
|
3051
|
-
}
|
3015
|
+
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(functionType);
|
3016
|
+
if (paramSpec) {
|
3017
|
+
const paramSpecType = this.transformParamSpec(paramSpec, recursionCount);
|
3018
|
+
if (paramSpecType) {
|
3019
|
+
const transformedParamSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(paramSpecType);
|
3020
|
+
if (paramSpecType.details.parameters.length > 0 ||
|
3021
|
+
!transformedParamSpec ||
|
3022
|
+
!(0, types_1.isTypeSame)(paramSpec, transformedParamSpec)) {
|
3023
|
+
functionType = types_1.FunctionType.applyParamSpecValue(functionType, paramSpecType);
|
3052
3024
|
}
|
3053
3025
|
}
|
3054
3026
|
}
|