@zzzen/pyright-internal 1.2.0-dev.20240310 → 1.2.0-dev.20240317
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.d.ts +1 -0
- package/dist/analyzer/checker.js +38 -45
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/operations.js +8 -8
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.js +1 -1
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +16 -12
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/service.js +1 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +188 -73
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -1
- package/dist/analyzer/typeGuards.js +8 -11
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -1
- package/dist/analyzer/typeUtils.js +13 -14
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +2 -1
- package/dist/analyzer/types.js +1 -0
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +4 -1
- package/dist/backgroundThreadBase.js +14 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +0 -1
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/configOptions.d.ts +1 -0
- package/dist/common/configOptions.js +5 -0
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/diagnosticRules.d.ts +1 -0
- package/dist/common/diagnosticRules.js +1 -0
- package/dist/common/diagnosticRules.js.map +1 -1
- package/dist/common/logTracker.d.ts +5 -5
- package/dist/common/logTracker.js +7 -6
- package/dist/common/logTracker.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -0
- package/dist/localization/localize.js +1 -8
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +13 -5
- package/dist/localization/package.nls.de.json +13 -5
- package/dist/localization/package.nls.en-us.json +1 -0
- package/dist/localization/package.nls.es.json +13 -5
- package/dist/localization/package.nls.fr.json +15 -7
- package/dist/localization/package.nls.it.json +11 -3
- package/dist/localization/package.nls.ja.json +13 -5
- package/dist/localization/package.nls.ko.json +13 -5
- package/dist/localization/package.nls.pl.json +13 -5
- package/dist/localization/package.nls.pt-br.json +13 -5
- package/dist/localization/package.nls.qps-ploc.json +13 -5
- package/dist/localization/package.nls.ru.json +12 -4
- package/dist/localization/package.nls.tr.json +13 -5
- package/dist/localization/package.nls.zh-cn.json +13 -5
- package/dist/localization/package.nls.zh-tw.json +13 -5
- package/dist/parser/parser.js +1 -1
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.js +12 -12
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +0 -1
- package/dist/parser/tokenizer.js +41 -41
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +1 -2
- package/dist/parser/tokenizerTypes.js +0 -1
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js +1 -1
- package/dist/tests/fourslash/completions.override2.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.d.ts +2 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +2 -2
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +1 -1
- package/dist/tests/typeEvaluator3.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +1 -1
- package/dist/tests/typeEvaluator5.test.js +9 -7
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +1 -1
@@ -1342,6 +1342,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1342
1342
|
}
|
1343
1343
|
return { type: types_1.UnknownType.create() };
|
1344
1344
|
}
|
1345
|
+
// If this is an unspecialized generic class, specialize it using the default
|
1346
|
+
// values for its type parameters.
|
1347
|
+
if ((0, types_1.isInstantiableClass)(objectType) &&
|
1348
|
+
!objectType.includeSubclasses &&
|
1349
|
+
objectType.details.typeParameters.length > 0) {
|
1350
|
+
// Skip this if we're suppressing the use of attribute access override,
|
1351
|
+
// such as with dundered methods (like __call__).
|
1352
|
+
if ((flags & 512 /* MemberAccessFlags.SkipAttributeAccessOverride */) === 0) {
|
1353
|
+
objectType = (0, typeUtils_1.specializeWithDefaultTypeArgs)(objectType);
|
1354
|
+
}
|
1355
|
+
}
|
1345
1356
|
// Determine the class that was used to instantiate the objectType.
|
1346
1357
|
// If the objectType is a class itself, then the class used to instantiate
|
1347
1358
|
// it is the metaclass.
|
@@ -1827,8 +1838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1827
1838
|
}
|
1828
1839
|
else {
|
1829
1840
|
const iterReturnTypeDiag = new diagnostic_1.DiagnosticAddendum();
|
1830
|
-
const returnType = mapSubtypesExpandTypeVars(iterReturnType,
|
1831
|
-
/* conditionFilter */ undefined, (subtype) => {
|
1841
|
+
const returnType = mapSubtypesExpandTypeVars(iterReturnType, /* options */ undefined, (subtype) => {
|
1832
1842
|
if ((0, types_1.isAnyOrUnknown)(subtype)) {
|
1833
1843
|
return subtype;
|
1834
1844
|
}
|
@@ -2545,7 +2555,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2545
2555
|
}
|
2546
2556
|
return types_1.AnyType.create();
|
2547
2557
|
}
|
2548
|
-
|
2558
|
+
// Fall back to "*tuple[object, ...]".
|
2559
|
+
return makeTupleObject([{ type: objectType !== null && objectType !== void 0 ? objectType : types_1.UnknownType.create(), isUnbounded: true }],
|
2560
|
+
/* isUnpacked */ true);
|
2549
2561
|
}
|
2550
2562
|
if ((0, types_1.isTypeVar)(subtype)) {
|
2551
2563
|
// If this is a recursive type alias placeholder
|
@@ -2591,16 +2603,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2591
2603
|
// its bound type and a constrained TypeVar is expanded to its individual
|
2592
2604
|
// constrained types). If conditionFilter is specified, conditions that
|
2593
2605
|
// do not match will be ignored.
|
2594
|
-
function mapSubtypesExpandTypeVars(type,
|
2606
|
+
function mapSubtypesExpandTypeVars(type, options, callback, recursionCount = 0) {
|
2595
2607
|
const newSubtypes = [];
|
2596
2608
|
let typeChanged = false;
|
2597
2609
|
function expandSubtype(unexpandedType, isLastSubtype) {
|
2598
2610
|
let expandedType = (0, types_1.isUnion)(unexpandedType) ? unexpandedType : makeTopLevelTypeVarsConcrete(unexpandedType);
|
2599
2611
|
expandedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedType);
|
2612
|
+
if (options === null || options === void 0 ? void 0 : options.expandCallback) {
|
2613
|
+
expandedType = options.expandCallback(expandedType);
|
2614
|
+
}
|
2600
2615
|
(0, typeUtils_1.doForEachSubtype)(expandedType, (subtype, index, allSubtypes) => {
|
2601
2616
|
var _a;
|
2602
|
-
if (conditionFilter) {
|
2603
|
-
const filteredType = applyConditionFilterToType(subtype, conditionFilter, recursionCount);
|
2617
|
+
if (options === null || options === void 0 ? void 0 : options.conditionFilter) {
|
2618
|
+
const filteredType = applyConditionFilterToType(subtype, options.conditionFilter, recursionCount);
|
2604
2619
|
if (!filteredType) {
|
2605
2620
|
return undefined;
|
2606
2621
|
}
|
@@ -2625,10 +2640,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2625
2640
|
}
|
2626
2641
|
}
|
2627
2642
|
return undefined;
|
2628
|
-
}, sortSubtypes);
|
2643
|
+
}, options === null || options === void 0 ? void 0 : options.sortSubtypes);
|
2629
2644
|
}
|
2630
2645
|
if ((0, types_1.isUnion)(type)) {
|
2631
|
-
const subtypes = sortSubtypes ? (0, typeUtils_1.sortTypes)(type.subtypes) : type.subtypes;
|
2646
|
+
const subtypes = (options === null || options === void 0 ? void 0 : options.sortSubtypes) ? (0, typeUtils_1.sortTypes)(type.subtypes) : type.subtypes;
|
2632
2647
|
subtypes.forEach((subtype, index) => {
|
2633
2648
|
expandSubtype(subtype, index === type.subtypes.length - 1);
|
2634
2649
|
});
|
@@ -2669,10 +2684,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2669
2684
|
if (variance !== 3 /* Variance.Covariant */) {
|
2670
2685
|
return typeArg;
|
2671
2686
|
}
|
2672
|
-
const filteredTypeArg = mapSubtypesExpandTypeVars(typeArg, conditionFilter, (expandedSubtype) => {
|
2687
|
+
const filteredTypeArg = mapSubtypesExpandTypeVars(typeArg, { conditionFilter }, (expandedSubtype) => {
|
2673
2688
|
return expandedSubtype;
|
2674
|
-
},
|
2675
|
-
/* sortSubtypes */ undefined, recursionCount);
|
2689
|
+
}, recursionCount);
|
2676
2690
|
if (filteredTypeArg !== typeArg) {
|
2677
2691
|
typeWasTransformed = true;
|
2678
2692
|
}
|
@@ -3288,11 +3302,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3288
3302
|
const defaultTypeArgs = [];
|
3289
3303
|
const typeVarContext = new typeVarContext_1.TypeVarContext(type.typeAliasInfo.typeVarScopeId);
|
3290
3304
|
type.typeAliasInfo.typeParameters.forEach((param) => {
|
3291
|
-
if (!param.details.
|
3305
|
+
if (!param.details.isDefaultExplicit) {
|
3292
3306
|
reportMissingTypeArguments = true;
|
3293
3307
|
}
|
3294
3308
|
let defaultType;
|
3295
|
-
if (param.details.
|
3309
|
+
if (param.details.isDefaultExplicit || param.details.isParamSpec) {
|
3296
3310
|
defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
|
3297
3311
|
}
|
3298
3312
|
else if (param.details.isVariadic && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
@@ -4386,7 +4400,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4386
4400
|
// known to have symmetric __getitem__ and __setitem__ methods (i.e. the value
|
4387
4401
|
// passed to __setitem__ is the same type as the value returned by __getitem__).
|
4388
4402
|
let baseTypeSupportsIndexNarrowing = !(0, types_1.isAny)(baseTypeResult.type);
|
4389
|
-
mapSubtypesExpandTypeVars(baseTypeResult.type, /*
|
4403
|
+
mapSubtypesExpandTypeVars(baseTypeResult.type, /* options */ undefined, (subtype) => {
|
4390
4404
|
if (!(0, types_1.isClassInstance)(subtype) ||
|
4391
4405
|
!(types_1.ClassType.isBuiltIn(subtype) || types_1.ClassType.isTypedDictClass(subtype))) {
|
4392
4406
|
baseTypeSupportsIndexNarrowing = false;
|
@@ -4460,8 +4474,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4460
4474
|
// param somewhere in the list?
|
4461
4475
|
if (variadicIndex >= 0) {
|
4462
4476
|
const variadicTypeVar = typeParameters[variadicIndex];
|
4477
|
+
// If the type param list ends with a ParamSpec with a default value,
|
4478
|
+
// we can ignore it for purposes of finding type args that map to the
|
4479
|
+
// TypeVarTuple.
|
4480
|
+
let typeParamCount = typeParameters.length;
|
4481
|
+
while (typeParamCount > 0) {
|
4482
|
+
const lastTypeParam = typeParameters[typeParamCount - 1];
|
4483
|
+
if (!lastTypeParam.details.isParamSpec || !lastTypeParam.details.isDefaultExplicit) {
|
4484
|
+
break;
|
4485
|
+
}
|
4486
|
+
typeParamCount--;
|
4487
|
+
}
|
4463
4488
|
if (variadicIndex < typeArgs.length) {
|
4464
|
-
|
4489
|
+
// If there are typeArg lists at the end, these should map to ParamSpecs rather
|
4490
|
+
// than the TypeVarTuple, so exclude them.
|
4491
|
+
let variadicEndIndex = variadicIndex + 1 + typeArgs.length - typeParamCount;
|
4492
|
+
while (variadicEndIndex > variadicIndex) {
|
4493
|
+
if (!typeArgs[variadicEndIndex - 1].typeList) {
|
4494
|
+
break;
|
4495
|
+
}
|
4496
|
+
variadicEndIndex--;
|
4497
|
+
}
|
4498
|
+
const variadicTypeResults = typeArgs.slice(variadicIndex, variadicEndIndex);
|
4465
4499
|
// If the type args consist of a lone variadic type variable, don't wrap it in a tuple.
|
4466
4500
|
if (variadicTypeResults.length === 1 && (0, types_1.isVariadicTypeVar)(variadicTypeResults[0].type)) {
|
4467
4501
|
validateVariadicTypeVarIsUnpacked(variadicTypeResults[0].type, variadicTypeResults[0].node);
|
@@ -4492,11 +4526,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4492
4526
|
typeArgs = [
|
4493
4527
|
...typeArgs.slice(0, variadicIndex),
|
4494
4528
|
{ node: typeArgs[variadicIndex].node, type: tupleObject },
|
4495
|
-
...typeArgs.slice(
|
4529
|
+
...typeArgs.slice(variadicEndIndex, typeArgs.length),
|
4496
4530
|
];
|
4497
4531
|
}
|
4498
4532
|
}
|
4499
|
-
else if (!variadicTypeVar.details.
|
4533
|
+
else if (!variadicTypeVar.details.isDefaultExplicit) {
|
4500
4534
|
// Add an empty tuple that maps to the TypeVarTuple type parameter.
|
4501
4535
|
typeArgs.push({
|
4502
4536
|
node: errorNode,
|
@@ -4551,7 +4585,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4551
4585
|
}
|
4552
4586
|
}
|
4553
4587
|
let minTypeArgCount = typeParameters.length;
|
4554
|
-
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.
|
4588
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.isDefaultExplicit);
|
4555
4589
|
if (firstDefaultParamIndex >= 0) {
|
4556
4590
|
minTypeArgCount = firstDefaultParamIndex;
|
4557
4591
|
}
|
@@ -4645,7 +4679,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4645
4679
|
if (index < typeArgs.length) {
|
4646
4680
|
typeArgType = (0, typeUtils_1.convertToInstance)(typeArgs[index].type);
|
4647
4681
|
}
|
4648
|
-
else if (param.details.
|
4682
|
+
else if (param.details.isDefaultExplicit) {
|
4649
4683
|
typeArgType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
|
4650
4684
|
}
|
4651
4685
|
else {
|
@@ -4717,7 +4751,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4717
4751
|
let isNotRequired = false;
|
4718
4752
|
let isReadOnly = false;
|
4719
4753
|
const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
|
4720
|
-
/*
|
4754
|
+
/* options */ undefined, (concreteSubtype, unexpandedSubtype) => {
|
4721
4755
|
var _a;
|
4722
4756
|
const selfType = (0, types_1.isTypeVar)(unexpandedSubtype) ? unexpandedSubtype : undefined;
|
4723
4757
|
if ((0, types_1.isAnyOrUnknown)(concreteSubtype)) {
|
@@ -6437,8 +6471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6437
6471
|
}), exprNode);
|
6438
6472
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6439
6473
|
}
|
6440
|
-
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type,
|
6441
|
-
/* conditionFilter */ undefined, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
|
6474
|
+
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type, { sortSubtypes: true }, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
|
6442
6475
|
return useSpeculativeMode(isLastIteration ? undefined : errorNode, () => {
|
6443
6476
|
const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6444
6477
|
if (callResult.argumentErrors) {
|
@@ -6455,8 +6488,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6455
6488
|
}, {
|
6456
6489
|
allowDiagnostics: true,
|
6457
6490
|
});
|
6458
|
-
}
|
6459
|
-
/* sortSubtypes */ true);
|
6491
|
+
});
|
6460
6492
|
// If we ended up with a "Never" type because all code paths returned
|
6461
6493
|
// undefined due to argument errors, transform the result into an Unknown
|
6462
6494
|
// to avoid subsequent false positives.
|
@@ -8419,7 +8451,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8419
8451
|
// if appropriate. This doesn't properly handle non-top-level constrained
|
8420
8452
|
// type variables.
|
8421
8453
|
if (options.conditionFilter) {
|
8422
|
-
argType = mapSubtypesExpandTypeVars(argType, options.conditionFilter, (expandedSubtype) => {
|
8454
|
+
argType = mapSubtypesExpandTypeVars(argType, { conditionFilter: options.conditionFilter }, (expandedSubtype) => {
|
8423
8455
|
return expandedSubtype;
|
8424
8456
|
});
|
8425
8457
|
}
|
@@ -8661,6 +8693,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8661
8693
|
allowTypeVarsWithoutScopeId: true,
|
8662
8694
|
}).type;
|
8663
8695
|
typeVar.details.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
8696
|
+
typeVar.details.isDefaultExplicit = true;
|
8664
8697
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8665
8698
|
if (!fileInfo.isStubFile &&
|
8666
8699
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
@@ -8694,23 +8727,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8694
8727
|
}
|
8695
8728
|
// If a default is provided, make sure it is compatible with the bound
|
8696
8729
|
// or constraint.
|
8697
|
-
if (typeVar.details.
|
8698
|
-
|
8699
|
-
|
8700
|
-
|
8701
|
-
|
8702
|
-
|
8703
|
-
|
8704
|
-
|
8705
|
-
|
8730
|
+
if (typeVar.details.isDefaultExplicit && defaultValueNode) {
|
8731
|
+
verifyTypeVarDefaultIsCompatible(typeVar, defaultValueNode);
|
8732
|
+
}
|
8733
|
+
return typeVar;
|
8734
|
+
}
|
8735
|
+
function verifyTypeVarDefaultIsCompatible(typeVar, defaultValueNode) {
|
8736
|
+
(0, debug_1.assert)(typeVar.details.isDefaultExplicit);
|
8737
|
+
const typeVarContext = new typeVarContext_1.TypeVarContext(types_1.WildcardTypeVarScopeId);
|
8738
|
+
const concreteDefaultType = makeTopLevelTypeVarsConcrete((0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext, {
|
8739
|
+
unknownIfNotFound: true,
|
8740
|
+
}));
|
8741
|
+
if (typeVar.details.boundType) {
|
8742
|
+
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
8743
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), defaultValueNode);
|
8706
8744
|
}
|
8707
|
-
|
8708
|
-
|
8709
|
-
|
8745
|
+
}
|
8746
|
+
else if (typeVar.details.constraints.length > 0) {
|
8747
|
+
let isConstraintCompatible = true;
|
8748
|
+
// If the default type is a constrained TypeVar, make sure all of its constraints
|
8749
|
+
// are also constraints in typeVar. If the default type is not a constrained TypeVar,
|
8750
|
+
// use its concrete type to compare against the constraints.
|
8751
|
+
if ((0, types_1.isTypeVar)(typeVar.details.defaultType) && typeVar.details.defaultType.details.constraints.length > 0) {
|
8752
|
+
for (const constraint of typeVar.details.defaultType.details.constraints) {
|
8753
|
+
if (!typeVar.details.constraints.some((c) => (0, types_1.isTypeSame)(c, constraint))) {
|
8754
|
+
isConstraintCompatible = false;
|
8755
|
+
}
|
8710
8756
|
}
|
8711
8757
|
}
|
8758
|
+
else if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType, { ignoreConditions: true }))) {
|
8759
|
+
isConstraintCompatible = false;
|
8760
|
+
}
|
8761
|
+
if (!isConstraintCompatible) {
|
8762
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), defaultValueNode);
|
8763
|
+
}
|
8712
8764
|
}
|
8713
|
-
return typeVar;
|
8714
8765
|
}
|
8715
8766
|
function createTypeVarTupleType(errorNode, classType, argList) {
|
8716
8767
|
var _a, _b;
|
@@ -8728,6 +8779,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8728
8779
|
}
|
8729
8780
|
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false), types_1.ClassType.cloneAsInstance(classType));
|
8730
8781
|
typeVar.details.isVariadic = true;
|
8782
|
+
typeVar.details.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
8731
8783
|
// Parse the remaining parameters.
|
8732
8784
|
for (let i = 1; i < argList.length; i++) {
|
8733
8785
|
const paramNameNode = argList[i].name;
|
@@ -8736,7 +8788,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8736
8788
|
if (paramName === 'default') {
|
8737
8789
|
const expr = argList[i].valueExpression;
|
8738
8790
|
if (expr) {
|
8739
|
-
|
8791
|
+
const defaultType = getTypeVarTupleDefaultType(expr);
|
8792
|
+
if (defaultType) {
|
8793
|
+
typeVar.details.defaultType = defaultType;
|
8794
|
+
typeVar.details.isDefaultExplicit = true;
|
8795
|
+
}
|
8740
8796
|
}
|
8741
8797
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8742
8798
|
if (!fileInfo.isStubFile &&
|
@@ -8782,6 +8838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8782
8838
|
addError(localize_1.LocMessage.paramSpecFirstArg(), firstArg.valueExpression || errorNode);
|
8783
8839
|
}
|
8784
8840
|
const paramSpec = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(paramSpecName, /* isParamSpec */ true), types_1.ClassType.cloneAsInstance(classType));
|
8841
|
+
paramSpec.details.defaultType = (0, typeUtils_1.getUnknownTypeForParamSpec)();
|
8785
8842
|
// Parse the remaining parameters.
|
8786
8843
|
for (let i = 1; i < argList.length; i++) {
|
8787
8844
|
const paramNameNode = argList[i].name;
|
@@ -8790,7 +8847,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8790
8847
|
if (paramName === 'default') {
|
8791
8848
|
const expr = argList[i].valueExpression;
|
8792
8849
|
if (expr) {
|
8793
|
-
|
8850
|
+
const defaultType = getParamSpecDefaultType(expr);
|
8851
|
+
if (defaultType) {
|
8852
|
+
paramSpec.details.defaultType = defaultType;
|
8853
|
+
paramSpec.details.isDefaultExplicit = true;
|
8854
|
+
}
|
8794
8855
|
}
|
8795
8856
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8796
8857
|
if (!fileInfo.isStubFile &&
|
@@ -9582,8 +9643,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9582
9643
|
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9583
9644
|
}
|
9584
9645
|
});
|
9585
|
-
|
9586
|
-
|
9646
|
+
let isTypeInvariant = false;
|
9647
|
+
if ((0, types_1.isClassInstance)(inferenceContext.expectedType)) {
|
9648
|
+
inferTypeParameterVarianceForClass(inferenceContext.expectedType);
|
9649
|
+
if (inferenceContext.expectedType.details.typeParameters.some((t) => types_1.TypeVarType.getVariance(t) === 2 /* Variance.Invariant */)) {
|
9650
|
+
isTypeInvariant = true;
|
9651
|
+
}
|
9652
|
+
}
|
9587
9653
|
const specializedEntryType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedEntryType), entryTypes, !isTypeInvariant);
|
9588
9654
|
if (!specializedEntryType) {
|
9589
9655
|
return { type: types_1.UnknownType.create(), isIncomplete, typeErrors: true, expectedTypeDiagAddendum };
|
@@ -9624,7 +9690,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9624
9690
|
let entryTypes = [];
|
9625
9691
|
node.entries.forEach((entry, index) => {
|
9626
9692
|
let entryTypeResult;
|
9627
|
-
if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
9693
|
+
if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */ && !entry.isGenerator) {
|
9628
9694
|
entryTypeResult = getElementTypeFromListComprehension(entry);
|
9629
9695
|
}
|
9630
9696
|
else {
|
@@ -9684,7 +9750,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9684
9750
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9685
9751
|
diag.addMessage(localize_1.LocAddendum.unhashableType().format({ type: printType(type) }));
|
9686
9752
|
const message = isDictKey ? localize_1.LocMessage.unhashableDictKey() : localize_1.LocMessage.unhashableSetEntry();
|
9687
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.
|
9753
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnhashable, message + diag.getString(), entry);
|
9688
9754
|
}
|
9689
9755
|
}
|
9690
9756
|
function inferTypeArgFromExpectedEntryType(inferenceContext, entryTypes, isNarrowable) {
|
@@ -10902,6 +10968,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10902
10968
|
}
|
10903
10969
|
return (0, typeUtils_1.convertToInstance)(typeVar);
|
10904
10970
|
});
|
10971
|
+
// See if the type alias includes a TypeVarTuple followed by a TypeVar
|
10972
|
+
// with a default value. This isn't allowed.
|
10973
|
+
const firstTypeVarTupleIndex = typeParameters.findIndex((typeVar) => (0, types_1.isVariadicTypeVar)(typeVar));
|
10974
|
+
if (firstTypeVarTupleIndex >= 0) {
|
10975
|
+
const typeVarWithDefaultIndex = typeParameters.findIndex((typeVar, index) => index > firstTypeVarTupleIndex && !typeVar.details.isParamSpec && typeVar.details.isDefaultExplicit);
|
10976
|
+
if (typeVarWithDefaultIndex >= 0) {
|
10977
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithDefaultFollowsVariadic().format({
|
10978
|
+
typeVarName: typeParameters[typeVarWithDefaultIndex].details.name,
|
10979
|
+
variadicName: typeParameters[firstTypeVarTupleIndex].details.name,
|
10980
|
+
}), typeParamNodes ? typeParamNodes[typeVarWithDefaultIndex].name : name);
|
10981
|
+
}
|
10982
|
+
}
|
10905
10983
|
const typeAliasScopeId = ParseTreeUtils.getScopeIdForNode(name);
|
10906
10984
|
// Validate the default types for all type parameters.
|
10907
10985
|
typeParameters.forEach((typeParam, index) => {
|
@@ -11310,6 +11388,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11310
11388
|
}
|
11311
11389
|
aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
|
11312
11390
|
/* isPep695TypeVarType */ true, typeParameters, typeParamNodes);
|
11391
|
+
// See if the type alias relies on itself in a way that cannot be resolved.
|
11313
11392
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
11314
11393
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11315
11394
|
name: nameNode.value,
|
@@ -11659,12 +11738,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11659
11738
|
classType.details.requiresVarianceInference = true;
|
11660
11739
|
}
|
11661
11740
|
// Make sure there's at most one variadic type parameter.
|
11662
|
-
const variadics =
|
11741
|
+
const variadics = typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
|
11663
11742
|
if (variadics.length > 1) {
|
11664
|
-
|
11743
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.variadicTypeParamTooManyClass().format({
|
11665
11744
|
names: variadics.map((v) => `"${v.details.name}"`).join(', '),
|
11666
11745
|
}), node.name, textRange_1.TextRange.combine(node.arguments) || node.name);
|
11667
11746
|
}
|
11747
|
+
else if (variadics.length > 0) {
|
11748
|
+
// Make sure a TypeVar with a default doesn't come after a variadic type parameter.
|
11749
|
+
const firstVariadicIndex = classType.details.typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
11750
|
+
const typeVarWithDefaultIndex = classType.details.typeParameters.findIndex((param, index) => index > firstVariadicIndex && !param.details.isParamSpec && param.details.isDefaultExplicit);
|
11751
|
+
if (typeVarWithDefaultIndex >= 0) {
|
11752
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithDefaultFollowsVariadic().format({
|
11753
|
+
typeVarName: typeParameters[typeVarWithDefaultIndex].details.name,
|
11754
|
+
variadicName: typeParameters[firstVariadicIndex].details.name,
|
11755
|
+
}), node.typeParameters ? node.typeParameters.parameters[typeVarWithDefaultIndex].name : node.name);
|
11756
|
+
}
|
11757
|
+
}
|
11668
11758
|
// Validate the default types for all type parameters.
|
11669
11759
|
classType.details.typeParameters.forEach((typeParam, index) => {
|
11670
11760
|
var _a;
|
@@ -11676,7 +11766,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11676
11766
|
validateTypeParameterDefault(bestErrorNode, typeParam, classType.details.typeParameters.slice(0, index), classType.details.typeVarScopeId);
|
11677
11767
|
});
|
11678
11768
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
11679
|
-
|
11769
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodOrdering(), node.name);
|
11680
11770
|
}
|
11681
11771
|
// The scope for this class becomes the "fields" for the corresponding type.
|
11682
11772
|
const innerScope = ScopeUtils.getScopeForNode(node.suite);
|
@@ -11892,10 +11982,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11892
11982
|
// parameters and updates the scope of the type parameter referred to in the
|
11893
11983
|
// default type expression.
|
11894
11984
|
function validateTypeParameterDefault(errorNode, typeParam, otherLiveTypeParams, scopeId) {
|
11895
|
-
if (!typeParam.details.
|
11985
|
+
if (!typeParam.details.isDefaultExplicit &&
|
11896
11986
|
!typeParam.details.isSynthesized &&
|
11897
11987
|
!typeParam.details.isSynthesizedSelf) {
|
11898
|
-
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.
|
11988
|
+
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.isDefaultExplicit && param.scopeId === scopeId);
|
11899
11989
|
if (typeVarWithDefault) {
|
11900
11990
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithoutDefault().format({
|
11901
11991
|
name: typeParam.details.name,
|
@@ -14110,7 +14200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14110
14200
|
const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
14111
14201
|
if (typeArgs) {
|
14112
14202
|
let minTypeArgCount = typeParameters.length;
|
14113
|
-
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.
|
14203
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.isDefaultExplicit);
|
14114
14204
|
if (firstDefaultParamIndex >= 0) {
|
14115
14205
|
minTypeArgCount = firstDefaultParamIndex;
|
14116
14206
|
}
|
@@ -14965,35 +15055,43 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14965
15055
|
}
|
14966
15056
|
}
|
14967
15057
|
}
|
14968
|
-
if (node.
|
14969
|
-
|
14970
|
-
|
15058
|
+
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec) {
|
15059
|
+
const defaultType = node.defaultExpression ? getParamSpecDefaultType(node.defaultExpression) : undefined;
|
15060
|
+
if (defaultType) {
|
15061
|
+
typeVar.details.defaultType = defaultType;
|
15062
|
+
typeVar.details.isDefaultExplicit = true;
|
14971
15063
|
}
|
14972
|
-
else
|
14973
|
-
typeVar.details.defaultType =
|
15064
|
+
else {
|
15065
|
+
typeVar.details.defaultType = (0, typeUtils_1.getUnknownTypeForParamSpec)();
|
15066
|
+
}
|
15067
|
+
}
|
15068
|
+
else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
|
15069
|
+
const defaultType = node.defaultExpression ? getTypeVarTupleDefaultType(node.defaultExpression) : undefined;
|
15070
|
+
if (defaultType) {
|
15071
|
+
typeVar.details.defaultType = defaultType;
|
15072
|
+
typeVar.details.isDefaultExplicit = true;
|
14974
15073
|
}
|
14975
15074
|
else {
|
14976
|
-
typeVar.details.defaultType = (
|
15075
|
+
typeVar.details.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
14977
15076
|
}
|
14978
15077
|
}
|
14979
|
-
|
14980
|
-
|
14981
|
-
|
14982
|
-
|
14983
|
-
|
14984
|
-
|
14985
|
-
|
14986
|
-
if (typeVar.details.boundType) {
|
14987
|
-
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
14988
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), node.defaultExpression);
|
14989
|
-
}
|
15078
|
+
else {
|
15079
|
+
const defaultType = node.defaultExpression
|
15080
|
+
? (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(node.defaultExpression).type)
|
15081
|
+
: undefined;
|
15082
|
+
if (defaultType) {
|
15083
|
+
typeVar.details.defaultType = defaultType;
|
15084
|
+
typeVar.details.isDefaultExplicit = true;
|
14990
15085
|
}
|
14991
|
-
else
|
14992
|
-
|
14993
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), node.defaultExpression);
|
14994
|
-
}
|
15086
|
+
else {
|
15087
|
+
typeVar.details.defaultType = types_1.UnknownType.create();
|
14995
15088
|
}
|
14996
15089
|
}
|
15090
|
+
// If a default is provided, make sure it is compatible with the bound
|
15091
|
+
// or constraint.
|
15092
|
+
if (typeVar.details.isDefaultExplicit && node.defaultExpression) {
|
15093
|
+
verifyTypeVarDefaultIsCompatible(typeVar, node.defaultExpression);
|
15094
|
+
}
|
14997
15095
|
// Associate the type variable with the owning scope.
|
14998
15096
|
const scopeNode = ParseTreeUtils.getTypeVarScopeNode(node);
|
14999
15097
|
if (scopeNode) {
|
@@ -15354,7 +15452,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15354
15452
|
const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
15355
15453
|
allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
|
15356
15454
|
})) !== null && _a !== void 0 ? _a : decl;
|
15357
|
-
if (!isPossibleTypeAliasDeclaration(resolvedDecl)) {
|
15455
|
+
if (!isPossibleTypeAliasDeclaration(resolvedDecl) && !isExplicitTypeAliasDeclaration(resolvedDecl)) {
|
15358
15456
|
includesIllegalTypeAliasDecl = true;
|
15359
15457
|
}
|
15360
15458
|
if (resolvedDecl.type === 1 /* DeclarationType.Variable */) {
|
@@ -17854,7 +17952,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17854
17952
|
if (srcStartOfNamed >= 0) {
|
17855
17953
|
srcParamDetails.params.forEach((srcParamInfo, index) => {
|
17856
17954
|
if (index >= srcStartOfNamed) {
|
17857
|
-
if (srcParamInfo.param.name &&
|
17955
|
+
if (srcParamInfo.param.name &&
|
17956
|
+
srcParamInfo.param.category === 0 /* ParameterCategory.Simple */ &&
|
17957
|
+
srcParamInfo.source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
17858
17958
|
const destParamInfo = destParamMap.get(srcParamInfo.param.name);
|
17859
17959
|
const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
17860
17960
|
const srcParamType = srcParamInfo.type;
|
@@ -18469,6 +18569,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18469
18569
|
}
|
18470
18570
|
}
|
18471
18571
|
}
|
18572
|
+
// Check for positional (named) parameters in the base method that
|
18573
|
+
// do not exist in the override.
|
18574
|
+
if (enforceParamNames && overrideParamDetails.kwargsIndex === undefined) {
|
18575
|
+
for (let i = positionalParamCount; i < baseParamDetails.positionParamCount; i++) {
|
18576
|
+
const baseParam = baseParamDetails.params[i];
|
18577
|
+
if (baseParam.source === parameterUtils_1.ParameterSource.PositionOrKeyword &&
|
18578
|
+
baseParam.param.category === 0 /* ParameterCategory.Simple */) {
|
18579
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18580
|
+
index: i + 1,
|
18581
|
+
baseName: baseParam.param.name || '*',
|
18582
|
+
}));
|
18583
|
+
canOverride = false;
|
18584
|
+
}
|
18585
|
+
}
|
18586
|
+
}
|
18472
18587
|
// Check for a *args match.
|
18473
18588
|
if (baseParamDetails.argsIndex !== undefined) {
|
18474
18589
|
if (overrideParamDetails.argsIndex === undefined) {
|