@zzzen/pyright-internal 1.2.0-dev.20240307 → 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/backgroundAnalysisProgram.d.ts +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +58 -55
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.d.ts +3 -4
- package/dist/analyzer/codeFlowEngine.js +20 -13
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/importStatementUtils.d.ts +2 -1
- package/dist/analyzer/importStatementUtils.js +6 -1
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/operations.js +25 -10
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +2 -0
- package/dist/analyzer/parseTreeUtils.js +31 -5
- 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.d.ts +6 -1
- package/dist/analyzer/service.js +8 -5
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +3 -3
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +242 -101
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -1
- package/dist/analyzer/typeGuards.js +15 -16
- 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/languageServerBase.d.ts +2 -2
- package/dist/languageServerBase.js +1 -8
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +4 -1
- package/dist/languageService/completionProvider.js +19 -19
- package/dist/languageService/completionProvider.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 +19 -9
- package/dist/localization/package.nls.de.json +19 -9
- package/dist/localization/package.nls.en-us.json +1 -0
- package/dist/localization/package.nls.es.json +19 -9
- package/dist/localization/package.nls.fr.json +21 -11
- package/dist/localization/package.nls.it.json +16 -6
- package/dist/localization/package.nls.ja.json +19 -9
- package/dist/localization/package.nls.ko.json +19 -9
- package/dist/localization/package.nls.pl.json +19 -9
- package/dist/localization/package.nls.pt-br.json +19 -9
- package/dist/localization/package.nls.qps-ploc.json +19 -9
- package/dist/localization/package.nls.ru.json +18 -8
- package/dist/localization/package.nls.tr.json +19 -9
- package/dist/localization/package.nls.zh-cn.json +16 -6
- package/dist/localization/package.nls.zh-tw.json +19 -9
- 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/fourslash/hover.builtinDocstrings.builtinInheritedByBuiltin.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.builtinInheritedByBuiltin.fourslash.js +22 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.builtinInheritedByBuiltin.fourslash.js.map +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.builtinInheritedByUserCode.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.builtinInheritedByUserCode.fourslash.js +20 -0
- package/dist/tests/fourslash/hover.builtinDocstrings.builtinInheritedByUserCode.fourslash.js.map +1 -0
- 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/importStatementUtils.test.js +27 -2
- package/dist/tests/importStatementUtils.test.js.map +1 -1
- package/dist/tests/tokenizer.test.js +22 -0
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -0
- package/dist/tests/typeEvaluator1.test.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 +2 -2
- 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
|
}
|
@@ -2034,12 +2044,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2034
2044
|
// Although isFlowNodeReachable indicates that the node is reachable, it
|
2035
2045
|
// may not be reachable if we apply "never narrowing".
|
2036
2046
|
function isFlowNodeReachableUsingNeverNarrowing(node, flowNode) {
|
2037
|
-
const analyzer = getCodeFlowAnalyzerForNode(node.id);
|
2047
|
+
const analyzer = getCodeFlowAnalyzerForNode(node.id, /* typeAtStart */ undefined);
|
2038
2048
|
if (checkCodeFlowTooComplex(node)) {
|
2039
2049
|
return true;
|
2040
2050
|
}
|
2041
2051
|
const codeFlowResult = analyzer.getTypeFromCodeFlow(flowNode, /* reference */ undefined, {
|
2042
|
-
typeAtStart: types_1.UnboundType.create(),
|
2052
|
+
typeAtStart: { type: types_1.UnboundType.create() },
|
2043
2053
|
});
|
2044
2054
|
return codeFlowResult.type !== undefined && !(0, types_1.isNever)(codeFlowResult.type);
|
2045
2055
|
}
|
@@ -2221,12 +2231,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2221
2231
|
}
|
2222
2232
|
}
|
2223
2233
|
}
|
2224
|
-
const
|
2234
|
+
const varDeclIndex = declarations.findIndex((decl) => decl.type === 1 /* DeclarationType.Variable */);
|
2235
|
+
const varDecl = varDeclIndex >= 0 ? declarations[varDeclIndex] : undefined;
|
2236
|
+
// Are there any non-var decls before the var decl?
|
2237
|
+
const nonVarDecl = declarations.find((decl, index) => varDeclIndex < index && decl.type !== 1 /* DeclarationType.Variable */);
|
2225
2238
|
if (varDecl && varDecl.type === 1 /* DeclarationType.Variable */) {
|
2226
2239
|
if (varDecl.isConstant) {
|
2227
2240
|
// A constant variable can be assigned only once. If this
|
2228
2241
|
// isn't the first assignment, generate an error.
|
2229
|
-
if (nameNode !== (0, declarationUtils_1.getNameNodeForDeclaration)(declarations[0])) {
|
2242
|
+
if (nameNode !== (0, declarationUtils_1.getNameNodeForDeclaration)(declarations[0]) || !!nonVarDecl) {
|
2230
2243
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportConstantRedefinition, localize_1.LocMessage.constantRedefinition().format({ name: nameValue }), nameNode);
|
2231
2244
|
}
|
2232
2245
|
}
|
@@ -2542,7 +2555,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2542
2555
|
}
|
2543
2556
|
return types_1.AnyType.create();
|
2544
2557
|
}
|
2545
|
-
|
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);
|
2546
2561
|
}
|
2547
2562
|
if ((0, types_1.isTypeVar)(subtype)) {
|
2548
2563
|
// If this is a recursive type alias placeholder
|
@@ -2588,16 +2603,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2588
2603
|
// its bound type and a constrained TypeVar is expanded to its individual
|
2589
2604
|
// constrained types). If conditionFilter is specified, conditions that
|
2590
2605
|
// do not match will be ignored.
|
2591
|
-
function mapSubtypesExpandTypeVars(type,
|
2606
|
+
function mapSubtypesExpandTypeVars(type, options, callback, recursionCount = 0) {
|
2592
2607
|
const newSubtypes = [];
|
2593
2608
|
let typeChanged = false;
|
2594
2609
|
function expandSubtype(unexpandedType, isLastSubtype) {
|
2595
2610
|
let expandedType = (0, types_1.isUnion)(unexpandedType) ? unexpandedType : makeTopLevelTypeVarsConcrete(unexpandedType);
|
2596
2611
|
expandedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedType);
|
2612
|
+
if (options === null || options === void 0 ? void 0 : options.expandCallback) {
|
2613
|
+
expandedType = options.expandCallback(expandedType);
|
2614
|
+
}
|
2597
2615
|
(0, typeUtils_1.doForEachSubtype)(expandedType, (subtype, index, allSubtypes) => {
|
2598
2616
|
var _a;
|
2599
|
-
if (conditionFilter) {
|
2600
|
-
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);
|
2601
2619
|
if (!filteredType) {
|
2602
2620
|
return undefined;
|
2603
2621
|
}
|
@@ -2622,10 +2640,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2622
2640
|
}
|
2623
2641
|
}
|
2624
2642
|
return undefined;
|
2625
|
-
}, sortSubtypes);
|
2643
|
+
}, options === null || options === void 0 ? void 0 : options.sortSubtypes);
|
2626
2644
|
}
|
2627
2645
|
if ((0, types_1.isUnion)(type)) {
|
2628
|
-
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;
|
2629
2647
|
subtypes.forEach((subtype, index) => {
|
2630
2648
|
expandSubtype(subtype, index === type.subtypes.length - 1);
|
2631
2649
|
});
|
@@ -2666,10 +2684,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2666
2684
|
if (variance !== 3 /* Variance.Covariant */) {
|
2667
2685
|
return typeArg;
|
2668
2686
|
}
|
2669
|
-
const filteredTypeArg = mapSubtypesExpandTypeVars(typeArg, conditionFilter, (expandedSubtype) => {
|
2687
|
+
const filteredTypeArg = mapSubtypesExpandTypeVars(typeArg, { conditionFilter }, (expandedSubtype) => {
|
2670
2688
|
return expandedSubtype;
|
2671
|
-
},
|
2672
|
-
/* sortSubtypes */ undefined, recursionCount);
|
2689
|
+
}, recursionCount);
|
2673
2690
|
if (filteredTypeArg !== typeArg) {
|
2674
2691
|
typeWasTransformed = true;
|
2675
2692
|
}
|
@@ -2970,6 +2987,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2970
2987
|
// type. If it's declared inside our execution scope, it generally starts
|
2971
2988
|
// as unbound at the start of the code flow.
|
2972
2989
|
let typeAtStart = effectiveType;
|
2990
|
+
let isTypeAtStartIncomplete = false;
|
2973
2991
|
if (!symbolWithScope.isBeyondExecutionScope && symbol.isInitiallyUnbound()) {
|
2974
2992
|
typeAtStart = types_1.UnboundType.create();
|
2975
2993
|
// Is this a module-level scope? If so, see if it's an alias of a builtin.
|
@@ -2982,9 +3000,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2982
3000
|
}
|
2983
3001
|
}
|
2984
3002
|
}
|
3003
|
+
if (symbolWithScope.isBeyondExecutionScope) {
|
3004
|
+
const outerScopeTypeResult = getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType);
|
3005
|
+
if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.type) {
|
3006
|
+
type = outerScopeTypeResult.type;
|
3007
|
+
typeAtStart = type;
|
3008
|
+
isTypeAtStartIncomplete = !!outerScopeTypeResult.isIncomplete;
|
3009
|
+
}
|
3010
|
+
}
|
2985
3011
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
2986
3012
|
targetSymbolId: symbol.id,
|
2987
|
-
typeAtStart,
|
3013
|
+
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
2988
3014
|
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
2989
3015
|
});
|
2990
3016
|
if (codeFlowTypeResult.type) {
|
@@ -2993,15 +3019,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2993
3019
|
if (codeFlowTypeResult.isIncomplete) {
|
2994
3020
|
isIncomplete = true;
|
2995
3021
|
}
|
2996
|
-
if (!codeFlowTypeResult.type && symbolWithScope.isBeyondExecutionScope) {
|
2997
|
-
const outerScopeTypeResult = getCodeFlowTypeForCapturedVariable(node, symbolWithScope, effectiveType);
|
2998
|
-
if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.type) {
|
2999
|
-
type = outerScopeTypeResult.type;
|
3000
|
-
}
|
3001
|
-
if (outerScopeTypeResult === null || outerScopeTypeResult === void 0 ? void 0 : outerScopeTypeResult.isIncomplete) {
|
3002
|
-
isIncomplete = true;
|
3003
|
-
}
|
3004
|
-
}
|
3005
3022
|
}
|
3006
3023
|
// Detect, report, and fill in missing type arguments if appropriate.
|
3007
3024
|
type = reportMissingTypeArguments(node, type, flags);
|
@@ -3139,7 +3156,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3139
3156
|
}
|
3140
3157
|
return getFlowTypeOfReference(node, innerScopeNode, {
|
3141
3158
|
targetSymbolId: symbolWithScope.symbol.id,
|
3142
|
-
typeAtStart,
|
3159
|
+
typeAtStart: { type: typeAtStart },
|
3143
3160
|
});
|
3144
3161
|
}
|
3145
3162
|
}
|
@@ -3285,11 +3302,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3285
3302
|
const defaultTypeArgs = [];
|
3286
3303
|
const typeVarContext = new typeVarContext_1.TypeVarContext(type.typeAliasInfo.typeVarScopeId);
|
3287
3304
|
type.typeAliasInfo.typeParameters.forEach((param) => {
|
3288
|
-
if (!param.details.
|
3305
|
+
if (!param.details.isDefaultExplicit) {
|
3289
3306
|
reportMissingTypeArguments = true;
|
3290
3307
|
}
|
3291
3308
|
let defaultType;
|
3292
|
-
if (param.details.
|
3309
|
+
if (param.details.isDefaultExplicit || param.details.isParamSpec) {
|
3293
3310
|
defaultType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
|
3294
3311
|
}
|
3295
3312
|
else if (param.details.isVariadic && tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
@@ -3466,8 +3483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3466
3483
|
// See if we can refine the type based on code flow analysis.
|
3467
3484
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
3468
3485
|
targetSymbolId: symbol_1.indeterminateSymbolId,
|
3469
|
-
typeAtStart,
|
3470
|
-
isTypeAtStartIncomplete,
|
3486
|
+
typeAtStart: { type: typeAtStart, isIncomplete: isTypeAtStartIncomplete },
|
3471
3487
|
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
3472
3488
|
});
|
3473
3489
|
if (codeFlowTypeResult.type) {
|
@@ -4384,7 +4400,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4384
4400
|
// known to have symmetric __getitem__ and __setitem__ methods (i.e. the value
|
4385
4401
|
// passed to __setitem__ is the same type as the value returned by __getitem__).
|
4386
4402
|
let baseTypeSupportsIndexNarrowing = !(0, types_1.isAny)(baseTypeResult.type);
|
4387
|
-
mapSubtypesExpandTypeVars(baseTypeResult.type, /*
|
4403
|
+
mapSubtypesExpandTypeVars(baseTypeResult.type, /* options */ undefined, (subtype) => {
|
4388
4404
|
if (!(0, types_1.isClassInstance)(subtype) ||
|
4389
4405
|
!(types_1.ClassType.isBuiltIn(subtype) || types_1.ClassType.isTypedDictClass(subtype))) {
|
4390
4406
|
baseTypeSupportsIndexNarrowing = false;
|
@@ -4397,8 +4413,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4397
4413
|
// See if we can refine the type based on code flow analysis.
|
4398
4414
|
const codeFlowTypeResult = getFlowTypeOfReference(node, /* startNode */ undefined, {
|
4399
4415
|
targetSymbolId: symbol_1.indeterminateSymbolId,
|
4400
|
-
typeAtStart:
|
4401
|
-
|
4416
|
+
typeAtStart: {
|
4417
|
+
type: indexTypeResult.type,
|
4418
|
+
isIncomplete: !!baseTypeResult.isIncomplete || !!indexTypeResult.isIncomplete,
|
4419
|
+
},
|
4402
4420
|
skipConditionalNarrowing: (flags & 256 /* EvaluatorFlags.ExpectingTypeAnnotation */) !== 0,
|
4403
4421
|
});
|
4404
4422
|
if (codeFlowTypeResult.type) {
|
@@ -4456,8 +4474,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4456
4474
|
// param somewhere in the list?
|
4457
4475
|
if (variadicIndex >= 0) {
|
4458
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
|
+
}
|
4459
4488
|
if (variadicIndex < typeArgs.length) {
|
4460
|
-
|
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);
|
4461
4499
|
// If the type args consist of a lone variadic type variable, don't wrap it in a tuple.
|
4462
4500
|
if (variadicTypeResults.length === 1 && (0, types_1.isVariadicTypeVar)(variadicTypeResults[0].type)) {
|
4463
4501
|
validateVariadicTypeVarIsUnpacked(variadicTypeResults[0].type, variadicTypeResults[0].node);
|
@@ -4488,11 +4526,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4488
4526
|
typeArgs = [
|
4489
4527
|
...typeArgs.slice(0, variadicIndex),
|
4490
4528
|
{ node: typeArgs[variadicIndex].node, type: tupleObject },
|
4491
|
-
...typeArgs.slice(
|
4529
|
+
...typeArgs.slice(variadicEndIndex, typeArgs.length),
|
4492
4530
|
];
|
4493
4531
|
}
|
4494
4532
|
}
|
4495
|
-
else if (!variadicTypeVar.details.
|
4533
|
+
else if (!variadicTypeVar.details.isDefaultExplicit) {
|
4496
4534
|
// Add an empty tuple that maps to the TypeVarTuple type parameter.
|
4497
4535
|
typeArgs.push({
|
4498
4536
|
node: errorNode,
|
@@ -4547,7 +4585,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4547
4585
|
}
|
4548
4586
|
}
|
4549
4587
|
let minTypeArgCount = typeParameters.length;
|
4550
|
-
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.
|
4588
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.isDefaultExplicit);
|
4551
4589
|
if (firstDefaultParamIndex >= 0) {
|
4552
4590
|
minTypeArgCount = firstDefaultParamIndex;
|
4553
4591
|
}
|
@@ -4641,7 +4679,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4641
4679
|
if (index < typeArgs.length) {
|
4642
4680
|
typeArgType = (0, typeUtils_1.convertToInstance)(typeArgs[index].type);
|
4643
4681
|
}
|
4644
|
-
else if (param.details.
|
4682
|
+
else if (param.details.isDefaultExplicit) {
|
4645
4683
|
typeArgType = (0, typeUtils_1.applySolvedTypeVars)(param, typeVarContext, { unknownIfNotFound: true });
|
4646
4684
|
}
|
4647
4685
|
else {
|
@@ -4713,7 +4751,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4713
4751
|
let isNotRequired = false;
|
4714
4752
|
let isReadOnly = false;
|
4715
4753
|
const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
|
4716
|
-
/*
|
4754
|
+
/* options */ undefined, (concreteSubtype, unexpandedSubtype) => {
|
4717
4755
|
var _a;
|
4718
4756
|
const selfType = (0, types_1.isTypeVar)(unexpandedSubtype) ? unexpandedSubtype : undefined;
|
4719
4757
|
if ((0, types_1.isAnyOrUnknown)(concreteSubtype)) {
|
@@ -6433,8 +6471,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6433
6471
|
}), exprNode);
|
6434
6472
|
return { returnType: types_1.UnknownType.create(), argumentErrors: true, overloadsUsedForCall };
|
6435
6473
|
}
|
6436
|
-
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type,
|
6437
|
-
/* conditionFilter */ undefined, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
|
6474
|
+
let returnType = mapSubtypesExpandTypeVars(callTypeResult.type, { sortSubtypes: true }, (expandedSubtype, unexpandedSubtype, isLastIteration) => {
|
6438
6475
|
return useSpeculativeMode(isLastIteration ? undefined : errorNode, () => {
|
6439
6476
|
const callResult = validateCallArgumentsForSubtype(errorNode, argList, expandedSubtype, unexpandedSubtype, !!callTypeResult.isIncomplete, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6440
6477
|
if (callResult.argumentErrors) {
|
@@ -6451,8 +6488,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6451
6488
|
}, {
|
6452
6489
|
allowDiagnostics: true,
|
6453
6490
|
});
|
6454
|
-
}
|
6455
|
-
/* sortSubtypes */ true);
|
6491
|
+
});
|
6456
6492
|
// If we ended up with a "Never" type because all code paths returned
|
6457
6493
|
// undefined due to argument errors, transform the result into an Unknown
|
6458
6494
|
// to avoid subsequent false positives.
|
@@ -6704,12 +6740,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6704
6740
|
if (expandedCallType.details.name === 'type' && argList.length === 1) {
|
6705
6741
|
const argType = getTypeOfArgument(argList[0]).type;
|
6706
6742
|
const returnType = (0, typeUtils_1.mapSubtypes)(argType, (subtype) => {
|
6743
|
+
var _a;
|
6744
|
+
if ((0, types_1.isInstantiableClass)(subtype)) {
|
6745
|
+
return (_a = subtype.details.effectiveMetaclass) !== null && _a !== void 0 ? _a : types_1.AnyType.create();
|
6746
|
+
}
|
6707
6747
|
if ((0, types_1.isClassInstance)(subtype) ||
|
6708
6748
|
((0, types_1.isTypeVar)(subtype) && types_1.TypeBase.isInstance(subtype)) ||
|
6709
6749
|
(0, typeUtils_1.isNoneInstance)(subtype)) {
|
6710
6750
|
return (0, typeUtils_1.convertToInstantiable)(stripLiteralValue(subtype));
|
6711
6751
|
}
|
6712
|
-
|
6752
|
+
if ((0, types_1.isFunction)(subtype) && types_1.TypeBase.isInstance(subtype)) {
|
6713
6753
|
return types_1.FunctionType.cloneAsInstantiable(subtype);
|
6714
6754
|
}
|
6715
6755
|
return types_1.AnyType.create();
|
@@ -8411,7 +8451,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8411
8451
|
// if appropriate. This doesn't properly handle non-top-level constrained
|
8412
8452
|
// type variables.
|
8413
8453
|
if (options.conditionFilter) {
|
8414
|
-
argType = mapSubtypesExpandTypeVars(argType, options.conditionFilter, (expandedSubtype) => {
|
8454
|
+
argType = mapSubtypesExpandTypeVars(argType, { conditionFilter: options.conditionFilter }, (expandedSubtype) => {
|
8415
8455
|
return expandedSubtype;
|
8416
8456
|
});
|
8417
8457
|
}
|
@@ -8653,6 +8693,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8653
8693
|
allowTypeVarsWithoutScopeId: true,
|
8654
8694
|
}).type;
|
8655
8695
|
typeVar.details.defaultType = (0, typeUtils_1.convertToInstance)(argType);
|
8696
|
+
typeVar.details.isDefaultExplicit = true;
|
8656
8697
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8657
8698
|
if (!fileInfo.isStubFile &&
|
8658
8699
|
fileInfo.executionEnvironment.pythonVersion < pythonVersion_1.PythonVersion.V3_13 &&
|
@@ -8686,23 +8727,41 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8686
8727
|
}
|
8687
8728
|
// If a default is provided, make sure it is compatible with the bound
|
8688
8729
|
// or constraint.
|
8689
|
-
if (typeVar.details.
|
8690
|
-
|
8691
|
-
|
8692
|
-
|
8693
|
-
|
8694
|
-
|
8695
|
-
|
8696
|
-
|
8697
|
-
|
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);
|
8698
8744
|
}
|
8699
|
-
|
8700
|
-
|
8701
|
-
|
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
|
+
}
|
8702
8756
|
}
|
8703
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
|
+
}
|
8704
8764
|
}
|
8705
|
-
return typeVar;
|
8706
8765
|
}
|
8707
8766
|
function createTypeVarTupleType(errorNode, classType, argList) {
|
8708
8767
|
var _a, _b;
|
@@ -8720,6 +8779,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8720
8779
|
}
|
8721
8780
|
const typeVar = types_1.TypeBase.cloneAsSpecialForm(types_1.TypeVarType.createInstantiable(typeVarName, /* isParamSpec */ false), types_1.ClassType.cloneAsInstance(classType));
|
8722
8781
|
typeVar.details.isVariadic = true;
|
8782
|
+
typeVar.details.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
8723
8783
|
// Parse the remaining parameters.
|
8724
8784
|
for (let i = 1; i < argList.length; i++) {
|
8725
8785
|
const paramNameNode = argList[i].name;
|
@@ -8728,7 +8788,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8728
8788
|
if (paramName === 'default') {
|
8729
8789
|
const expr = argList[i].valueExpression;
|
8730
8790
|
if (expr) {
|
8731
|
-
|
8791
|
+
const defaultType = getTypeVarTupleDefaultType(expr);
|
8792
|
+
if (defaultType) {
|
8793
|
+
typeVar.details.defaultType = defaultType;
|
8794
|
+
typeVar.details.isDefaultExplicit = true;
|
8795
|
+
}
|
8732
8796
|
}
|
8733
8797
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8734
8798
|
if (!fileInfo.isStubFile &&
|
@@ -8774,6 +8838,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8774
8838
|
addError(localize_1.LocMessage.paramSpecFirstArg(), firstArg.valueExpression || errorNode);
|
8775
8839
|
}
|
8776
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)();
|
8777
8842
|
// Parse the remaining parameters.
|
8778
8843
|
for (let i = 1; i < argList.length; i++) {
|
8779
8844
|
const paramNameNode = argList[i].name;
|
@@ -8782,7 +8847,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8782
8847
|
if (paramName === 'default') {
|
8783
8848
|
const expr = argList[i].valueExpression;
|
8784
8849
|
if (expr) {
|
8785
|
-
|
8850
|
+
const defaultType = getParamSpecDefaultType(expr);
|
8851
|
+
if (defaultType) {
|
8852
|
+
paramSpec.details.defaultType = defaultType;
|
8853
|
+
paramSpec.details.isDefaultExplicit = true;
|
8854
|
+
}
|
8786
8855
|
}
|
8787
8856
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
8788
8857
|
if (!fileInfo.isStubFile &&
|
@@ -9574,8 +9643,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9574
9643
|
verifySetEntryOrDictKeyIsHashable(entry, entryTypeResult.type, /* isDictKey */ false);
|
9575
9644
|
}
|
9576
9645
|
});
|
9577
|
-
|
9578
|
-
|
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
|
+
}
|
9579
9653
|
const specializedEntryType = inferTypeArgFromExpectedEntryType((0, typeUtils_1.makeInferenceContext)(expectedEntryType), entryTypes, !isTypeInvariant);
|
9580
9654
|
if (!specializedEntryType) {
|
9581
9655
|
return { type: types_1.UnknownType.create(), isIncomplete, typeErrors: true, expectedTypeDiagAddendum };
|
@@ -9616,7 +9690,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9616
9690
|
let entryTypes = [];
|
9617
9691
|
node.entries.forEach((entry, index) => {
|
9618
9692
|
let entryTypeResult;
|
9619
|
-
if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */) {
|
9693
|
+
if (entry.nodeType === 32 /* ParseNodeType.ListComprehension */ && !entry.isGenerator) {
|
9620
9694
|
entryTypeResult = getElementTypeFromListComprehension(entry);
|
9621
9695
|
}
|
9622
9696
|
else {
|
@@ -9676,7 +9750,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9676
9750
|
const diag = new diagnostic_1.DiagnosticAddendum();
|
9677
9751
|
diag.addMessage(localize_1.LocAddendum.unhashableType().format({ type: printType(type) }));
|
9678
9752
|
const message = isDictKey ? localize_1.LocMessage.unhashableDictKey() : localize_1.LocMessage.unhashableSetEntry();
|
9679
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.
|
9753
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportUnhashable, message + diag.getString(), entry);
|
9680
9754
|
}
|
9681
9755
|
}
|
9682
9756
|
function inferTypeArgFromExpectedEntryType(inferenceContext, entryTypes, isNarrowable) {
|
@@ -10894,6 +10968,18 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10894
10968
|
}
|
10895
10969
|
return (0, typeUtils_1.convertToInstance)(typeVar);
|
10896
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
|
+
}
|
10897
10983
|
const typeAliasScopeId = ParseTreeUtils.getScopeIdForNode(name);
|
10898
10984
|
// Validate the default types for all type parameters.
|
10899
10985
|
typeParameters.forEach((typeParam, index) => {
|
@@ -11302,6 +11388,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11302
11388
|
}
|
11303
11389
|
aliasType = transformTypeForTypeAlias(aliasType, nameNode, nameNode, isPep695Syntax,
|
11304
11390
|
/* isPep695TypeVarType */ true, typeParameters, typeParamNodes);
|
11391
|
+
// See if the type alias relies on itself in a way that cannot be resolved.
|
11305
11392
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
11306
11393
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeAliasIsRecursiveDirect().format({
|
11307
11394
|
name: nameNode.value,
|
@@ -11651,12 +11738,23 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11651
11738
|
classType.details.requiresVarianceInference = true;
|
11652
11739
|
}
|
11653
11740
|
// Make sure there's at most one variadic type parameter.
|
11654
|
-
const variadics =
|
11741
|
+
const variadics = typeParameters.filter((param) => (0, types_1.isVariadicTypeVar)(param));
|
11655
11742
|
if (variadics.length > 1) {
|
11656
|
-
|
11743
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.variadicTypeParamTooManyClass().format({
|
11657
11744
|
names: variadics.map((v) => `"${v.details.name}"`).join(', '),
|
11658
11745
|
}), node.name, textRange_1.TextRange.combine(node.arguments) || node.name);
|
11659
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
|
+
}
|
11660
11758
|
// Validate the default types for all type parameters.
|
11661
11759
|
classType.details.typeParameters.forEach((typeParam, index) => {
|
11662
11760
|
var _a;
|
@@ -11668,7 +11766,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11668
11766
|
validateTypeParameterDefault(bestErrorNode, typeParam, classType.details.typeParameters.slice(0, index), classType.details.typeVarScopeId);
|
11669
11767
|
});
|
11670
11768
|
if (!(0, typeUtils_1.computeMroLinearization)(classType)) {
|
11671
|
-
|
11769
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.methodOrdering(), node.name);
|
11672
11770
|
}
|
11673
11771
|
// The scope for this class becomes the "fields" for the corresponding type.
|
11674
11772
|
const innerScope = ScopeUtils.getScopeForNode(node.suite);
|
@@ -11884,10 +11982,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11884
11982
|
// parameters and updates the scope of the type parameter referred to in the
|
11885
11983
|
// default type expression.
|
11886
11984
|
function validateTypeParameterDefault(errorNode, typeParam, otherLiveTypeParams, scopeId) {
|
11887
|
-
if (!typeParam.details.
|
11985
|
+
if (!typeParam.details.isDefaultExplicit &&
|
11888
11986
|
!typeParam.details.isSynthesized &&
|
11889
11987
|
!typeParam.details.isSynthesizedSelf) {
|
11890
|
-
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.
|
11988
|
+
const typeVarWithDefault = otherLiveTypeParams.find((param) => param.details.isDefaultExplicit && param.scopeId === scopeId);
|
11891
11989
|
if (typeVarWithDefault) {
|
11892
11990
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarWithoutDefault().format({
|
11893
11991
|
name: typeParam.details.name,
|
@@ -13878,12 +13976,30 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13878
13976
|
}
|
13879
13977
|
return undefined;
|
13880
13978
|
}
|
13881
|
-
function getCodeFlowAnalyzerForNode(nodeId) {
|
13882
|
-
let
|
13883
|
-
if (
|
13884
|
-
|
13885
|
-
|
13886
|
-
|
13979
|
+
function getCodeFlowAnalyzerForNode(nodeId, typeAtStart) {
|
13980
|
+
let entries = codeFlowAnalyzerCache.get(nodeId);
|
13981
|
+
if (entries) {
|
13982
|
+
const cachedEntry = entries.find((entry) => {
|
13983
|
+
if (!typeAtStart || !entry.typeAtStart) {
|
13984
|
+
return !typeAtStart && !entry.typeAtStart;
|
13985
|
+
}
|
13986
|
+
if (!typeAtStart.isIncomplete !== !entry.typeAtStart.isIncomplete) {
|
13987
|
+
return false;
|
13988
|
+
}
|
13989
|
+
return (0, types_1.isTypeSame)(typeAtStart.type, entry.typeAtStart.type);
|
13990
|
+
});
|
13991
|
+
if (cachedEntry) {
|
13992
|
+
return cachedEntry.codeFlowAnalyzer;
|
13993
|
+
}
|
13994
|
+
}
|
13995
|
+
// Allocate a new code flow analyzer.
|
13996
|
+
const analyzer = codeFlowEngine.createCodeFlowAnalyzer(typeAtStart);
|
13997
|
+
if (entries) {
|
13998
|
+
entries.push({ typeAtStart, codeFlowAnalyzer: analyzer });
|
13999
|
+
}
|
14000
|
+
else {
|
14001
|
+
entries = [{ typeAtStart, codeFlowAnalyzer: analyzer }];
|
14002
|
+
codeFlowAnalyzerCache.set(nodeId, entries);
|
13887
14003
|
}
|
13888
14004
|
return analyzer;
|
13889
14005
|
}
|
@@ -13916,7 +14032,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13916
14032
|
analyzer = getCodeFlowAnalyzerForReturnTypeInferenceContext();
|
13917
14033
|
}
|
13918
14034
|
else {
|
13919
|
-
analyzer = getCodeFlowAnalyzerForNode(executionNode.id);
|
14035
|
+
analyzer = getCodeFlowAnalyzerForNode(executionNode.id, options === null || options === void 0 ? void 0 : options.typeAtStart);
|
13920
14036
|
}
|
13921
14037
|
const flowNode = AnalyzerNodeInfo.getFlowNode(startNode !== null && startNode !== void 0 ? startNode : reference);
|
13922
14038
|
if (flowNode === undefined) {
|
@@ -14084,7 +14200,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14084
14200
|
const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
14085
14201
|
if (typeArgs) {
|
14086
14202
|
let minTypeArgCount = typeParameters.length;
|
14087
|
-
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.
|
14203
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.isDefaultExplicit);
|
14088
14204
|
if (firstDefaultParamIndex >= 0) {
|
14089
14205
|
minTypeArgCount = firstDefaultParamIndex;
|
14090
14206
|
}
|
@@ -14939,34 +15055,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14939
15055
|
}
|
14940
15056
|
}
|
14941
15057
|
}
|
14942
|
-
if (node.
|
14943
|
-
|
14944
|
-
|
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;
|
15063
|
+
}
|
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;
|
14945
15073
|
}
|
14946
|
-
else
|
14947
|
-
typeVar.details.defaultType =
|
15074
|
+
else {
|
15075
|
+
typeVar.details.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
15076
|
+
}
|
15077
|
+
}
|
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;
|
14948
15085
|
}
|
14949
15086
|
else {
|
14950
|
-
typeVar.details.defaultType =
|
15087
|
+
typeVar.details.defaultType = types_1.UnknownType.create();
|
14951
15088
|
}
|
14952
15089
|
}
|
14953
15090
|
// If a default is provided, make sure it is compatible with the bound
|
14954
15091
|
// or constraint.
|
14955
|
-
if (typeVar.details.
|
14956
|
-
|
14957
|
-
const concreteDefaultType = (0, typeUtils_1.applySolvedTypeVars)(typeVar.details.defaultType, typeVarContext, {
|
14958
|
-
unknownIfNotFound: true,
|
14959
|
-
});
|
14960
|
-
if (typeVar.details.boundType) {
|
14961
|
-
if (!assignType(typeVar.details.boundType, concreteDefaultType)) {
|
14962
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultBoundMismatch(), node.defaultExpression);
|
14963
|
-
}
|
14964
|
-
}
|
14965
|
-
else if (typeVar.details.constraints.length > 0) {
|
14966
|
-
if (!typeVar.details.constraints.some((constraint) => (0, types_1.isTypeSame)(constraint, concreteDefaultType))) {
|
14967
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), node.defaultExpression);
|
14968
|
-
}
|
14969
|
-
}
|
15092
|
+
if (typeVar.details.isDefaultExplicit && node.defaultExpression) {
|
15093
|
+
verifyTypeVarDefaultIsCompatible(typeVar, node.defaultExpression);
|
14970
15094
|
}
|
14971
15095
|
// Associate the type variable with the owning scope.
|
14972
15096
|
const scopeNode = ParseTreeUtils.getTypeVarScopeNode(node);
|
@@ -15328,7 +15452,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15328
15452
|
const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
15329
15453
|
allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
|
15330
15454
|
})) !== null && _a !== void 0 ? _a : decl;
|
15331
|
-
if (!isPossibleTypeAliasDeclaration(resolvedDecl)) {
|
15455
|
+
if (!isPossibleTypeAliasDeclaration(resolvedDecl) && !isExplicitTypeAliasDeclaration(resolvedDecl)) {
|
15332
15456
|
includesIllegalTypeAliasDecl = true;
|
15333
15457
|
}
|
15334
15458
|
if (resolvedDecl.type === 1 /* DeclarationType.Variable */) {
|
@@ -15725,7 +15849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15725
15849
|
const prevTypeCache = returnTypeInferenceTypeCache;
|
15726
15850
|
returnTypeInferenceContextStack.push({
|
15727
15851
|
functionNode,
|
15728
|
-
codeFlowAnalyzer: codeFlowEngine.createCodeFlowAnalyzer(),
|
15852
|
+
codeFlowAnalyzer: codeFlowEngine.createCodeFlowAnalyzer(/* typeAtStart */ undefined),
|
15729
15853
|
});
|
15730
15854
|
try {
|
15731
15855
|
returnTypeInferenceTypeCache = new Map();
|
@@ -17828,7 +17952,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17828
17952
|
if (srcStartOfNamed >= 0) {
|
17829
17953
|
srcParamDetails.params.forEach((srcParamInfo, index) => {
|
17830
17954
|
if (index >= srcStartOfNamed) {
|
17831
|
-
if (srcParamInfo.param.name &&
|
17955
|
+
if (srcParamInfo.param.name &&
|
17956
|
+
srcParamInfo.param.category === 0 /* ParameterCategory.Simple */ &&
|
17957
|
+
srcParamInfo.source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
17832
17958
|
const destParamInfo = destParamMap.get(srcParamInfo.param.name);
|
17833
17959
|
const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
17834
17960
|
const srcParamType = srcParamInfo.type;
|
@@ -18443,6 +18569,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18443
18569
|
}
|
18444
18570
|
}
|
18445
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
|
+
}
|
18446
18587
|
// Check for a *args match.
|
18447
18588
|
if (baseParamDetails.argsIndex !== undefined) {
|
18448
18589
|
if (overrideParamDetails.argsIndex === undefined) {
|