@zzzen/pyright-internal 1.2.0-dev.20240310 → 1.2.0-dev.20240324
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/analyzerFileInfo.js +1 -1
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +44 -51
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/deprecatedSymbols.js +40 -40
- package/dist/analyzer/deprecatedSymbols.js.map +1 -1
- package/dist/analyzer/importResolver.js +6 -6
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/operations.js +9 -9
- 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/properties.js +2 -8
- package/dist/analyzer/properties.js.map +1 -1
- package/dist/analyzer/pythonPathUtils.js +1 -2
- package/dist/analyzer/pythonPathUtils.js.map +1 -1
- package/dist/analyzer/service.js +1 -1
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/staticExpressions.js +52 -30
- package/dist/analyzer/staticExpressions.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +216 -105
- 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 +34 -15
- 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 +21 -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 +9 -4
- 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/fullAccessHost.js +7 -3
- package/dist/common/fullAccessHost.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/common/pythonVersion.d.ts +36 -20
- package/dist/common/pythonVersion.js +160 -54
- package/dist/common/pythonVersion.js.map +1 -1
- package/dist/languageService/completionProvider.js +2 -2
- 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 +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 +25 -22
- 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/parser/unicode.js +3456 -2853
- package/dist/parser/unicode.js.map +1 -1
- package/dist/pyright.js +1 -1
- package/dist/pyright.js.map +1 -1
- package/dist/tests/checker.test.js +11 -11
- package/dist/tests/checker.test.js.map +1 -1
- package/dist/tests/config.test.js +7 -7
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tests/fourSlashParser.test.js +2 -2
- package/dist/tests/fourSlashParser.test.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/languageServer.test.js +1 -1
- package/dist/tests/languageServer.test.js.map +1 -1
- package/dist/tests/lsp/customLsp.d.ts +1 -1
- package/dist/tests/lsp/languageServer.js +2 -1
- package/dist/tests/lsp/languageServer.js.map +1 -1
- package/dist/tests/lsp/languageServerTestUtils.js +6 -6
- package/dist/tests/lsp/languageServerTestUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +16 -12
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +3 -3
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +57 -57
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +22 -22
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +35 -33
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/package.json +1 -1
@@ -86,21 +86,21 @@ const types_1 = require("./types");
|
|
86
86
|
// It lists the first version of Python where subscripting is
|
87
87
|
// allowed.
|
88
88
|
const nonSubscriptableBuiltinTypes = new Map([
|
89
|
-
['asyncio.futures.Future', pythonVersion_1.
|
90
|
-
['asyncio.tasks.Task', pythonVersion_1.
|
91
|
-
['builtins.dict', pythonVersion_1.
|
92
|
-
['builtins.frozenset', pythonVersion_1.
|
93
|
-
['builtins.list', pythonVersion_1.
|
94
|
-
['builtins._PathLike', pythonVersion_1.
|
95
|
-
['builtins.set', pythonVersion_1.
|
96
|
-
['builtins.tuple', pythonVersion_1.
|
97
|
-
['collections.ChainMap', pythonVersion_1.
|
98
|
-
['collections.Counter', pythonVersion_1.
|
99
|
-
['collections.defaultdict', pythonVersion_1.
|
100
|
-
['collections.DefaultDict', pythonVersion_1.
|
101
|
-
['collections.deque', pythonVersion_1.
|
102
|
-
['collections.OrderedDict', pythonVersion_1.
|
103
|
-
['queue.Queue', pythonVersion_1.
|
89
|
+
['asyncio.futures.Future', pythonVersion_1.pythonVersion3_9],
|
90
|
+
['asyncio.tasks.Task', pythonVersion_1.pythonVersion3_9],
|
91
|
+
['builtins.dict', pythonVersion_1.pythonVersion3_9],
|
92
|
+
['builtins.frozenset', pythonVersion_1.pythonVersion3_9],
|
93
|
+
['builtins.list', pythonVersion_1.pythonVersion3_9],
|
94
|
+
['builtins._PathLike', pythonVersion_1.pythonVersion3_9],
|
95
|
+
['builtins.set', pythonVersion_1.pythonVersion3_9],
|
96
|
+
['builtins.tuple', pythonVersion_1.pythonVersion3_9],
|
97
|
+
['collections.ChainMap', pythonVersion_1.pythonVersion3_9],
|
98
|
+
['collections.Counter', pythonVersion_1.pythonVersion3_9],
|
99
|
+
['collections.defaultdict', pythonVersion_1.pythonVersion3_9],
|
100
|
+
['collections.DefaultDict', pythonVersion_1.pythonVersion3_9],
|
101
|
+
['collections.deque', pythonVersion_1.pythonVersion3_9],
|
102
|
+
['collections.OrderedDict', pythonVersion_1.pythonVersion3_9],
|
103
|
+
['queue.Queue', pythonVersion_1.pythonVersion3_9],
|
104
104
|
]);
|
105
105
|
// Some types that do not inherit from others are still considered
|
106
106
|
// "compatible" based on the Python spec. These are sometimes referred
|
@@ -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)) {
|
@@ -3648,7 +3662,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3648
3662
|
if (usage.method === 'get') {
|
3649
3663
|
const getAttrSymbol = types_1.ModuleType.getField(baseType, '__getattr__');
|
3650
3664
|
if (getAttrSymbol) {
|
3651
|
-
const isModuleGetAttrSupported = fileInfo.executionEnvironment.pythonVersion
|
3665
|
+
const isModuleGetAttrSupported = fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_7) ||
|
3652
3666
|
getAttrSymbol.getDeclarations().some((decl) => decl.uri.hasExtension('.pyi'));
|
3653
3667
|
if (isModuleGetAttrSupported) {
|
3654
3668
|
const getAttrTypeResult = getEffectiveTypeOfSymbolForUsage(getAttrSymbol);
|
@@ -4371,7 +4385,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4371
4385
|
!baseTypeResult.type.aliasName) {
|
4372
4386
|
const minPythonVersion = nonSubscriptableBuiltinTypes.get(baseTypeResult.type.details.fullName);
|
4373
4387
|
if (minPythonVersion !== undefined &&
|
4374
|
-
fileInfo.executionEnvironment.pythonVersion
|
4388
|
+
fileInfo.executionEnvironment.pythonVersion.isLessThan(minPythonVersion) &&
|
4375
4389
|
!fileInfo.isStubFile) {
|
4376
4390
|
addError(localize_1.LocMessage.classNotRuntimeSubscriptable().format({
|
4377
4391
|
name: baseTypeResult.type.aliasName || baseTypeResult.type.details.name,
|
@@ -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,9 +8693,10 @@ 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
|
-
fileInfo.executionEnvironment.pythonVersion
|
8699
|
+
fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_13) &&
|
8667
8700
|
classType.details.moduleName !== 'typing_extensions') {
|
8668
8701
|
addError(localize_1.LocMessage.typeVarDefaultIllegal(), defaultValueNode);
|
8669
8702
|
}
|
@@ -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,11 +8788,15 @@ 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 &&
|
8743
|
-
fileInfo.executionEnvironment.pythonVersion
|
8799
|
+
fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_13) &&
|
8744
8800
|
classType.details.moduleName !== 'typing_extensions') {
|
8745
8801
|
addError(localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8746
8802
|
}
|
@@ -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,11 +8847,15 @@ 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 &&
|
8797
|
-
fileInfo.executionEnvironment.pythonVersion
|
8858
|
+
fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_13) &&
|
8798
8859
|
classType.details.moduleName !== 'typing_extensions') {
|
8799
8860
|
addError(localize_1.LocMessage.typeVarDefaultIllegal(), expr);
|
8800
8861
|
}
|
@@ -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,12 +9750,12 @@ 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) {
|
9691
9757
|
// If the expected type is Any, the resulting type becomes Any.
|
9692
|
-
if ((0, types_1.
|
9758
|
+
if ((0, types_1.isAny)(inferenceContext.expectedType)) {
|
9693
9759
|
return inferenceContext.expectedType;
|
9694
9760
|
}
|
9695
9761
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(inferenceContext.expectedType));
|
@@ -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,
|
@@ -11473,7 +11552,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11473
11552
|
if (types_1.ClassType.isBuiltIn(argType, 'Protocol')) {
|
11474
11553
|
if (!fileInfo.isStubFile &&
|
11475
11554
|
!types_1.ClassType.isTypingExtensionClass(argType) &&
|
11476
|
-
fileInfo.executionEnvironment.pythonVersion
|
11555
|
+
fileInfo.executionEnvironment.pythonVersion.isLessThan(pythonVersion_1.pythonVersion3_7)) {
|
11477
11556
|
addError(localize_1.LocMessage.protocolIllegal(), arg.valueExpression);
|
11478
11557
|
}
|
11479
11558
|
classType.details.flags |= 16384 /* ClassTypeFlags.ProtocolClass */;
|
@@ -11483,7 +11562,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11483
11562
|
}
|
11484
11563
|
// If the class directly derives from NamedTuple (in Python 3.6 or
|
11485
11564
|
// newer), it's considered a (read-only) dataclass.
|
11486
|
-
if (fileInfo.executionEnvironment.pythonVersion
|
11565
|
+
if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_6)) {
|
11487
11566
|
if (types_1.ClassType.isBuiltIn(argType, 'NamedTuple')) {
|
11488
11567
|
classType.details.flags |=
|
11489
11568
|
4 /* ClassTypeFlags.DataClass */ |
|
@@ -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,
|
@@ -12159,7 +12249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12159
12249
|
const paramInfo = paramListDetails.params[paramIndex];
|
12160
12250
|
const argParam = {
|
12161
12251
|
paramCategory: paramInfo.param.category,
|
12162
|
-
paramType:
|
12252
|
+
paramType: paramInfo.type,
|
12163
12253
|
requiresTypeVarMatching: false,
|
12164
12254
|
argument: arg,
|
12165
12255
|
errorNode: (_b = arg.valueExpression) !== null && _b !== void 0 ? _b : errorNode,
|
@@ -12651,17 +12741,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12651
12741
|
// Callable, these type variables are "rescoped" from the function to
|
12652
12742
|
// the Callable.
|
12653
12743
|
function rescopeTypeVarsForCallableReturnType(returnType, functionType, typeParametersSeen) {
|
12654
|
-
const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType);
|
12744
|
+
const typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType).filter((t) => t.scopeId === functionType.details.typeVarScopeId);
|
12655
12745
|
const rescopedTypeVars = [];
|
12656
12746
|
typeVarsInReturnType.forEach((typeVar) => {
|
12657
12747
|
if (types_1.TypeBase.isInstantiable(typeVar)) {
|
12658
12748
|
typeVar = types_1.TypeVarType.cloneAsInstance(typeVar);
|
12659
12749
|
}
|
12660
|
-
// If this type variable isn't scoped to this function, it is probably
|
12661
|
-
// associated with an outer scope.
|
12662
|
-
if (typeVar.scopeId !== functionType.details.typeVarScopeId) {
|
12663
|
-
return;
|
12664
|
-
}
|
12665
12750
|
// If this type variable was already seen in one or more input parameters,
|
12666
12751
|
// don't attempt to rescope it.
|
12667
12752
|
if (typeParametersSeen.some((tp) => (0, types_1.isTypeSame)((0, typeUtils_1.convertToInstance)(tp), typeVar))) {
|
@@ -13259,7 +13344,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13259
13344
|
reportError = true;
|
13260
13345
|
// Handle PEP 562 support for module-level __getattr__ function,
|
13261
13346
|
// introduced in Python 3.7.
|
13262
|
-
if (fileInfo.executionEnvironment.pythonVersion
|
13347
|
+
if (fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_7) ||
|
13348
|
+
fileInfo.isStubFile) {
|
13263
13349
|
const getAttrSymbol = importLookupInfo.symbolTable.get('__getattr__');
|
13264
13350
|
if (getAttrSymbol) {
|
13265
13351
|
const getAttrType = getEffectiveTypeOfSymbol(getAttrSymbol);
|
@@ -14065,7 +14151,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14065
14151
|
}
|
14066
14152
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(errorNode);
|
14067
14153
|
if (fileInfo.isStubFile ||
|
14068
|
-
fileInfo.executionEnvironment.pythonVersion
|
14154
|
+
fileInfo.executionEnvironment.pythonVersion.isGreaterOrEqualTo(pythonVersion_1.pythonVersion3_9) ||
|
14069
14155
|
(0, analyzerFileInfo_1.isAnnotationEvaluationPostponed)(AnalyzerNodeInfo.getFileInfo(errorNode)) ||
|
14070
14156
|
(flags & 4 /* EvaluatorFlags.AllowForwardReferences */) !== 0) {
|
14071
14157
|
// Handle "type" specially, since it needs to act like "Type"
|
@@ -14110,7 +14196,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14110
14196
|
const variadicTypeParamIndex = typeParameters.findIndex((param) => (0, types_1.isVariadicTypeVar)(param));
|
14111
14197
|
if (typeArgs) {
|
14112
14198
|
let minTypeArgCount = typeParameters.length;
|
14113
|
-
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.
|
14199
|
+
const firstDefaultParamIndex = typeParameters.findIndex((param) => !!param.details.isDefaultExplicit);
|
14114
14200
|
if (firstDefaultParamIndex >= 0) {
|
14115
14201
|
minTypeArgCount = firstDefaultParamIndex;
|
14116
14202
|
}
|
@@ -14965,35 +15051,43 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14965
15051
|
}
|
14966
15052
|
}
|
14967
15053
|
}
|
14968
|
-
if (node.
|
14969
|
-
|
14970
|
-
|
15054
|
+
if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.ParamSpec) {
|
15055
|
+
const defaultType = node.defaultExpression ? getParamSpecDefaultType(node.defaultExpression) : undefined;
|
15056
|
+
if (defaultType) {
|
15057
|
+
typeVar.details.defaultType = defaultType;
|
15058
|
+
typeVar.details.isDefaultExplicit = true;
|
14971
15059
|
}
|
14972
|
-
else
|
14973
|
-
typeVar.details.defaultType =
|
15060
|
+
else {
|
15061
|
+
typeVar.details.defaultType = (0, typeUtils_1.getUnknownTypeForParamSpec)();
|
15062
|
+
}
|
15063
|
+
}
|
15064
|
+
else if (node.typeParamCategory === parseNodes_1.TypeParameterCategory.TypeVarTuple) {
|
15065
|
+
const defaultType = node.defaultExpression ? getTypeVarTupleDefaultType(node.defaultExpression) : undefined;
|
15066
|
+
if (defaultType) {
|
15067
|
+
typeVar.details.defaultType = defaultType;
|
15068
|
+
typeVar.details.isDefaultExplicit = true;
|
14974
15069
|
}
|
14975
15070
|
else {
|
14976
|
-
typeVar.details.defaultType = (
|
15071
|
+
typeVar.details.defaultType = makeTupleObject([{ type: types_1.UnknownType.create(), isUnbounded: true }]);
|
14977
15072
|
}
|
14978
15073
|
}
|
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
|
-
}
|
15074
|
+
else {
|
15075
|
+
const defaultType = node.defaultExpression
|
15076
|
+
? (0, typeUtils_1.convertToInstance)(getTypeOfExpressionExpectingType(node.defaultExpression).type)
|
15077
|
+
: undefined;
|
15078
|
+
if (defaultType) {
|
15079
|
+
typeVar.details.defaultType = defaultType;
|
15080
|
+
typeVar.details.isDefaultExplicit = true;
|
14990
15081
|
}
|
14991
|
-
else
|
14992
|
-
|
14993
|
-
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typeVarDefaultConstraintMismatch(), node.defaultExpression);
|
14994
|
-
}
|
15082
|
+
else {
|
15083
|
+
typeVar.details.defaultType = types_1.UnknownType.create();
|
14995
15084
|
}
|
14996
15085
|
}
|
15086
|
+
// If a default is provided, make sure it is compatible with the bound
|
15087
|
+
// or constraint.
|
15088
|
+
if (typeVar.details.isDefaultExplicit && node.defaultExpression) {
|
15089
|
+
verifyTypeVarDefaultIsCompatible(typeVar, node.defaultExpression);
|
15090
|
+
}
|
14997
15091
|
// Associate the type variable with the owning scope.
|
14998
15092
|
const scopeNode = ParseTreeUtils.getTypeVarScopeNode(node);
|
14999
15093
|
if (scopeNode) {
|
@@ -15354,7 +15448,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15354
15448
|
const resolvedDecl = (_a = resolveAliasDeclaration(decl, /* resolveLocalNames */ true, {
|
15355
15449
|
allowExternallyHiddenAccess: AnalyzerNodeInfo.getFileInfo(decl.node).isStubFile,
|
15356
15450
|
})) !== null && _a !== void 0 ? _a : decl;
|
15357
|
-
if (!isPossibleTypeAliasDeclaration(resolvedDecl)) {
|
15451
|
+
if (!isPossibleTypeAliasDeclaration(resolvedDecl) && !isExplicitTypeAliasDeclaration(resolvedDecl)) {
|
15358
15452
|
includesIllegalTypeAliasDecl = true;
|
15359
15453
|
}
|
15360
15454
|
if (resolvedDecl.type === 1 /* DeclarationType.Variable */) {
|
@@ -17854,7 +17948,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17854
17948
|
if (srcStartOfNamed >= 0) {
|
17855
17949
|
srcParamDetails.params.forEach((srcParamInfo, index) => {
|
17856
17950
|
if (index >= srcStartOfNamed) {
|
17857
|
-
if (srcParamInfo.param.name &&
|
17951
|
+
if (srcParamInfo.param.name &&
|
17952
|
+
srcParamInfo.param.category === 0 /* ParameterCategory.Simple */ &&
|
17953
|
+
srcParamInfo.source !== parameterUtils_1.ParameterSource.PositionOnly) {
|
17858
17954
|
const destParamInfo = destParamMap.get(srcParamInfo.param.name);
|
17859
17955
|
const paramDiag = diag === null || diag === void 0 ? void 0 : diag.createAddendum();
|
17860
17956
|
const srcParamType = srcParamInfo.type;
|
@@ -18469,6 +18565,21 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
18469
18565
|
}
|
18470
18566
|
}
|
18471
18567
|
}
|
18568
|
+
// Check for positional (named) parameters in the base method that
|
18569
|
+
// do not exist in the override.
|
18570
|
+
if (enforceParamNames && overrideParamDetails.kwargsIndex === undefined) {
|
18571
|
+
for (let i = positionalParamCount; i < baseParamDetails.positionParamCount; i++) {
|
18572
|
+
const baseParam = baseParamDetails.params[i];
|
18573
|
+
if (baseParam.source === parameterUtils_1.ParameterSource.PositionOrKeyword &&
|
18574
|
+
baseParam.param.category === 0 /* ParameterCategory.Simple */) {
|
18575
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.LocAddendum.overrideParamNamePositionOnly().format({
|
18576
|
+
index: i + 1,
|
18577
|
+
baseName: baseParam.param.name || '*',
|
18578
|
+
}));
|
18579
|
+
canOverride = false;
|
18580
|
+
}
|
18581
|
+
}
|
18582
|
+
}
|
18472
18583
|
// Check for a *args match.
|
18473
18584
|
if (baseParamDetails.argsIndex !== undefined) {
|
18474
18585
|
if (overrideParamDetails.argsIndex === undefined) {
|