@zzzen/pyright-internal 1.2.0-dev.20230806 → 1.2.0-dev.20230820
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 +6 -5
- package/dist/analyzer/backgroundAnalysisProgram.js +6 -5
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.js +8 -2
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +79 -8
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +5 -5
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/constraintSolver.d.ts +1 -0
- package/dist/analyzer/constraintSolver.js +30 -23
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/dataClasses.js +242 -236
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/decorators.js +8 -8
- package/dist/analyzer/decorators.js.map +1 -1
- package/dist/analyzer/enums.js +12 -0
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.js +3 -1
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/namedTuples.js +6 -0
- package/dist/analyzer/namedTuples.js.map +1 -1
- package/dist/analyzer/operations.d.ts +1 -1
- package/dist/analyzer/operations.js +2 -2
- package/dist/analyzer/operations.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +4 -1
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +2 -1
- package/dist/analyzer/parameterUtils.js +15 -0
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/patternMatching.js +3 -3
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +4 -1
- package/dist/analyzer/program.js +8 -10
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +42 -20
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +3 -0
- package/dist/analyzer/service.js +37 -2
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +279 -141
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +6 -2
- package/dist/analyzer/typeEvaluatorTypes.js +10 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +9 -6
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +4 -1
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +47 -29
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/types.d.ts +3 -1
- package/dist/analyzer/types.js +3 -1
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysis.d.ts +2 -1
- package/dist/backgroundAnalysis.js +2 -2
- package/dist/backgroundAnalysis.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +3 -3
- package/dist/backgroundAnalysisBase.js +3 -3
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +7 -6
- package/dist/backgroundThreadBase.js +20 -6
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/common/console.js.map +1 -1
- package/dist/common/extensibility.d.ts +2 -18
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/fileSystem.d.ts +1 -1
- package/dist/common/pathUtils.d.ts +1 -0
- package/dist/common/pathUtils.js +19 -5
- package/dist/common/pathUtils.js.map +1 -1
- package/dist/common/realFileSystem.d.ts +1 -1
- package/dist/common/realFileSystem.js +12 -8
- package/dist/common/realFileSystem.js.map +1 -1
- package/dist/common/serviceProvider.d.ts +15 -0
- package/dist/common/serviceProvider.js +37 -0
- package/dist/common/serviceProvider.js.map +1 -0
- package/dist/common/serviceProviderExtensions.d.ts +16 -0
- package/dist/common/serviceProviderExtensions.js +27 -0
- package/dist/common/serviceProviderExtensions.js.map +1 -0
- package/dist/languageServerBase.d.ts +6 -5
- package/dist/languageServerBase.js +8 -6
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/navigationUtils.js +1 -1
- package/dist/languageService/navigationUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +25 -4
- package/dist/localization/localize.js +8 -2
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +4 -3
- package/dist/localization/package.nls.de.json +4 -3
- package/dist/localization/package.nls.en-us.json +17 -11
- package/dist/localization/package.nls.es.json +4 -3
- package/dist/localization/package.nls.fr.json +4 -3
- package/dist/localization/package.nls.it.json +4 -3
- package/dist/localization/package.nls.ja.json +4 -3
- package/dist/localization/package.nls.ko.json +4 -3
- package/dist/localization/package.nls.pl.json +4 -3
- package/dist/localization/package.nls.pt-br.json +4 -3
- package/dist/localization/package.nls.qps-ploc.json +3 -2
- package/dist/localization/package.nls.ru.json +4 -3
- package/dist/localization/package.nls.tr.json +4 -3
- package/dist/localization/package.nls.zh-cn.json +4 -3
- package/dist/localization/package.nls.zh-tw.json +3 -2
- package/dist/nodeMain.js +2 -1
- package/dist/nodeMain.js.map +1 -1
- package/dist/parser/parser.d.ts +1 -0
- package/dist/parser/parser.js +80 -20
- package/dist/parser/parser.js.map +1 -1
- package/dist/pyrightFileSystem.d.ts +3 -1
- package/dist/pyrightFileSystem.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.d.ts +1 -1
- package/dist/readonlyAugmentedFileSystem.js +2 -2
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/server.js +8 -2
- package/dist/server.js.map +1 -1
- package/dist/tests/harness/fourslash/runner.js +1 -1
- package/dist/tests/harness/fourslash/runner.js.map +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js +1 -1
- package/dist/tests/harness/fourslash/testLanguageService.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +6 -1
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/harness/vfs/filesystem.d.ts +2 -2
- package/dist/tests/harness/vfs/filesystem.js +1 -1
- package/dist/tests/harness/vfs/filesystem.js.map +1 -1
- package/dist/tests/service.test.js +65 -0
- package/dist/tests/service.test.js.map +1 -1
- package/dist/tests/testUtils.js +6 -1
- package/dist/tests/testUtils.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +4 -4
- package/dist/tests/typeEvaluator1.test.js.map +1 -1
- package/dist/tests/typeEvaluator2.test.js +9 -1
- package/dist/tests/typeEvaluator2.test.js.map +1 -1
- package/dist/tests/typeEvaluator3.test.js +7 -3
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +10 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +10 -2
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/zipfs.test.js +8 -5
- package/dist/tests/zipfs.test.js.map +1 -1
- package/package.json +1 -1
@@ -157,7 +157,7 @@ const maxRecursiveTypeAliasRecursionCount = 10;
|
|
157
157
|
// This switch enables a special debug mode that attempts to catch
|
158
158
|
// bugs due to inconsistent evaluation flags used when reading types
|
159
159
|
// from the type cache.
|
160
|
-
const verifyTypeCacheEvaluatorFlags =
|
160
|
+
const verifyTypeCacheEvaluatorFlags = true;
|
161
161
|
// This debugging option prints each expression and its evaluated type.
|
162
162
|
const printExpressionTypes = false;
|
163
163
|
// The following number is chosen somewhat arbitrarily. We need to cut
|
@@ -683,6 +683,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
683
683
|
}
|
684
684
|
return typeResult;
|
685
685
|
}
|
686
|
+
function reportInvalidUseOfPep695TypeAlias(type, node) {
|
687
|
+
var _a;
|
688
|
+
// PEP 695 type aliases cannot be used as instantiable classes.
|
689
|
+
if (((_a = type.typeAliasInfo) === null || _a === void 0 ? void 0 : _a.name) && type.typeAliasInfo.isPep695Syntax && types_1.TypeBase.isSpecialForm(type)) {
|
690
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasNotAllowed().format({ name: type.typeAliasInfo.name }), node);
|
691
|
+
return true;
|
692
|
+
}
|
693
|
+
return false;
|
694
|
+
}
|
686
695
|
function validateTypeIsInstantiable(typeResult, flags, node) {
|
687
696
|
var _a;
|
688
697
|
// If the type is incomplete, don't log any diagnostics yet.
|
@@ -971,9 +980,6 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
971
980
|
if (options === null || options === void 0 ? void 0 : options.associateTypeVarsWithScope) {
|
972
981
|
evaluatorFlags |= 8192 /* AssociateTypeVarsWithCurrentScope */;
|
973
982
|
}
|
974
|
-
else {
|
975
|
-
evaluatorFlags |= 4096 /* DisallowTypeVarsWithoutScopeId */;
|
976
|
-
}
|
977
983
|
if (options === null || options === void 0 ? void 0 : options.allowUnpackedTypedDict) {
|
978
984
|
evaluatorFlags |= 8388608 /* AllowUnpackedTypedDict */;
|
979
985
|
}
|
@@ -1451,7 +1457,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1451
1457
|
return getDeclaredTypeForExpression(expression.valueExpression, usage);
|
1452
1458
|
}
|
1453
1459
|
case 35 /* MemberAccess */: {
|
1454
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression,
|
1460
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.leftExpression, 16777218 /* MemberAccessBaseDefaults */).type);
|
1455
1461
|
let classMemberInfo;
|
1456
1462
|
if ((0, types_1.isClassInstance)(baseType)) {
|
1457
1463
|
classMemberInfo = (0, typeUtils_1.lookUpObjectMember)(baseType, expression.memberName.value, 16 /* DeclaredTypesOnly */);
|
@@ -1475,7 +1481,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1475
1481
|
break;
|
1476
1482
|
}
|
1477
1483
|
case 24 /* Index */: {
|
1478
|
-
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /*
|
1484
|
+
const baseType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(expression.baseExpression, 2 /* IndexBaseDefaults */).type);
|
1479
1485
|
if (baseType && (0, types_1.isClassInstance)(baseType)) {
|
1480
1486
|
const setItemMember = (0, typeUtils_1.lookUpClassMember)(baseType, '__setitem__');
|
1481
1487
|
if (setItemMember) {
|
@@ -2036,7 +2042,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2036
2042
|
writeTypeCache(nameNode, { type: destType, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
2037
2043
|
}
|
2038
2044
|
function assignTypeToMemberAccessNode(target, type, isTypeIncomplete, srcExpr, expectedTypeDiagAddendum) {
|
2039
|
-
const baseTypeResult = getTypeOfExpression(target.leftExpression,
|
2045
|
+
const baseTypeResult = getTypeOfExpression(target.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2040
2046
|
const baseType = makeTopLevelTypeVarsConcrete(baseTypeResult.type);
|
2041
2047
|
// Handle member accesses (e.g. self.x or cls.y).
|
2042
2048
|
if (target.leftExpression.nodeType === 38 /* Name */) {
|
@@ -2493,19 +2499,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2493
2499
|
// Is the source expression a TypeVar() call?
|
2494
2500
|
if ((0, types_1.isTypeVar)(type)) {
|
2495
2501
|
if (srcExpr && srcExpr.nodeType === 9 /* Call */) {
|
2496
|
-
const callType = getTypeOfExpression(srcExpr.leftExpression,
|
2502
|
+
const callType = getTypeOfExpression(srcExpr.leftExpression, 16777218 /* CallBaseDefaults */).type;
|
2497
2503
|
if ((0, types_1.isInstantiableClass)(callType) &&
|
2498
2504
|
(types_1.ClassType.isBuiltIn(callType, 'TypeVar') ||
|
2499
2505
|
types_1.ClassType.isBuiltIn(callType, 'TypeVarTuple') ||
|
2500
2506
|
types_1.ClassType.isBuiltIn(callType, 'ParamSpec'))) {
|
2501
|
-
|
2507
|
+
const typeVarTarget = target.nodeType === 54 /* TypeAnnotation */ ? target.valueExpression : target;
|
2508
|
+
if (typeVarTarget.nodeType !== 38 /* Name */ || typeVarTarget.value !== type.details.name) {
|
2502
2509
|
addError(type.details.isParamSpec
|
2503
2510
|
? localize_1.Localizer.Diagnostic.paramSpecAssignedName().format({
|
2504
2511
|
name: types_1.TypeVarType.getReadableName(type),
|
2505
2512
|
})
|
2506
2513
|
: localize_1.Localizer.Diagnostic.typeVarAssignedName().format({
|
2507
2514
|
name: types_1.TypeVarType.getReadableName(type),
|
2508
|
-
}),
|
2515
|
+
}), typeVarTarget);
|
2509
2516
|
}
|
2510
2517
|
}
|
2511
2518
|
}
|
@@ -2524,7 +2531,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2524
2531
|
break;
|
2525
2532
|
}
|
2526
2533
|
case 24 /* Index */: {
|
2527
|
-
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /*
|
2534
|
+
const baseTypeResult = getTypeOfExpression(target.baseExpression, 2 /* IndexBaseDefaults */);
|
2528
2535
|
getTypeOfIndexWithBaseType(target, baseTypeResult, {
|
2529
2536
|
method: 'set',
|
2530
2537
|
setType: { type, isIncomplete: isTypeIncomplete },
|
@@ -2561,8 +2568,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2561
2568
|
}
|
2562
2569
|
}
|
2563
2570
|
}
|
2564
|
-
assignTypeToExpression(target.valueExpression, type,
|
2565
|
-
/* isIncomplete */ false, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2571
|
+
assignTypeToExpression(target.valueExpression, type, isTypeIncomplete, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2566
2572
|
break;
|
2567
2573
|
}
|
2568
2574
|
case 56 /* Unpack */: {
|
@@ -2652,14 +2658,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2652
2658
|
break;
|
2653
2659
|
}
|
2654
2660
|
case 35 /* MemberAccess */: {
|
2655
|
-
const baseTypeResult = getTypeOfExpression(node.leftExpression,
|
2661
|
+
const baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* MemberAccessBaseDefaults */);
|
2656
2662
|
const memberType = getTypeOfMemberAccessWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2657
2663
|
writeTypeCache(node.memberName, { type: memberType.type }, 0 /* None */);
|
2658
2664
|
writeTypeCache(node, { type: memberType.type }, 0 /* None */);
|
2659
2665
|
break;
|
2660
2666
|
}
|
2661
2667
|
case 24 /* Index */: {
|
2662
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /*
|
2668
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, 2 /* IndexBaseDefaults */);
|
2663
2669
|
getTypeOfIndexWithBaseType(node, baseTypeResult, { method: 'del' }, 0 /* None */);
|
2664
2670
|
writeTypeCache(node, { type: types_1.UnboundType.create() }, 0 /* None */);
|
2665
2671
|
break;
|
@@ -2914,6 +2920,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2914
2920
|
}
|
2915
2921
|
}
|
2916
2922
|
}
|
2923
|
+
if ((flags & 16777216 /* DisallowPep695TypeAlias */) !== 0) {
|
2924
|
+
if (reportInvalidUseOfPep695TypeAlias(type, node)) {
|
2925
|
+
type = types_1.UnknownType.create();
|
2926
|
+
}
|
2927
|
+
}
|
2917
2928
|
if ((flags & 128 /* ExpectingInstantiableType */) !== 0) {
|
2918
2929
|
if ((flags & 1024 /* AllowGenericClassType */) === 0) {
|
2919
2930
|
if ((0, types_1.isInstantiableClass)(type) && types_1.ClassType.isBuiltIn(type, 'Generic')) {
|
@@ -3066,7 +3077,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3066
3077
|
}
|
3067
3078
|
}
|
3068
3079
|
}
|
3069
|
-
else if ((flags & 4096 /*
|
3080
|
+
else if ((flags & 4096 /* AllowTypeVarsWithoutScopeId */) === 0) {
|
3070
3081
|
if ((type.scopeId === undefined || scopedTypeVarInfo.foundInterveningClass) &&
|
3071
3082
|
!type.details.isSynthesized) {
|
3072
3083
|
let message;
|
@@ -3143,7 +3154,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3143
3154
|
name: type.typeAliasInfo.name,
|
3144
3155
|
}), node);
|
3145
3156
|
}
|
3146
|
-
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, { unknownIfNotFound: true }), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.typeParameters, defaultTypeArgs);
|
3157
|
+
type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(type, typeVarContext, { unknownIfNotFound: true }), type.typeAliasInfo.name, type.typeAliasInfo.fullName, type.typeAliasInfo.typeVarScopeId, type.typeAliasInfo.isPep695Syntax, type.typeAliasInfo.typeParameters, defaultTypeArgs);
|
3147
3158
|
}
|
3148
3159
|
return type;
|
3149
3160
|
}
|
@@ -3251,14 +3262,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3251
3262
|
return { type, isRescoped: false, foundInterveningClass: false };
|
3252
3263
|
}
|
3253
3264
|
function getTypeOfMemberAccess(node, flags) {
|
3254
|
-
const baseTypeFlags =
|
3265
|
+
const baseTypeFlags = 16777218 /* MemberAccessBaseDefaults */ |
|
3255
3266
|
(flags &
|
3256
3267
|
(256 /* ExpectingTypeAnnotation */ |
|
3257
3268
|
32768 /* VariableTypeAnnotation */ |
|
3258
3269
|
4 /* AllowForwardReferences */ |
|
3259
3270
|
524288 /* NotParsedByInterpreter */ |
|
3260
3271
|
2048 /* DisallowTypeVarsWithScopeId */ |
|
3261
|
-
4096 /* DisallowTypeVarsWithoutScopeId */ |
|
3262
3272
|
8192 /* AssociateTypeVarsWithCurrentScope */));
|
3263
3273
|
const baseTypeResult = getTypeOfExpression(node.leftExpression, baseTypeFlags);
|
3264
3274
|
if ((0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
@@ -3875,10 +3885,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3875
3885
|
},
|
3876
3886
|
];
|
3877
3887
|
if (usage.method === 'get') {
|
3878
|
-
// Provide "
|
3888
|
+
// Provide "owner" argument.
|
3889
|
+
// Use Any rather than None for the owner argument if accessing through an object.
|
3890
|
+
// None is more correct, but it doesn't really matter, and many descriptor classes
|
3891
|
+
// incorrectly annotate the owner parameter. Rather than create a bunch of noise,
|
3892
|
+
// we'll use Any here.
|
3879
3893
|
argList.push({
|
3880
3894
|
argumentCategory: 0 /* Simple */,
|
3881
|
-
typeResult: {
|
3895
|
+
typeResult: {
|
3896
|
+
type: isAccessedThroughObject ? types_1.AnyType.create() : baseTypeClass,
|
3897
|
+
},
|
3882
3898
|
});
|
3883
3899
|
}
|
3884
3900
|
else if (usage.method === 'set') {
|
@@ -4233,7 +4249,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4233
4249
|
return undefined;
|
4234
4250
|
}
|
4235
4251
|
function getTypeOfIndex(node, flags = 0 /* None */) {
|
4236
|
-
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /*
|
4252
|
+
const baseTypeResult = getTypeOfExpression(node.baseExpression, flags | 2 /* IndexBaseDefaults */);
|
4237
4253
|
// If this is meant to be a type and the base expression is a string expression,
|
4238
4254
|
// emit an error because this will generate a runtime exception in Python versions
|
4239
4255
|
// less than 3.10.
|
@@ -4474,6 +4490,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4474
4490
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
4475
4491
|
functionType.details.paramSpec = typeArg;
|
4476
4492
|
}
|
4493
|
+
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
4494
|
+
types_1.FunctionType.addDefaultParameters(functionType);
|
4495
|
+
functionType.details.flags |= 32768 /* SkipArgsKwargsCompatibilityCheck */;
|
4496
|
+
}
|
4477
4497
|
}
|
4478
4498
|
else {
|
4479
4499
|
types_1.FunctionType.addParameter(functionType, {
|
@@ -4545,7 +4565,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4545
4565
|
}
|
4546
4566
|
aliasTypeArgs.push(typeVarType || types_1.UnknownType.create());
|
4547
4567
|
});
|
4548
|
-
const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), baseType.typeAliasInfo.name, baseType.typeAliasInfo.fullName, baseType.typeAliasInfo.typeVarScopeId, baseType.typeAliasInfo.typeParameters, aliasTypeArgs);
|
4568
|
+
const type = types_1.TypeBase.cloneForTypeAlias((0, typeUtils_1.applySolvedTypeVars)(baseType, typeVarContext), baseType.typeAliasInfo.name, baseType.typeAliasInfo.fullName, baseType.typeAliasInfo.typeVarScopeId, baseType.typeAliasInfo.isPep695Syntax, baseType.typeAliasInfo.typeParameters, aliasTypeArgs);
|
4549
4569
|
return { type, node };
|
4550
4570
|
}
|
4551
4571
|
function getTypeOfIndexWithBaseType(node, baseTypeResult, usage, flags) {
|
@@ -4556,7 +4576,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4556
4576
|
}
|
4557
4577
|
if ((0, types_1.isTypeVar)(baseTypeResult.type) && (0, typeUtils_1.isTypeAliasPlaceholder)(baseTypeResult.type)) {
|
4558
4578
|
const typeArgTypes = getTypeArgs(node, flags).map((t) => (0, typeUtils_1.convertToInstance)(t.type));
|
4559
|
-
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4579
|
+
const type = types_1.TypeBase.cloneForTypeAlias(baseTypeResult.type, baseTypeResult.type.details.recursiveTypeAliasName, '', baseTypeResult.type.details.recursiveTypeAliasScopeId, baseTypeResult.type.details.recursiveTypeAliasIsPep695Syntax, baseTypeResult.type.details.recursiveTypeParameters, typeArgTypes);
|
4560
4580
|
return { type };
|
4561
4581
|
}
|
4562
4582
|
let isIncomplete = baseTypeResult.isIncomplete;
|
@@ -4853,14 +4873,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4853
4873
|
typeof valueType.literalValue === 'number') {
|
4854
4874
|
const indexValue = valueType.literalValue;
|
4855
4875
|
const tupleType = (0, typeUtils_1.getSpecializedTupleType)(baseType);
|
4856
|
-
if (tupleType && tupleType.tupleTypeArguments
|
4857
|
-
if (
|
4858
|
-
|
4859
|
-
|
4860
|
-
|
4861
|
-
|
4862
|
-
|
4863
|
-
|
4876
|
+
if (tupleType && tupleType.tupleTypeArguments) {
|
4877
|
+
if ((0, typeUtils_1.isTupleIndexUnambiguous)(tupleType, indexValue)) {
|
4878
|
+
if (indexValue >= 0 && indexValue < tupleType.tupleTypeArguments.length) {
|
4879
|
+
return { type: tupleType.tupleTypeArguments[indexValue].type };
|
4880
|
+
}
|
4881
|
+
else if (indexValue < 0 && tupleType.tupleTypeArguments.length + indexValue >= 0) {
|
4882
|
+
return {
|
4883
|
+
type: tupleType.tupleTypeArguments[tupleType.tupleTypeArguments.length + indexValue]
|
4884
|
+
.type,
|
4885
|
+
};
|
4886
|
+
}
|
4864
4887
|
}
|
4865
4888
|
}
|
4866
4889
|
}
|
@@ -5340,7 +5363,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5340
5363
|
baseTypeResult = getTypeOfLambdaForCall(node, inferenceContext);
|
5341
5364
|
}
|
5342
5365
|
else {
|
5343
|
-
baseTypeResult = getTypeOfExpression(node.leftExpression,
|
5366
|
+
baseTypeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */ | (flags & 4 /* AllowForwardReferences */));
|
5344
5367
|
}
|
5345
5368
|
const argList = node.arguments.map((arg) => {
|
5346
5369
|
const functionArg = {
|
@@ -5475,7 +5498,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5475
5498
|
}
|
5476
5499
|
}
|
5477
5500
|
function getLambdaType() {
|
5478
|
-
return getTypeOfExpression(node.leftExpression,
|
5501
|
+
return getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */, (0, typeUtils_1.makeInferenceContext)(expectedType));
|
5479
5502
|
}
|
5480
5503
|
// If one or more of the arguments are incomplete, use speculative mode
|
5481
5504
|
// for the lambda evaluation because it may need to be reevaluated once
|
@@ -5485,7 +5508,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5485
5508
|
: getLambdaType();
|
5486
5509
|
// If bidirectional type inference failed, use normal type inference instead.
|
5487
5510
|
if (typeResult.typeErrors) {
|
5488
|
-
typeResult = getTypeOfExpression(node.leftExpression,
|
5511
|
+
typeResult = getTypeOfExpression(node.leftExpression, 16777218 /* CallBaseDefaults */);
|
5489
5512
|
}
|
5490
5513
|
return typeResult;
|
5491
5514
|
}
|
@@ -5650,7 +5673,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
5650
5673
|
}
|
5651
5674
|
else if ((0, types_1.isInstantiableClass)(secondArgType)) {
|
5652
5675
|
if ((0, types_1.isInstantiableClass)(targetClassType)) {
|
5653
|
-
if (!
|
5676
|
+
if (!types_1.ClassType.isBuiltIn(targetClassType, 'type') &&
|
5677
|
+
!(0, typeUtils_1.derivesFromClassRecursive)(secondArgType, targetClassType, /* ignoreUnknown */ true)) {
|
5654
5678
|
reportError = true;
|
5655
5679
|
}
|
5656
5680
|
}
|
@@ -6281,23 +6305,25 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6281
6305
|
}
|
6282
6306
|
}
|
6283
6307
|
}
|
6308
|
+
let effectiveTypeVarContext = typeVarContext;
|
6309
|
+
if (!effectiveTypeVarContext) {
|
6310
|
+
// If a typeVarContext wasn't provided by the caller, allocate one here.
|
6311
|
+
effectiveTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(expandedCallType));
|
6312
|
+
}
|
6284
6313
|
// The stdlib collections/__init__.pyi stub file defines namedtuple
|
6285
6314
|
// as a function rather than a class, so we need to check for it here.
|
6286
6315
|
if (expandedCallType.details.builtInName === 'namedtuple') {
|
6287
6316
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(errorNode).diagnosticRuleSet.reportUntypedNamedTuple, diagnosticRules_1.DiagnosticRule.reportUntypedNamedTuple, localize_1.Localizer.Diagnostic.namedTupleNoTypes(), errorNode);
|
6288
|
-
|
6317
|
+
const result = {
|
6289
6318
|
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ false),
|
6290
6319
|
};
|
6320
|
+
validateFunctionArguments(errorNode, argList, { type: expandedCallType }, effectiveTypeVarContext, skipUnknownArgCheck);
|
6321
|
+
return result;
|
6291
6322
|
}
|
6292
6323
|
// Handle the NewType specially, replacing the normal return type.
|
6293
6324
|
if (expandedCallType.details.builtInName === 'NewType') {
|
6294
6325
|
return { returnType: createNewType(errorNode, argList) };
|
6295
6326
|
}
|
6296
|
-
let effectiveTypeVarContext = typeVarContext;
|
6297
|
-
if (!effectiveTypeVarContext) {
|
6298
|
-
// If a typeVarContext wasn't provided by the caller, allocate one here.
|
6299
|
-
effectiveTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeIds)(expandedCallType));
|
6300
|
-
}
|
6301
6327
|
const functionResult = validateFunctionArguments(errorNode, argList, { type: expandedCallType, isIncomplete: isCallTypeIncomplete }, effectiveTypeVarContext, skipUnknownArgCheck, inferenceContext);
|
6302
6328
|
let isTypeIncomplete = !!functionResult.isTypeIncomplete;
|
6303
6329
|
let returnType = functionResult.returnType;
|
@@ -6424,9 +6450,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6424
6450
|
}
|
6425
6451
|
}
|
6426
6452
|
if (className === 'NamedTuple') {
|
6427
|
-
|
6453
|
+
const result = {
|
6428
6454
|
returnType: (0, namedTuples_1.createNamedTupleType)(evaluatorInterface, errorNode, argList, /* includesTypes */ true),
|
6429
6455
|
};
|
6456
|
+
const initTypeResult = getTypeOfObjectMember(errorNode, types_1.ClassType.cloneAsInstance(expandedCallType), '__init__');
|
6457
|
+
if (initTypeResult && (0, types_1.isOverloadedFunction)(initTypeResult.type)) {
|
6458
|
+
validateOverloadedFunctionArguments(errorNode, argList, { type: initTypeResult.type },
|
6459
|
+
/* typeVarContext */ undefined, skipUnknownArgCheck,
|
6460
|
+
/* inferenceContext */ undefined);
|
6461
|
+
}
|
6462
|
+
return result;
|
6430
6463
|
}
|
6431
6464
|
if (className === 'NewType') {
|
6432
6465
|
return { returnType: createNewType(errorNode, argList) };
|
@@ -8072,7 +8105,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8072
8105
|
? 512 /* AllowMissingTypeArgs */ |
|
8073
8106
|
8 /* EvaluateStringLiteralAsType */ |
|
8074
8107
|
32 /* DisallowParamSpec */ |
|
8075
|
-
64 /* DisallowTypeVarTuple */
|
8108
|
+
64 /* DisallowTypeVarTuple */ |
|
8109
|
+
16777216 /* DisallowPep695TypeAlias */
|
8076
8110
|
: 2 /* DoNotSpecialize */;
|
8077
8111
|
const exprTypeResult = getTypeOfExpression(argParam.argument.valueExpression, flags, (0, typeUtils_1.makeInferenceContext)(expectedType, !!(typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete), signatureTracker));
|
8078
8112
|
argType = exprTypeResult.type;
|
@@ -8623,7 +8657,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8623
8657
|
typeParameters = [];
|
8624
8658
|
let isTypeParamListValid = true;
|
8625
8659
|
typeParamsExpr.expressions.map((expr) => {
|
8626
|
-
let entryType = getTypeOfExpression(expr, 128 /* ExpectingInstantiableType */).type;
|
8660
|
+
let entryType = getTypeOfExpression(expr, 128 /* ExpectingInstantiableType */ | 4096 /* AllowTypeVarsWithoutScopeId */).type;
|
8627
8661
|
if ((0, types_1.isTypeVar)(entryType)) {
|
8628
8662
|
if (entryType.scopeId) {
|
8629
8663
|
isTypeParamListValid = false;
|
@@ -8643,6 +8677,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8643
8677
|
}
|
8644
8678
|
}
|
8645
8679
|
return getTypeOfTypeAliasCommon(nameNode, nameNode, valueExpr,
|
8680
|
+
/* isPep695Syntax */ false,
|
8646
8681
|
/* typeParamNodes */ undefined, () => typeParameters !== null && typeParameters !== void 0 ? typeParameters : []);
|
8647
8682
|
}
|
8648
8683
|
function getBooleanValue(node) {
|
@@ -8922,7 +8957,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8922
8957
|
}
|
8923
8958
|
function getTypeOfDictionaryWithContext(node, inferenceContext, expectedDiagAddendum) {
|
8924
8959
|
inferenceContext.expectedType = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(inferenceContext.expectedType);
|
8925
|
-
|
8960
|
+
let concreteExpectedType = makeTopLevelTypeVarsConcrete(inferenceContext.expectedType);
|
8926
8961
|
if (!(0, types_1.isClassInstance)(concreteExpectedType)) {
|
8927
8962
|
return undefined;
|
8928
8963
|
}
|
@@ -8931,6 +8966,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8931
8966
|
let isIncomplete = false;
|
8932
8967
|
// Handle TypedDict's as a special case.
|
8933
8968
|
if (types_1.ClassType.isTypedDictClass(concreteExpectedType)) {
|
8969
|
+
// Remove any conditions associated with the type so the resulting type isn't
|
8970
|
+
// considered compatible with a bound TypeVar.
|
8971
|
+
concreteExpectedType = types_1.TypeBase.cloneForCondition(concreteExpectedType, undefined);
|
8934
8972
|
const expectedTypedDictEntries = (0, typedDicts_1.getTypedDictMembersForClass)(evaluatorInterface, concreteExpectedType);
|
8935
8973
|
// Infer the key and value types if possible.
|
8936
8974
|
if (getKeyAndValueTypesFromDictionary(node, keyTypes, valueTypes,
|
@@ -8940,17 +8978,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8940
8978
|
/* expectedValueType */ undefined, expectedTypedDictEntries, expectedDiagAddendum)) {
|
8941
8979
|
isIncomplete = true;
|
8942
8980
|
}
|
8943
|
-
|
8944
|
-
|
8945
|
-
|
8946
|
-
|
8947
|
-
|
8948
|
-
|
8949
|
-
|
8950
|
-
|
8951
|
-
|
8952
|
-
};
|
8953
|
-
}
|
8981
|
+
const resultTypedDict = (0, typedDicts_1.assignToTypedDict)(evaluatorInterface, concreteExpectedType, keyTypes, valueTypes,
|
8982
|
+
// Don't overwrite existing expectedDiagAddendum messages if they were
|
8983
|
+
// already provided by getKeyValueTypesFromDictionary.
|
8984
|
+
(expectedDiagAddendum === null || expectedDiagAddendum === void 0 ? void 0 : expectedDiagAddendum.isEmpty()) ? expectedDiagAddendum : undefined);
|
8985
|
+
if (resultTypedDict) {
|
8986
|
+
return {
|
8987
|
+
type: resultTypedDict,
|
8988
|
+
isIncomplete,
|
8989
|
+
};
|
8954
8990
|
}
|
8955
8991
|
return undefined;
|
8956
8992
|
}
|
@@ -9886,6 +9922,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9886
9922
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
9887
9923
|
functionType.details.paramSpec = typeArg;
|
9888
9924
|
}
|
9925
|
+
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
9926
|
+
types_1.FunctionType.addDefaultParameters(functionType);
|
9927
|
+
functionType.details.flags |= 32768 /* SkipArgsKwargsCompatibilityCheck */;
|
9928
|
+
}
|
9889
9929
|
}
|
9890
9930
|
else {
|
9891
9931
|
types_1.FunctionType.addParameter(functionType, {
|
@@ -10264,7 +10304,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10264
10304
|
else {
|
10265
10305
|
typeArgs.forEach((typeArg, index) => {
|
10266
10306
|
if (index === typeArgs.length - 1) {
|
10267
|
-
if (!(0, types_1.isParamSpec)(typeArg.type)) {
|
10307
|
+
if (!(0, types_1.isParamSpec)(typeArg.type) && !(0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
10268
10308
|
addError(localize_1.Localizer.Diagnostic.concatenateParamSpecMissing(), typeArg.node);
|
10269
10309
|
}
|
10270
10310
|
}
|
@@ -10322,7 +10362,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10322
10362
|
typeArgs.forEach((typeArg, index) => {
|
10323
10363
|
if ((0, typeUtils_1.isEllipsisType)(typeArg.type)) {
|
10324
10364
|
if (!isTupleTypeParam) {
|
10325
|
-
|
10365
|
+
if (!allowParamSpec) {
|
10366
|
+
addError(localize_1.Localizer.Diagnostic.ellipsisContext(), typeArg.node);
|
10367
|
+
}
|
10326
10368
|
}
|
10327
10369
|
else if (typeArgs.length !== 2 || index !== 1) {
|
10328
10370
|
addError(localize_1.Localizer.Diagnostic.ellipsisSecondArg(), typeArg.node);
|
@@ -10490,7 +10532,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10490
10532
|
}
|
10491
10533
|
return createSpecialType(classType, typeArgs, /* paramLimit */ undefined, /* allowParamSpec */ true);
|
10492
10534
|
}
|
10493
|
-
function transformTypeForTypeAlias(type, name, errorNode, typeParameters, typeParamNodes) {
|
10535
|
+
function transformTypeForTypeAlias(type, name, errorNode, isPep695Syntax, typeParameters, typeParamNodes) {
|
10494
10536
|
if (!types_1.TypeBase.isInstantiable(type)) {
|
10495
10537
|
return type;
|
10496
10538
|
}
|
@@ -10540,7 +10582,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10540
10582
|
names: boundTypeVars.map((t) => `${t.details.name}`).join(', '),
|
10541
10583
|
}), errorNode);
|
10542
10584
|
}
|
10543
|
-
|
10585
|
+
const typeAlias = types_1.TypeBase.cloneForTypeAlias(type, name.value, ParseTreeUtils.getClassFullName(name, fileInfo.moduleName, name.value), typeAliasScopeId, isPep695Syntax, typeParameters.length > 0 ? typeParameters : undefined);
|
10586
|
+
// All PEP 695 type aliases are special forms because they are
|
10587
|
+
// TypeAliasType objects at runtime.
|
10588
|
+
if (isPep695Syntax) {
|
10589
|
+
typeAlias.flags |= 8 /* SpecialForm */;
|
10590
|
+
}
|
10591
|
+
return typeAlias;
|
10544
10592
|
}
|
10545
10593
|
function createSpecialBuiltInClass(node, assignedName, aliasMapEntry) {
|
10546
10594
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
@@ -10686,7 +10734,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10686
10734
|
return undefined;
|
10687
10735
|
}
|
10688
10736
|
function evaluateTypesForAssignmentStatement(node) {
|
10689
|
-
var _a;
|
10737
|
+
var _a, _b;
|
10690
10738
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
10691
10739
|
// If the entire statement has already been evaluated, don't
|
10692
10740
|
// re-evaluate it.
|
@@ -10761,6 +10809,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10761
10809
|
typeAliasTypeVar.details.recursiveTypeAliasName = typeAliasNameNode.value;
|
10762
10810
|
const scopeId = ParseTreeUtils.getScopeIdForNode(typeAliasNameNode);
|
10763
10811
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10812
|
+
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = false;
|
10764
10813
|
typeAliasTypeVar.scopeId = scopeId;
|
10765
10814
|
// Write the type back to the type cache. It will be replaced below.
|
10766
10815
|
writeTypeCache(node, { type: typeAliasTypeVar }, /* flags */ undefined);
|
@@ -10784,20 +10833,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10784
10833
|
srcType = types_1.ClassType.cloneWithLiteral(boolType, constExprValue);
|
10785
10834
|
}
|
10786
10835
|
}
|
10787
|
-
// If there was a declared type, make sure the RHS value is compatible.
|
10788
|
-
if (declaredType) {
|
10789
|
-
if (assignType(declaredType, srcType)) {
|
10790
|
-
// Narrow the resulting type if possible.
|
10791
|
-
if (!(0, types_1.isAnyOrUnknown)(srcType)) {
|
10792
|
-
srcType = narrowTypeBasedOnAssignment(node, declaredType, srcType);
|
10793
|
-
}
|
10794
|
-
}
|
10795
|
-
}
|
10796
10836
|
// If this is an enum, transform the type as required.
|
10797
10837
|
rightHandType = srcType;
|
10798
10838
|
if (node.leftExpression.nodeType === 38 /* Name */ && !node.typeAnnotationComment) {
|
10799
10839
|
rightHandType =
|
10800
|
-
(0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType)
|
10840
|
+
(_a = (0, enums_1.transformTypeForPossibleEnumClass)(evaluatorInterface, node.leftExpression, () => rightHandType)) !== null && _a !== void 0 ? _a : rightHandType;
|
10801
10841
|
}
|
10802
10842
|
if (typeAliasNameNode) {
|
10803
10843
|
// If this was a speculative type alias, it becomes a real type alias
|
@@ -10805,7 +10845,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10805
10845
|
if (!isSpeculativeTypeAlias ||
|
10806
10846
|
(types_1.TypeBase.isInstantiable(rightHandType) && !(0, types_1.isUnknown)(rightHandType))) {
|
10807
10847
|
// If this is a type alias, record its name based on the assignment target.
|
10808
|
-
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression
|
10848
|
+
rightHandType = transformTypeForTypeAlias(rightHandType, typeAliasNameNode, node.rightExpression,
|
10849
|
+
/* isPep695Syntax */ false);
|
10809
10850
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, rightHandType)) {
|
10810
10851
|
addDiagnostic(fileInfo.diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10811
10852
|
name: typeAliasNameNode.value,
|
@@ -10817,7 +10858,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10817
10858
|
typeAliasTypeVar.details.boundType = rightHandType;
|
10818
10859
|
// Record the type parameters within the recursive type alias so it
|
10819
10860
|
// can be specialized.
|
10820
|
-
typeAliasTypeVar.details.recursiveTypeParameters = (
|
10861
|
+
typeAliasTypeVar.details.recursiveTypeParameters = (_b = rightHandType.typeAliasInfo) === null || _b === void 0 ? void 0 : _b.typeParameters;
|
10821
10862
|
}
|
10822
10863
|
}
|
10823
10864
|
}
|
@@ -10846,7 +10887,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10846
10887
|
callLeftNode.leftExpression.nodeType === 38 /* Name */)) {
|
10847
10888
|
// See if this is a call to TypedDict. We want to support
|
10848
10889
|
// recursive type references in a TypedDict call.
|
10849
|
-
const callType = getTypeOfExpression(callLeftNode,
|
10890
|
+
const callType = getTypeOfExpression(callLeftNode, 16777218 /* CallBaseDefaults */).type;
|
10850
10891
|
if ((0, types_1.isInstantiableClass)(callType) && types_1.ClassType.isBuiltIn(callType, 'TypedDict')) {
|
10851
10892
|
return true;
|
10852
10893
|
}
|
@@ -10859,7 +10900,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10859
10900
|
// variables since they use normal variable assignment syntax.
|
10860
10901
|
function getTypeOfTypeAlias(node) {
|
10861
10902
|
var _a;
|
10862
|
-
return getTypeOfTypeAliasCommon(node, node.name, node.expression,
|
10903
|
+
return getTypeOfTypeAliasCommon(node, node.name, node.expression,
|
10904
|
+
/* isPep695Syntax */ true, (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.parameters, () => {
|
10863
10905
|
let typeParameters = [];
|
10864
10906
|
if (node.typeParameters) {
|
10865
10907
|
typeParameters = evaluateTypeParameterList(node.typeParameters);
|
@@ -10869,7 +10911,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10869
10911
|
}
|
10870
10912
|
// This function is common to the handling of "type" statements and explicit
|
10871
10913
|
// calls to the TypeAliasType constructor.
|
10872
|
-
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, typeParamNodes, getTypeParamCallback) {
|
10914
|
+
function getTypeOfTypeAliasCommon(declNode, nameNode, valueNode, isPep695Syntax, typeParamNodes, getTypeParamCallback) {
|
10873
10915
|
const cachedType = readTypeCache(nameNode, 0 /* None */);
|
10874
10916
|
if (cachedType) {
|
10875
10917
|
return cachedType;
|
@@ -10881,6 +10923,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10881
10923
|
typeAliasTypeVar.details.recursiveTypeAliasName = nameNode.value;
|
10882
10924
|
const scopeId = ParseTreeUtils.getScopeIdForNode(nameNode);
|
10883
10925
|
typeAliasTypeVar.details.recursiveTypeAliasScopeId = scopeId;
|
10926
|
+
typeAliasTypeVar.details.recursiveTypeAliasIsPep695Syntax = isPep695Syntax;
|
10884
10927
|
typeAliasTypeVar.scopeId = scopeId;
|
10885
10928
|
// Write the type to the type cache. It will be replaced below.
|
10886
10929
|
writeTypeCache(nameNode, { type: typeAliasTypeVar }, /* flags */ undefined);
|
@@ -10902,7 +10945,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10902
10945
|
if (aliasTypeResult.isIncomplete) {
|
10903
10946
|
isIncomplete = true;
|
10904
10947
|
}
|
10905
|
-
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, typeParameters, typeParamNodes);
|
10948
|
+
aliasType = transformTypeForTypeAlias(aliasType, nameNode, valueNode, isPep695Syntax, typeParameters, typeParamNodes);
|
10906
10949
|
if ((0, typeUtils_1.isTypeAliasRecursive)(typeAliasTypeVar, aliasType)) {
|
10907
10950
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(valueNode).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAliasIsRecursiveDirect().format({
|
10908
10951
|
name: nameNode.value,
|
@@ -10998,7 +11041,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10998
11041
|
262144 /* DisallowNakedGeneric */ |
|
10999
11042
|
2048 /* DisallowTypeVarsWithScopeId */ |
|
11000
11043
|
8192 /* AssociateTypeVarsWithCurrentScope */ |
|
11001
|
-
16384 /* EnforceTypeVarVarianceConsistency
|
11044
|
+
16384 /* EnforceTypeVarVarianceConsistency */ |
|
11045
|
+
16777216 /* DisallowPep695TypeAlias */;
|
11002
11046
|
if (fileInfo.isStubFile) {
|
11003
11047
|
exprFlags |= 4 /* AllowForwardReferences */;
|
11004
11048
|
}
|
@@ -11249,6 +11293,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11249
11293
|
classType.details.fields = (innerScope === null || innerScope === void 0 ? void 0 : innerScope.symbolTable)
|
11250
11294
|
? new Map(innerScope.symbolTable)
|
11251
11295
|
: new Map();
|
11296
|
+
// Determine whether the class should inherit __hash__. If a class defines
|
11297
|
+
// __eq__ but doesn't define __hash__ then __hash__ is set to None.
|
11298
|
+
if (classType.details.fields.has('__eq__') && !classType.details.fields.has('__hash__')) {
|
11299
|
+
classType.details.fields.set('__hash__', symbol_1.Symbol.createWithType(4 /* ClassMember */ | 128 /* ClassVar */ | 64 /* IgnoredForProtocolMatch */, types_1.NoneType.createInstance()));
|
11300
|
+
}
|
11252
11301
|
// Determine whether the class's instance variables are constrained
|
11253
11302
|
// to those defined by __slots__. We need to do this prior to dataclass
|
11254
11303
|
// processing because dataclasses can implicitly add to the slots
|
@@ -11299,7 +11348,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11299
11348
|
classType.details.flags |= 262144 /* HasCustomClassGetItem */;
|
11300
11349
|
}
|
11301
11350
|
}
|
11302
|
-
// Determine the effective metaclass
|
11351
|
+
// Determine the effective metaclass.
|
11303
11352
|
if (metaclassNode) {
|
11304
11353
|
const metaclassType = getTypeOfExpression(metaclassNode, exprFlags).type;
|
11305
11354
|
if ((0, types_1.isInstantiableClass)(metaclassType) || (0, types_1.isUnknown)(metaclassType)) {
|
@@ -12085,11 +12134,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12085
12134
|
}
|
12086
12135
|
validateTypeParameterDefault(bestErrorNode, typeParam, functionType.details.typeParameters.slice(0, index));
|
12087
12136
|
});
|
12137
|
+
// If it's an async function, wrap the return type in an Awaitable or Generator.
|
12138
|
+
const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
|
12088
12139
|
// Clear the "partially evaluated" flag to indicate that the functionType
|
12089
12140
|
// is fully evaluated.
|
12090
12141
|
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
12091
|
-
// If it's an async function, wrap the return type in an Awaitable or Generator.
|
12092
|
-
const preDecoratedType = node.isAsync ? createAsyncFunction(node, functionType) : functionType;
|
12093
12142
|
// Apply all of the decorators in reverse order.
|
12094
12143
|
let decoratedType = preDecoratedType;
|
12095
12144
|
let foundUnknown = false;
|
@@ -12302,7 +12351,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12302
12351
|
(0, debug_1.assert)(types_1.FunctionType.isAsync(functionType));
|
12303
12352
|
// Clone the original function and replace its return type with an
|
12304
12353
|
// Awaitable[<returnType>]. Mark the new function as no longer async.
|
12305
|
-
const awaitableFunctionType = types_1.FunctionType.cloneWithNewFlags(functionType, functionType.details.flags & ~512 /* Async */);
|
12354
|
+
const awaitableFunctionType = types_1.FunctionType.cloneWithNewFlags(functionType, functionType.details.flags & ~(512 /* Async */ | 131072 /* PartiallyEvaluated */));
|
12306
12355
|
if (functionType.details.declaredReturnType) {
|
12307
12356
|
awaitableFunctionType.details.declaredReturnType = createAwaitableReturnType(node, functionType.details.declaredReturnType, types_1.FunctionType.isGenerator(functionType));
|
12308
12357
|
}
|
@@ -12785,7 +12834,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12785
12834
|
for (const caseStatement of node.parent.cases) {
|
12786
12835
|
if (caseStatement === node) {
|
12787
12836
|
if (fileInfo.diagnosticRuleSet.reportUnnecessaryComparison !== 'none') {
|
12788
|
-
(
|
12837
|
+
if (!subjectTypeResult.isIncomplete) {
|
12838
|
+
(0, patternMatching_1.checkForUnusedPattern)(evaluatorInterface, node.pattern, subjectType);
|
12839
|
+
}
|
12789
12840
|
}
|
12790
12841
|
break;
|
12791
12842
|
}
|
@@ -12801,23 +12852,57 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12801
12852
|
if (isTypeCached(node)) {
|
12802
12853
|
return;
|
12803
12854
|
}
|
12804
|
-
|
12805
|
-
|
12806
|
-
|
12807
|
-
|
12808
|
-
|
12809
|
-
|
12855
|
+
if (node.isWildcardImport) {
|
12856
|
+
// Write back a dummy type so we don't evaluate this node again.
|
12857
|
+
writeTypeCache(node, { type: types_1.AnyType.create() }, 0 /* None */);
|
12858
|
+
const flowNode = AnalyzerNodeInfo.getFlowNode(node);
|
12859
|
+
if (flowNode && (flowNode.flags & codeFlowTypes_1.FlowFlags.WildcardImport) !== 0) {
|
12860
|
+
const wildcardFlowNode = flowNode;
|
12861
|
+
wildcardFlowNode.names.forEach((name) => {
|
12862
|
+
var _a, _b;
|
12863
|
+
const importedSymbolType = getAliasedSymbolTypeForName(node, name);
|
12864
|
+
if (!importedSymbolType) {
|
12865
|
+
return;
|
12866
|
+
}
|
12867
|
+
const symbolWithScope = lookUpSymbolRecursive(node, name, /* honorCodeFlow */ false);
|
12868
|
+
if (!symbolWithScope) {
|
12869
|
+
return;
|
12870
|
+
}
|
12871
|
+
const declaredType = (_a = getDeclaredTypeOfSymbol(symbolWithScope.symbol)) === null || _a === void 0 ? void 0 : _a.type;
|
12872
|
+
if (!declaredType) {
|
12873
|
+
return;
|
12874
|
+
}
|
12875
|
+
const diagAddendum = new diagnostic_1.DiagnosticAddendum();
|
12876
|
+
if (!assignType(declaredType, importedSymbolType, diagAddendum)) {
|
12877
|
+
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeAssignmentMismatchWildcard().format({
|
12878
|
+
...printSrcDestTypes(importedSymbolType, declaredType),
|
12879
|
+
name,
|
12880
|
+
}) + diagAddendum.getString(), node, (_b = node.wildcardToken) !== null && _b !== void 0 ? _b : node);
|
12881
|
+
}
|
12882
|
+
});
|
12883
|
+
}
|
12810
12884
|
}
|
12811
|
-
|
12812
|
-
|
12813
|
-
|
12814
|
-
|
12815
|
-
|
12816
|
-
|
12885
|
+
else {
|
12886
|
+
// Use the first element of the name parts as the symbol.
|
12887
|
+
const symbolNameNode = node.module.nameParts[0];
|
12888
|
+
// Look up the symbol to find the alias declaration.
|
12889
|
+
let symbolType = getAliasedSymbolTypeForName(node, symbolNameNode.value);
|
12890
|
+
if (!symbolType) {
|
12891
|
+
return;
|
12892
|
+
}
|
12893
|
+
// Is there a cached module type associated with this node? If so, use
|
12894
|
+
// it instead of the type we just created.
|
12895
|
+
const cachedModuleType = readTypeCache(node, 0 /* None */);
|
12896
|
+
if (cachedModuleType && (0, types_1.isModule)(cachedModuleType) && symbolType) {
|
12897
|
+
if ((0, types_1.isTypeSame)(symbolType, cachedModuleType)) {
|
12898
|
+
symbolType = cachedModuleType;
|
12899
|
+
}
|
12817
12900
|
}
|
12901
|
+
assignTypeToNameNode(symbolNameNode, symbolType,
|
12902
|
+
/* isIncomplete */ false,
|
12903
|
+
/* ignoreEmptyContainers */ false);
|
12904
|
+
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12818
12905
|
}
|
12819
|
-
assignTypeToNameNode(symbolNameNode, symbolType, /* isIncomplete */ false, /* ignoreEmptyContainers */ false);
|
12820
|
-
writeTypeCache(node, { type: symbolType }, 0 /* None */);
|
12821
12906
|
}
|
12822
12907
|
function evaluateTypesForTypeAnnotationNode(node) {
|
12823
12908
|
var _a;
|
@@ -13029,14 +13114,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13029
13114
|
nodeToEvaluate = parent;
|
13030
13115
|
continue;
|
13031
13116
|
}
|
13032
|
-
flags =
|
13117
|
+
flags = 16777218 /* CallBaseDefaults */;
|
13033
13118
|
break;
|
13034
13119
|
}
|
13035
13120
|
}
|
13036
13121
|
else if (parent.nodeType === 24 /* Index */) {
|
13037
13122
|
// The base expression of an index expression is not contextual.
|
13038
13123
|
if (nodeToEvaluate === parent.baseExpression) {
|
13039
|
-
flags = 2 /*
|
13124
|
+
flags = 2 /* IndexBaseDefaults */;
|
13040
13125
|
break;
|
13041
13126
|
}
|
13042
13127
|
}
|
@@ -13643,6 +13728,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13643
13728
|
if ((0, types_1.isParamSpec)(typeArg)) {
|
13644
13729
|
functionType.details.paramSpec = typeArg;
|
13645
13730
|
}
|
13731
|
+
else if ((0, typeUtils_1.isEllipsisType)(typeArg)) {
|
13732
|
+
types_1.FunctionType.addDefaultParameters(functionType);
|
13733
|
+
functionType.details.flags |=
|
13734
|
+
32768 /* SkipArgsKwargsCompatibilityCheck */;
|
13735
|
+
}
|
13646
13736
|
}
|
13647
13737
|
else {
|
13648
13738
|
types_1.FunctionType.addParameter(functionType, {
|
@@ -13742,8 +13832,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13742
13832
|
let flags = 128 /* ExpectingInstantiableType */ |
|
13743
13833
|
8 /* EvaluateStringLiteralAsType */ |
|
13744
13834
|
131072 /* DisallowClassVar */;
|
13745
|
-
if (
|
13746
|
-
flags |= 4096 /*
|
13835
|
+
if (options === null || options === void 0 ? void 0 : options.allowTypeVarsWithoutScopeId) {
|
13836
|
+
flags |= 4096 /* AllowTypeVarsWithoutScopeId */;
|
13747
13837
|
}
|
13748
13838
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
13749
13839
|
if (fileInfo.isStubFile || (options === null || options === void 0 ? void 0 : options.allowForwardReference)) {
|
@@ -14481,7 +14571,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14481
14571
|
}
|
14482
14572
|
// Special-case calls to certain built-in type functions.
|
14483
14573
|
if (((_a = resolvedDecl.inferredTypeSource) === null || _a === void 0 ? void 0 : _a.nodeType) === 9 /* Call */) {
|
14484
|
-
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression,
|
14574
|
+
const baseTypeResult = getTypeOfExpression(resolvedDecl.inferredTypeSource.leftExpression, 16777218 /* CallBaseDefaults */);
|
14485
14575
|
const callType = baseTypeResult.type;
|
14486
14576
|
const exemptBuiltins = [
|
14487
14577
|
'TypeVar',
|
@@ -14537,7 +14627,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14537
14627
|
if (types_1.TypeBase.isInstantiable(inferredType) &&
|
14538
14628
|
!(0, types_1.isUnknown)(inferredType) &&
|
14539
14629
|
!(0, typeUtils_1.isEllipsisType)(inferredType)) {
|
14540
|
-
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node
|
14630
|
+
inferredType = transformTypeForTypeAlias(inferredType, resolvedDecl.typeAliasName, resolvedDecl.node,
|
14631
|
+
/* isPep695Syntax */ false);
|
14541
14632
|
isUnambiguousType = true;
|
14542
14633
|
}
|
14543
14634
|
}
|
@@ -14972,6 +15063,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
14972
15063
|
return types_1.UnknownType.create();
|
14973
15064
|
}
|
14974
15065
|
function getFunctionInferredReturnType(type, args) {
|
15066
|
+
var _a;
|
14975
15067
|
let returnType;
|
14976
15068
|
let isIncomplete = false;
|
14977
15069
|
let analyzeUnannotatedFunctions = true;
|
@@ -15039,9 +15131,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
15039
15131
|
!types_1.FunctionType.isStubDefinition(type) &&
|
15040
15132
|
!types_1.FunctionType.isPyTypedDefinition(type) &&
|
15041
15133
|
args) {
|
15042
|
-
|
15043
|
-
|
15044
|
-
|
15134
|
+
let hasDecorators = false;
|
15135
|
+
let isAsync = false;
|
15136
|
+
const declNode = (_a = type.details.declaration) === null || _a === void 0 ? void 0 : _a.node;
|
15137
|
+
if (declNode) {
|
15138
|
+
if (declNode.decorators.length > 0) {
|
15139
|
+
hasDecorators = true;
|
15140
|
+
}
|
15141
|
+
if (declNode.isAsync) {
|
15142
|
+
isAsync = true;
|
15143
|
+
}
|
15144
|
+
}
|
15145
|
+
// We can't use this technique if decorators or async are used because they
|
15146
|
+
// would need to be applied to the inferred return type.
|
15147
|
+
if (!hasDecorators && !isAsync) {
|
15148
|
+
const contextualReturnType = getFunctionInferredReturnTypeUsingArguments(type, args);
|
15149
|
+
if (contextualReturnType) {
|
15150
|
+
returnType = contextualReturnType;
|
15151
|
+
}
|
15045
15152
|
}
|
15046
15153
|
}
|
15047
15154
|
return returnType;
|
@@ -17007,16 +17114,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17007
17114
|
// concatenated parameters must match.
|
17008
17115
|
if (targetIncludesParamSpec &&
|
17009
17116
|
((_j = srcType.details.paramSpec) === null || _j === void 0 ? void 0 : _j.nameWithScope) === ((_k = destType.details.paramSpec) === null || _k === void 0 ? void 0 : _k.nameWithScope)) {
|
17010
|
-
|
17011
|
-
|
17012
|
-
if (srcParamCount !== destParamCount) {
|
17013
|
-
// If the dest has an extra position-only parameter separator appended
|
17014
|
-
// to the end of the signature, it's OK.
|
17015
|
-
if (srcParamCount !== destParamCount - 1 ||
|
17016
|
-
destType.details.parameters[destParamCount - 1].category !== 0 /* Simple */ ||
|
17017
|
-
!!destType.details.parameters[destParamCount - 1].name) {
|
17018
|
-
canAssign = false;
|
17019
|
-
}
|
17117
|
+
if (srcParamDetails.params.length !== destParamDetails.params.length) {
|
17118
|
+
canAssign = false;
|
17020
17119
|
}
|
17021
17120
|
}
|
17022
17121
|
const effectiveSrcTypeVarContext = (flags & 2 /* ReverseTypeVarMatching */) === 0 ? srcTypeVarContext : destTypeVarContext;
|
@@ -17076,6 +17175,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17076
17175
|
!(0, types_1.isTypeSame)(srcParamSpec, destParamSpec, { ignoreTypeFlags: true })) {
|
17077
17176
|
const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.details.flags | 64 /* SynthesizedMethod */, effectiveSrcType.details.docString);
|
17078
17177
|
remainingFunction.details.typeVarScopeId = effectiveSrcType.details.typeVarScopeId;
|
17178
|
+
remainingFunction.details.constructorTypeVarScopeId =
|
17179
|
+
effectiveSrcType.details.constructorTypeVarScopeId;
|
17079
17180
|
remainingParams.forEach((param) => {
|
17080
17181
|
types_1.FunctionType.addParameter(remainingFunction, param);
|
17081
17182
|
});
|
@@ -17174,7 +17275,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17174
17275
|
const typeParam = assignedType.details.typeParameters[index];
|
17175
17276
|
const expectedTypeArgType = typeVarContext.getPrimarySignature().getTypeVarType(typeParam);
|
17176
17277
|
if (expectedTypeArgType) {
|
17177
|
-
if ((0,
|
17278
|
+
if ((0, types_1.isAnyOrUnknown)(expectedTypeArgType) || (0, types_1.isAnyOrUnknown)(typeArg)) {
|
17178
17279
|
replacedTypeArg = true;
|
17179
17280
|
return expectedTypeArgType;
|
17180
17281
|
}
|
@@ -17186,6 +17287,19 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17186
17287
|
return recursiveReplacement;
|
17187
17288
|
}
|
17188
17289
|
}
|
17290
|
+
else if ((0, typeUtils_1.containsAnyRecursive)(expectedTypeArgType)) {
|
17291
|
+
// If the expected type arg contains an Any, we can replace it with
|
17292
|
+
// a version that doesn't contain Any if the replacement doesn't violate
|
17293
|
+
// the variance of the type parameter.
|
17294
|
+
const variance = types_1.TypeVarType.getVariance(typeParam);
|
17295
|
+
const isSubtype = assignType(expectedTypeArgType, typeArg);
|
17296
|
+
const isSupertype = assignType(typeArg, expectedTypeArgType);
|
17297
|
+
if ((variance === 4 /* Contravariant */ || isSubtype) &&
|
17298
|
+
(variance === 3 /* Covariant */ || isSupertype)) {
|
17299
|
+
replacedTypeArg = true;
|
17300
|
+
return expectedTypeArgType;
|
17301
|
+
}
|
17302
|
+
}
|
17189
17303
|
}
|
17190
17304
|
return typeArg;
|
17191
17305
|
});
|
@@ -17193,6 +17307,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17193
17307
|
return types_1.ClassType.cloneForSpecialization(assignedType, newTypeArgs, /* isTypeArgumentExplicit */ true);
|
17194
17308
|
}
|
17195
17309
|
}
|
17310
|
+
// If the declared and assigned types are the same generic type but the assigned type
|
17311
|
+
// contains one or more unknowns, use the declared type instead.
|
17312
|
+
if (types_1.ClassType.isSameGenericClass(declaredType, assignedType)) {
|
17313
|
+
if ((0, typeUtils_1.containsAnyRecursive)(assignedType) && !(0, typeUtils_1.containsAnyRecursive)(declaredType)) {
|
17314
|
+
return declaredType;
|
17315
|
+
}
|
17316
|
+
}
|
17196
17317
|
return undefined;
|
17197
17318
|
}
|
17198
17319
|
// When a value is assigned to a variable with a declared type,
|
@@ -17205,29 +17326,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17205
17326
|
return declaredSubtype;
|
17206
17327
|
}
|
17207
17328
|
if (assignType(declaredSubtype, assignedSubtype)) {
|
17208
|
-
// If the
|
17209
|
-
|
17210
|
-
|
17329
|
+
// If the assigned subtype is Any, stick with the declared type.
|
17330
|
+
if ((0, types_1.isAny)(assignedSubtype)) {
|
17331
|
+
return declaredSubtype;
|
17332
|
+
}
|
17333
|
+
if ((0, types_1.isClass)(declaredSubtype) &&
|
17334
|
+
(0, types_1.isClass)(assignedSubtype) &&
|
17335
|
+
types_1.TypeBase.isInstance(declaredSubtype) === types_1.TypeBase.isInstance(assignedSubtype)) {
|
17211
17336
|
const result = replaceTypeArgsWithAny(node, declaredSubtype, assignedSubtype);
|
17212
17337
|
if (result) {
|
17213
17338
|
assignedSubtype = result;
|
17214
17339
|
}
|
17340
|
+
return assignedSubtype;
|
17215
17341
|
}
|
17216
|
-
|
17217
|
-
const result = replaceTypeArgsWithAny(node, types_1.ClassType.cloneAsInstantiable(declaredSubtype), types_1.ClassType.cloneAsInstantiable(assignedSubtype));
|
17218
|
-
if (result) {
|
17219
|
-
assignedSubtype = types_1.ClassType.cloneAsInstance(result);
|
17220
|
-
}
|
17221
|
-
}
|
17222
|
-
else if (!(0, types_1.isTypeVar)(declaredSubtype) && (0, types_1.isTypeVar)(assignedSubtype)) {
|
17342
|
+
if (!(0, types_1.isTypeVar)(declaredSubtype) && (0, types_1.isTypeVar)(assignedSubtype)) {
|
17223
17343
|
// If the source is an unsolved TypeVar but the declared type is concrete,
|
17224
17344
|
// use the concrete type.
|
17225
17345
|
return declaredSubtype;
|
17226
17346
|
}
|
17227
|
-
// If the assigned subtype is Any, stick with the declared type.
|
17228
|
-
if ((0, types_1.isAny)(assignedSubtype)) {
|
17229
|
-
return declaredSubtype;
|
17230
|
-
}
|
17231
17347
|
// If the declared type doesn't contain any `Any` but the assigned
|
17232
17348
|
// type does, stick with the declared type.
|
17233
17349
|
if ((0, typeUtils_1.containsAnyRecursive)(assignedSubtype) && !(0, typeUtils_1.containsAnyRecursive)(declaredSubtype)) {
|
@@ -17295,28 +17411,42 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17295
17411
|
// must all match and be in the correct order. It is OK if the base method
|
17296
17412
|
// has additional overloads that are not present in the override.
|
17297
17413
|
let previousMatchIndex = -1;
|
17298
|
-
let overrideOverloadIndex = 0;
|
17299
17414
|
const baseOverloads = types_1.OverloadedFunctionType.getOverloads(baseMethod);
|
17300
17415
|
for (const overrideOverload of types_1.OverloadedFunctionType.getOverloads(overrideMethod)) {
|
17301
|
-
|
17416
|
+
let possibleMatchIndex;
|
17417
|
+
let matchIndex = baseOverloads.findIndex((baseOverload, index) => {
|
17302
17418
|
// If the override isn't applicable for this base class, skip the check.
|
17303
17419
|
if (baseClass && !isOverrideMethodApplicable(baseOverload, baseClass)) {
|
17304
17420
|
return false;
|
17305
17421
|
}
|
17306
|
-
|
17422
|
+
const isCompatible = validateOverrideMethodInternal(baseOverload, overrideOverload,
|
17307
17423
|
/* diag */ undefined, enforceParamNames,
|
17308
17424
|
/* exemptSelfClsParam */ false);
|
17425
|
+
// If the override is compatible but the match is one that is below the previous
|
17426
|
+
// matched index, keep looking for additional matches. Record the fact that
|
17427
|
+
// we found at least one match.
|
17428
|
+
if (isCompatible && index <= previousMatchIndex && possibleMatchIndex === undefined) {
|
17429
|
+
possibleMatchIndex = index;
|
17430
|
+
return false;
|
17431
|
+
}
|
17432
|
+
return isCompatible;
|
17309
17433
|
});
|
17434
|
+
if (matchIndex < 0 && possibleMatchIndex !== undefined) {
|
17435
|
+
matchIndex = possibleMatchIndex;
|
17436
|
+
}
|
17310
17437
|
if (matchIndex < 0) {
|
17311
|
-
|
17312
|
-
return false;
|
17438
|
+
continue;
|
17313
17439
|
}
|
17314
17440
|
if (matchIndex < previousMatchIndex) {
|
17315
17441
|
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadOrder());
|
17316
17442
|
return false;
|
17317
17443
|
}
|
17318
17444
|
previousMatchIndex = matchIndex;
|
17319
|
-
|
17445
|
+
}
|
17446
|
+
if (previousMatchIndex < baseOverloads.length - 1) {
|
17447
|
+
// We didn't find matches for all of the base overloads.
|
17448
|
+
diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideOverloadNoMatch());
|
17449
|
+
return false;
|
17320
17450
|
}
|
17321
17451
|
return true;
|
17322
17452
|
}
|
@@ -17586,9 +17716,17 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17586
17716
|
}
|
17587
17717
|
}
|
17588
17718
|
// Verify that one or the other method doesn't contain a ParamSpec.
|
17589
|
-
if (
|
17590
|
-
|
17591
|
-
|
17719
|
+
if (baseParamDetails.paramSpec && !overrideParamDetails.paramSpec) {
|
17720
|
+
// If the override uses an `*args: Any, **kwargs: Any` signature, we
|
17721
|
+
// will allow this as an acceptable overload for a `*args: P.args, **kwargs: P.kwargs`.
|
17722
|
+
const overrideHasArgsKwargs = overrideParamDetails.argsIndex !== undefined &&
|
17723
|
+
(0, types_1.isAnyOrUnknown)(overrideParamDetails.params[overrideParamDetails.argsIndex].type) &&
|
17724
|
+
overrideParamDetails.kwargsIndex !== undefined &&
|
17725
|
+
(0, types_1.isAnyOrUnknown)(overrideParamDetails.params[overrideParamDetails.kwargsIndex].type);
|
17726
|
+
if (!overrideHasArgsKwargs) {
|
17727
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecMissingInOverride());
|
17728
|
+
canOverride = false;
|
17729
|
+
}
|
17592
17730
|
}
|
17593
17731
|
// Now check the return type.
|
17594
17732
|
const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
|