@zzzen/pyright-internal 1.2.0-dev.20250126 → 1.2.0-dev.20250209
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/binder.js +18 -11
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -0
- package/dist/analyzer/checker.js +23 -5
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/codeFlowEngine.js +2 -2
- package/dist/analyzer/codeFlowEngine.js.map +1 -1
- package/dist/analyzer/dataClasses.js +4 -4
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/parameterUtils.d.ts +4 -1
- package/dist/analyzer/parameterUtils.js +7 -3
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +14 -0
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/tuples.d.ts +1 -0
- package/dist/analyzer/tuples.js +34 -0
- package/dist/analyzer/tuples.js.map +1 -1
- package/dist/analyzer/typeEvaluator.js +193 -120
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +2 -1
- package/dist/analyzer/typeUtils.js +8 -2
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typedDicts.js +25 -10
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/common/envVarUtils.js +4 -0
- package/dist/common/envVarUtils.js.map +1 -1
- package/dist/localization/localize.d.ts +4 -1
- package/dist/localization/localize.js +2 -1
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.cs.json +8 -4
- package/dist/localization/package.nls.de.json +8 -4
- package/dist/localization/package.nls.en-us.json +7 -3
- package/dist/localization/package.nls.es.json +8 -4
- package/dist/localization/package.nls.fr.json +8 -4
- package/dist/localization/package.nls.it.json +8 -4
- package/dist/localization/package.nls.ja.json +8 -4
- package/dist/localization/package.nls.ko.json +8 -4
- package/dist/localization/package.nls.pl.json +8 -4
- package/dist/localization/package.nls.pt-br.json +8 -4
- package/dist/localization/package.nls.qps-ploc.json +4 -0
- package/dist/localization/package.nls.ru.json +8 -4
- package/dist/localization/package.nls.tr.json +8 -4
- package/dist/localization/package.nls.zh-cn.json +8 -4
- package/dist/localization/package.nls.zh-tw.json +8 -4
- package/dist/parser/parser.js +6 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +9 -7
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/tests/fourslash/completions.vardecls.fourslash.js +2 -1
- package/dist/tests/fourslash/completions.vardecls.fourslash.js.map +1 -1
- package/dist/tests/fourslash/hover.async.fourslash.js +1 -1
- package/dist/tests/fourslash/hover.async.fourslash.js.map +1 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.d.ts +2 -1
- package/dist/tests/harness/fourslash/fourSlashTypes.js +2 -0
- package/dist/tests/harness/fourslash/fourSlashTypes.js.map +1 -1
- package/dist/tests/harness/fourslash/testState.js +7 -0
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +1 -1
- package/dist/tests/typeEvaluator2.test.js +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -3
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +3 -3
- package/dist/tests/typeEvaluator6.test.js +2 -2
- package/dist/tests/typeEvaluator7.test.js +5 -1
- package/dist/tests/typeEvaluator7.test.js.map +1 -1
- package/package.json +1 -1
@@ -61,6 +61,7 @@ const constraintSolver_1 = require("./constraintSolver");
|
|
61
61
|
const constraintTracker_1 = require("./constraintTracker");
|
62
62
|
const constructors_1 = require("./constructors");
|
63
63
|
const dataClasses_1 = require("./dataClasses");
|
64
|
+
const declaration_1 = require("./declaration");
|
64
65
|
const declarationUtils_1 = require("./declarationUtils");
|
65
66
|
const decorators_1 = require("./decorators");
|
66
67
|
const enums_1 = require("./enums");
|
@@ -81,6 +82,7 @@ const tuples_1 = require("./tuples");
|
|
81
82
|
const typeCacheUtils_1 = require("./typeCacheUtils");
|
82
83
|
const typedDicts_1 = require("./typedDicts");
|
83
84
|
const typeEvaluatorTypes_1 = require("./typeEvaluatorTypes");
|
85
|
+
const typeGuards_1 = require("./typeGuards");
|
84
86
|
const TypePrinter = __importStar(require("./typePrinter"));
|
85
87
|
const types_1 = require("./types");
|
86
88
|
const typeUtils_1 = require("./typeUtils");
|
@@ -146,9 +148,12 @@ const maxDeclarationsToUseForInference = 64;
|
|
146
148
|
// Maximum number of times to attempt effective type evaluation
|
147
149
|
// of a variable that has no type declaration.
|
148
150
|
const maxEffectiveTypeEvaluationAttempts = 16;
|
149
|
-
// Maximum number of combinatoric
|
151
|
+
// Maximum number of combinatoric argument type expansions allowed
|
150
152
|
// when resolving an overload.
|
151
|
-
const
|
153
|
+
const maxTotalOverloadArgTypeExpansionCount = 256;
|
154
|
+
// Maximum size of an enum that will be expanded during overload
|
155
|
+
// argument type expansion.
|
156
|
+
const maxSingleOverloadArgTypeExpansionCount = 64;
|
152
157
|
// Maximum number of recursive function return type inference attempts
|
153
158
|
// that can be concurrently pending before we give up.
|
154
159
|
const maxInferFunctionReturnRecursionCount = 12;
|
@@ -1468,7 +1473,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1468
1473
|
!types_1.ClassType.isBuiltIn(metaclass, 'type') &&
|
1469
1474
|
!types_1.ClassType.isSameGenericClass(metaclass, objectType)) {
|
1470
1475
|
const descMemberInfo = getTypeOfClassMemberName(errorNode, metaclass, memberName, usage,
|
1471
|
-
/* diag */ undefined, flags | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */, objectType, recursionCount);
|
1476
|
+
/* diag */ undefined, flags | 512 /* MemberAccessFlags.SkipAttributeAccessOverride */ | 4096 /* MemberAccessFlags.SkipTypedDictEntries */, objectType, recursionCount);
|
1472
1477
|
if (descMemberInfo) {
|
1473
1478
|
const isProperty = (0, types_1.isClassInstance)(descMemberInfo.type) && types_1.ClassType.isPropertyClass(descMemberInfo.type);
|
1474
1479
|
if ((0, typeUtils_1.isDescriptorInstance)(descMemberInfo.type, /* requireSetter */ true) || isProperty) {
|
@@ -1478,7 +1483,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
1478
1483
|
}
|
1479
1484
|
let subDiag;
|
1480
1485
|
if (!skipObjectTypeLookup) {
|
1481
|
-
let effectiveFlags = flags
|
1486
|
+
let effectiveFlags = flags | 4096 /* MemberAccessFlags.SkipTypedDictEntries */;
|
1482
1487
|
if (objectTypeIsInstantiable) {
|
1483
1488
|
effectiveFlags |=
|
1484
1489
|
16 /* MemberAccessFlags.SkipInstanceMembers */ |
|
@@ -2908,7 +2913,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2908
2913
|
case 54 /* ParseNodeType.TypeAnnotation */: {
|
2909
2914
|
let annotationType = getTypeOfAnnotation(target.d.annotation, {
|
2910
2915
|
varTypeAnnotation: true,
|
2911
|
-
allowFinal:
|
2916
|
+
allowFinal: isFinalAllowedForAssignmentTarget(target.d.valueExpr),
|
2912
2917
|
allowClassVar: isClassVarAllowedForAssignmentTarget(target.d.valueExpr),
|
2913
2918
|
});
|
2914
2919
|
if (annotationType) {
|
@@ -2935,12 +2940,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2935
2940
|
break;
|
2936
2941
|
}
|
2937
2942
|
case 56 /* ParseNodeType.Unpack */: {
|
2938
|
-
|
2939
|
-
|
2940
|
-
|
2941
|
-
|
2942
|
-
}, ignoreEmptyContainers, srcExpr);
|
2943
|
-
}
|
2943
|
+
assignTypeToExpression(target.d.expr, {
|
2944
|
+
type: getBuiltInObject(target.d.expr, 'list', [typeResult.type]),
|
2945
|
+
isIncomplete: typeResult.isIncomplete,
|
2946
|
+
}, srcExpr, ignoreEmptyContainers, allowAssignmentToFinalVar, expectedTypeDiagAddendum);
|
2944
2947
|
break;
|
2945
2948
|
}
|
2946
2949
|
case 0 /* ParseNodeType.Error */: {
|
@@ -2960,16 +2963,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
2960
2963
|
}
|
2961
2964
|
}
|
2962
2965
|
function isClassVarAllowedForAssignmentTarget(targetNode) {
|
2966
|
+
// ClassVar is allowed only in a class body.
|
2963
2967
|
const classNode = ParseTreeUtils.getEnclosingClass(targetNode, /* stopAtFunction */ true);
|
2964
2968
|
if (!classNode) {
|
2965
2969
|
return false;
|
2966
2970
|
}
|
2967
2971
|
// ClassVar is not allowed in a TypedDict or a NamedTuple class.
|
2972
|
+
return !isInTypedDictOrNamedTuple(classNode);
|
2973
|
+
}
|
2974
|
+
function isFinalAllowedForAssignmentTarget(targetNode) {
|
2975
|
+
const classNode = ParseTreeUtils.getEnclosingClass(targetNode, /* stopAtFunction */ true);
|
2976
|
+
// Final is not allowed in the body of a TypedDict or NamedTuple class.
|
2977
|
+
if (classNode && isInTypedDictOrNamedTuple(classNode)) {
|
2978
|
+
return false;
|
2979
|
+
}
|
2980
|
+
return ParseTreeUtils.isFinalAllowedForAssignmentTarget(targetNode);
|
2981
|
+
}
|
2982
|
+
function isInTypedDictOrNamedTuple(classNode) {
|
2968
2983
|
const classType = getTypeOfClass(classNode)?.classType;
|
2969
2984
|
if (!classType) {
|
2970
2985
|
return false;
|
2971
2986
|
}
|
2972
|
-
return
|
2987
|
+
return types_1.ClassType.isTypedDictClass(classType) || !!classType.shared.namedTupleEntries;
|
2973
2988
|
}
|
2974
2989
|
function verifyRaiseExceptionType(node, allowNone) {
|
2975
2990
|
const baseExceptionType = getBuiltInType(node, 'BaseException');
|
@@ -6718,9 +6733,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6718
6733
|
});
|
6719
6734
|
});
|
6720
6735
|
}
|
6721
|
-
expandedArgTypes =
|
6736
|
+
expandedArgTypes = expandArgTypes(contextFreeArgTypes, expandedArgTypes);
|
6722
6737
|
// Check for combinatoric explosion and break out of loop.
|
6723
|
-
if (!expandedArgTypes || expandedArgTypes.length >
|
6738
|
+
if (!expandedArgTypes || expandedArgTypes.length > maxTotalOverloadArgTypeExpansionCount) {
|
6724
6739
|
break;
|
6725
6740
|
}
|
6726
6741
|
}
|
@@ -6739,12 +6754,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6739
6754
|
return { argumentErrors: true, isTypeIncomplete, overloadsUsedForCall: [] };
|
6740
6755
|
}
|
6741
6756
|
// Replaces each item in the expandedArgTypes with n items where n is
|
6742
|
-
// the number of subtypes in a union
|
6743
|
-
// represents the types of the arguments
|
6744
|
-
// type inference (i.e. without the help of
|
6745
|
-
// expected type). If the function returns
|
6746
|
-
// all
|
6747
|
-
|
6757
|
+
// the number of subtypes in a union or other expandable type.
|
6758
|
+
// The contextFreeArgTypes parameter represents the types of the arguments
|
6759
|
+
// evaluated with no bidirectional type inference (i.e. without the help of
|
6760
|
+
// the corresponding parameter's expected type). If the function returns
|
6761
|
+
// undefined, that indicates that all types have been expanded, and no
|
6762
|
+
// more expansion is possible.
|
6763
|
+
function expandArgTypes(contextFreeArgTypes, expandedArgTypes) {
|
6748
6764
|
// Find the rightmost already-expanded argument.
|
6749
6765
|
let indexToExpand = contextFreeArgTypes.length - 1;
|
6750
6766
|
while (indexToExpand >= 0 && !expandedArgTypes[0][indexToExpand]) {
|
@@ -6755,28 +6771,24 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6755
6771
|
if (indexToExpand >= contextFreeArgTypes.length) {
|
6756
6772
|
return undefined;
|
6757
6773
|
}
|
6758
|
-
let
|
6774
|
+
let expandedTypes;
|
6759
6775
|
while (indexToExpand < contextFreeArgTypes.length) {
|
6760
6776
|
// Is this a union type? If so, we can expand it.
|
6761
6777
|
const argType = contextFreeArgTypes[indexToExpand];
|
6762
|
-
|
6763
|
-
|
6764
|
-
break;
|
6765
|
-
}
|
6766
|
-
else if ((0, types_1.isTypeVar)(argType) && types_1.TypeVarType.hasConstraints(argType)) {
|
6767
|
-
unionToExpand = makeTopLevelTypeVarsConcrete(argType);
|
6778
|
+
expandedTypes = expandArgType(argType);
|
6779
|
+
if (expandedTypes) {
|
6768
6780
|
break;
|
6769
6781
|
}
|
6770
6782
|
indexToExpand++;
|
6771
6783
|
}
|
6772
6784
|
// We have nothing left to expand.
|
6773
|
-
if (!
|
6785
|
+
if (!expandedTypes) {
|
6774
6786
|
return undefined;
|
6775
6787
|
}
|
6776
6788
|
// Expand entry indexToExpand.
|
6777
6789
|
const newExpandedArgTypes = [];
|
6778
6790
|
expandedArgTypes.forEach((preExpandedTypes) => {
|
6779
|
-
|
6791
|
+
expandedTypes.forEach((subtype) => {
|
6780
6792
|
const expandedTypes = [...preExpandedTypes];
|
6781
6793
|
expandedTypes[indexToExpand] = subtype;
|
6782
6794
|
newExpandedArgTypes.push(expandedTypes);
|
@@ -6784,6 +6796,29 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
6784
6796
|
});
|
6785
6797
|
return newExpandedArgTypes;
|
6786
6798
|
}
|
6799
|
+
function expandArgType(type) {
|
6800
|
+
const expandedTypes = [];
|
6801
|
+
// Expand any top-level type variables with constraints.
|
6802
|
+
type = makeTopLevelTypeVarsConcrete(type);
|
6803
|
+
(0, typeUtils_1.doForEachSubtype)(type, (subtype) => {
|
6804
|
+
if ((0, types_1.isClassInstance)(subtype)) {
|
6805
|
+
// Expand any bool or Enum literals.
|
6806
|
+
const expandedLiteralTypes = (0, typeGuards_1.enumerateLiteralsForType)(evaluatorInterface, subtype);
|
6807
|
+
if (expandedLiteralTypes && expandedLiteralTypes.length <= maxSingleOverloadArgTypeExpansionCount) {
|
6808
|
+
(0, collectionUtils_1.appendArray)(expandedTypes, expandedLiteralTypes);
|
6809
|
+
return;
|
6810
|
+
}
|
6811
|
+
// Expand any fixed-size tuples.
|
6812
|
+
const expandedTuples = (0, tuples_1.expandTuple)(subtype, maxSingleOverloadArgTypeExpansionCount);
|
6813
|
+
if (expandedTuples) {
|
6814
|
+
(0, collectionUtils_1.appendArray)(expandedTypes, expandedTuples);
|
6815
|
+
return;
|
6816
|
+
}
|
6817
|
+
}
|
6818
|
+
expandedTypes.push(subtype);
|
6819
|
+
});
|
6820
|
+
return expandedTypes.length > 1 ? expandedTypes : undefined;
|
6821
|
+
}
|
6787
6822
|
// Validates that the arguments can be assigned to the call's parameter
|
6788
6823
|
// list, specializes the call based on arg types, and returns the
|
6789
6824
|
// specialized type of the return value. If it detects an error along
|
@@ -7337,7 +7372,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7337
7372
|
// This logic is based on PEP 3102: https://www.python.org/dev/peps/pep-3102/
|
7338
7373
|
function matchArgsToParams(errorNode, argList, typeResult, overloadIndex) {
|
7339
7374
|
const overload = typeResult.type;
|
7340
|
-
const paramDetails = (0, parameterUtils_1.getParamListDetails)(overload);
|
7375
|
+
const paramDetails = (0, parameterUtils_1.getParamListDetails)(overload, { disallowExtraKwargsForTd: true });
|
7341
7376
|
const paramSpec = types_1.FunctionType.getParamSpecFromArgsKwargs(overload);
|
7342
7377
|
let argIndex = 0;
|
7343
7378
|
let matchedUnpackedListOfUnknownLength = false;
|
@@ -7811,8 +7846,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
7811
7846
|
const kwargsParam = paramDetails.params[paramDetails.kwargsIndex];
|
7812
7847
|
validateArgTypeParams.push({
|
7813
7848
|
paramCategory: 2 /* ParamCategory.KwargsDict */,
|
7814
|
-
paramType: kwargsParam.
|
7815
|
-
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(kwargsParam.
|
7849
|
+
paramType: kwargsParam.type,
|
7850
|
+
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(kwargsParam.type),
|
7816
7851
|
argument: {
|
7817
7852
|
argCategory: 2 /* ArgCategory.UnpackedDictionary */,
|
7818
7853
|
typeResult: { type: extraItemsType },
|
@@ -10190,7 +10225,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
10190
10225
|
return generatorTypeArgs.length >= 2 ? generatorTypeArgs[2] : types_1.UnknownType.create();
|
10191
10226
|
}
|
10192
10227
|
// Handle old-style (pre-await) Coroutines as a special case.
|
10193
|
-
if ((0, types_1.isClassInstance)(yieldFromSubtype) &&
|
10228
|
+
if ((0, types_1.isClassInstance)(yieldFromSubtype) &&
|
10229
|
+
types_1.ClassType.isBuiltIn(yieldFromSubtype, ['Coroutine', 'CoroutineType'])) {
|
10194
10230
|
return types_1.UnknownType.create();
|
10195
10231
|
}
|
10196
10232
|
// Handle simple iterables.
|
@@ -12034,6 +12070,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12034
12070
|
if (fileInfo.isStubFile) {
|
12035
12071
|
exprFlags |= 4 /* EvalFlags.ForwardRefs */;
|
12036
12072
|
}
|
12073
|
+
let sawClosedOrExtraItems = false;
|
12037
12074
|
node.d.arguments.forEach((arg) => {
|
12038
12075
|
// Ignore unpacked arguments.
|
12039
12076
|
if (arg.d.argCategory === 2 /* ArgCategory.UnpackedDictionary */) {
|
@@ -12216,15 +12253,22 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12216
12253
|
else if (arg.d.name.d.value === 'total' && !constArgValue) {
|
12217
12254
|
classType.shared.flags |= 32 /* ClassTypeFlags.CanOmitDictValues */;
|
12218
12255
|
}
|
12219
|
-
else if (arg.d.name.d.value === 'closed'
|
12220
|
-
|
12221
|
-
|
12222
|
-
|
12223
|
-
|
12224
|
-
|
12225
|
-
|
12256
|
+
else if (arg.d.name.d.value === 'closed') {
|
12257
|
+
if (constArgValue) {
|
12258
|
+
// This is an experimental feature because PEP 728 hasn't been accepted yet.
|
12259
|
+
if (AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.enableExperimentalFeatures) {
|
12260
|
+
classType.shared.flags |=
|
12261
|
+
8 /* ClassTypeFlags.TypedDictMarkedClosed */ |
|
12262
|
+
16 /* ClassTypeFlags.TypedDictEffectivelyClosed */;
|
12263
|
+
if (classType.shared.typedDictExtraItemsExpr) {
|
12264
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12265
|
+
}
|
12226
12266
|
}
|
12227
12267
|
}
|
12268
|
+
if (sawClosedOrExtraItems) {
|
12269
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
|
12270
|
+
}
|
12271
|
+
sawClosedOrExtraItems = true;
|
12228
12272
|
}
|
12229
12273
|
}
|
12230
12274
|
else if (arg.d.name.d.value === 'extra_items') {
|
@@ -12238,6 +12282,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
12238
12282
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), classType.shared.typedDictExtraItemsExpr);
|
12239
12283
|
}
|
12240
12284
|
}
|
12285
|
+
if (sawClosedOrExtraItems) {
|
12286
|
+
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictExtraItemsClosed(), arg.d.valueExpr);
|
12287
|
+
}
|
12288
|
+
sawClosedOrExtraItems = true;
|
12241
12289
|
}
|
12242
12290
|
else {
|
12243
12291
|
addDiagnostic(diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.LocMessage.typedDictInitsubclassParameter().format({ name: arg.d.name.d.value }), arg);
|
@@ -13517,8 +13565,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13517
13565
|
}
|
13518
13566
|
}
|
13519
13567
|
if (!awaitableReturnType || !isGenerator) {
|
13520
|
-
// Wrap in either an Awaitable or a
|
13521
|
-
const awaitableType =
|
13568
|
+
// Wrap in either an Awaitable or a CoroutineType, which is a subclass of Awaitable.
|
13569
|
+
const awaitableType = useCoroutine ? getTypesType(node, 'CoroutineType') : getTypingType(node, 'Awaitable');
|
13522
13570
|
if (awaitableType && (0, types_1.isInstantiableClass)(awaitableType)) {
|
13523
13571
|
awaitableReturnType = types_1.ClassType.cloneAsInstance(types_1.ClassType.specialize(awaitableType, useCoroutine ? [types_1.AnyType.create(), types_1.AnyType.create(), returnType] : [returnType]));
|
13524
13572
|
}
|
@@ -13637,7 +13685,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
13637
13685
|
isYieldResultUsed = true;
|
13638
13686
|
const iteratorTypeResult = getTypeOfExpression(yieldNode.d.expr);
|
13639
13687
|
if ((0, types_1.isClassInstance)(iteratorTypeResult.type) &&
|
13640
|
-
types_1.ClassType.isBuiltIn(iteratorTypeResult.type, 'Coroutine')) {
|
13688
|
+
types_1.ClassType.isBuiltIn(iteratorTypeResult.type, ['Coroutine', 'CoroutineType'])) {
|
13641
13689
|
const yieldType = iteratorTypeResult.type.priv.typeArgs &&
|
13642
13690
|
iteratorTypeResult.type.priv.typeArgs.length > 0
|
13643
13691
|
? iteratorTypeResult.type.priv.typeArgs[0]
|
@@ -14077,7 +14125,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14077
14125
|
else {
|
14078
14126
|
const annotationType = getTypeOfAnnotation(node.d.annotation, {
|
14079
14127
|
varTypeAnnotation: true,
|
14080
|
-
allowFinal:
|
14128
|
+
allowFinal: isFinalAllowedForAssignmentTarget(node.d.valueExpr),
|
14081
14129
|
allowClassVar: isClassVarAllowedForAssignmentTarget(node.d.valueExpr),
|
14082
14130
|
});
|
14083
14131
|
writeTypeCache(node.d.valueExpr, { type: annotationType }, 0 /* EvalFlags.None */);
|
@@ -14189,7 +14237,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
14189
14237
|
if (annotationNode === annotationParent.d.annotationComment) {
|
14190
14238
|
getTypeOfAnnotation(annotationNode, {
|
14191
14239
|
varTypeAnnotation: true,
|
14192
|
-
allowFinal:
|
14240
|
+
allowFinal: isFinalAllowedForAssignmentTarget(annotationParent.d.leftExpr),
|
14193
14241
|
allowClassVar: isClassVarAllowedForAssignmentTarget(annotationParent.d.leftExpr),
|
14194
14242
|
});
|
14195
14243
|
}
|
@@ -15734,7 +15782,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
15734
15782
|
? declaration.node.parent
|
15735
15783
|
: declaration.node;
|
15736
15784
|
const allowClassVar = isClassVarAllowedForAssignmentTarget(declNode);
|
15737
|
-
const allowFinal =
|
15785
|
+
const allowFinal = isFinalAllowedForAssignmentTarget(declNode);
|
15738
15786
|
const allowRequired = ParseTreeUtils.isRequiredAllowedForAssignmentTarget(declNode) ||
|
15739
15787
|
!!declaration.isInInlinedTypedDict;
|
15740
15788
|
declaredType = getTypeOfAnnotation(typeAnnotationNode, {
|
@@ -16298,6 +16346,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
16298
16346
|
}
|
16299
16347
|
declsToConsider.push(resolvedDecl);
|
16300
16348
|
});
|
16349
|
+
// If all of the decls come from augmented assignments, we won't be able to
|
16350
|
+
// determine its type. At least one declaration must be a simple assignment.
|
16351
|
+
if (declsToConsider.every((decl) => (0, declaration_1.isVariableDeclaration)(decl) &&
|
16352
|
+
ParseTreeUtils.isNodeContainedWithinNodeType(decl.node, 5 /* ParseNodeType.AugmentedAssignment */))) {
|
16353
|
+
declsToConsider.splice(0);
|
16354
|
+
}
|
16301
16355
|
const result = getTypeOfSymbolForDecls(symbol, declsToConsider, effectiveTypeCacheKey);
|
16302
16356
|
result.includesVariableDecl = includesVariableDecl;
|
16303
16357
|
result.includesIllegalTypeAliasDecl = includesIllegalTypeAliasDecl;
|
@@ -18748,66 +18802,76 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18748
18802
|
}
|
18749
18803
|
if (srcStartOfNamed >= 0) {
|
18750
18804
|
srcParamDetails.params.forEach((srcParamInfo, index) => {
|
18751
|
-
if (index
|
18752
|
-
|
18753
|
-
|
18754
|
-
|
18755
|
-
|
18756
|
-
|
18757
|
-
|
18758
|
-
|
18759
|
-
|
18760
|
-
|
18761
|
-
|
18762
|
-
|
18763
|
-
|
18764
|
-
|
18765
|
-
|
18766
|
-
|
18767
|
-
|
18768
|
-
// Make sure we can assign the type to the Kwargs.
|
18769
|
-
if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamType, destParamDetails.params[destParamDetails.kwargsIndex].index, diag?.createAddendum(), constraints, flags, recursionCount)) {
|
18770
|
-
canAssign = false;
|
18771
|
-
}
|
18772
|
-
}
|
18773
|
-
else if (srcParamInfo.defaultType) {
|
18774
|
-
// Assign default arg values in case they are needed for
|
18775
|
-
// populating TypeVar constraints.
|
18776
|
-
const defaultArgType = srcParamInfo.defaultType ?? srcParamInfo.defaultType;
|
18777
|
-
if (defaultArgType &&
|
18778
|
-
!assignType(srcParamInfo.type, defaultArgType, diag?.createAddendum(), constraints, flags, recursionCount)) {
|
18779
|
-
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) === 0) {
|
18780
|
-
canAssign = false;
|
18781
|
-
}
|
18782
|
-
}
|
18783
|
-
}
|
18805
|
+
if (index < srcStartOfNamed) {
|
18806
|
+
return;
|
18807
|
+
}
|
18808
|
+
if (!srcParamInfo.param.name ||
|
18809
|
+
srcParamInfo.param.category !== 0 /* ParamCategory.Simple */ ||
|
18810
|
+
srcParamInfo.kind === parameterUtils_1.ParamKind.Positional) {
|
18811
|
+
return;
|
18812
|
+
}
|
18813
|
+
const destParamInfo = destParamMap.get(srcParamInfo.param.name);
|
18814
|
+
const paramDiag = diag?.createAddendum();
|
18815
|
+
const srcParamType = srcParamInfo.type;
|
18816
|
+
if (!destParamInfo) {
|
18817
|
+
if (destParamDetails.kwargsIndex === undefined && !srcParamInfo.defaultType) {
|
18818
|
+
if (paramDiag) {
|
18819
|
+
paramDiag.addMessage(localize_1.LocAddendum.namedParamMissingInDest().format({
|
18820
|
+
name: srcParamInfo.param.name,
|
18821
|
+
}));
|
18784
18822
|
}
|
18785
|
-
|
18786
|
-
|
18787
|
-
|
18788
|
-
|
18789
|
-
|
18790
|
-
|
18791
|
-
|
18792
|
-
|
18793
|
-
|
18794
|
-
|
18795
|
-
|
18796
|
-
|
18797
|
-
|
18798
|
-
|
18799
|
-
|
18800
|
-
}
|
18801
|
-
if (destParamInfo.defaultType && !srcParamInfo.defaultType) {
|
18802
|
-
diag?.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
18803
|
-
name: srcParamInfo.param.name,
|
18804
|
-
}));
|
18823
|
+
canAssign = false;
|
18824
|
+
}
|
18825
|
+
else if (destParamDetails.kwargsIndex !== undefined) {
|
18826
|
+
// Make sure we can assign the type to the Kwargs.
|
18827
|
+
if (!assignParam(destParamDetails.params[destParamDetails.kwargsIndex].type, srcParamType, destParamDetails.params[destParamDetails.kwargsIndex].index, diag?.createAddendum(), constraints, flags, recursionCount)) {
|
18828
|
+
canAssign = false;
|
18829
|
+
}
|
18830
|
+
}
|
18831
|
+
else if (srcParamInfo.defaultType) {
|
18832
|
+
// Assign default arg values in case they are needed for
|
18833
|
+
// populating TypeVar constraints.
|
18834
|
+
const defaultArgType = srcParamInfo.defaultType ?? srcParamInfo.defaultType;
|
18835
|
+
if (defaultArgType &&
|
18836
|
+
!assignType(srcParamInfo.type, defaultArgType, diag?.createAddendum(), constraints, flags, recursionCount)) {
|
18837
|
+
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) === 0) {
|
18805
18838
|
canAssign = false;
|
18806
18839
|
}
|
18807
|
-
destParamMap.delete(srcParamInfo.param.name);
|
18808
18840
|
}
|
18809
18841
|
}
|
18842
|
+
return;
|
18843
|
+
}
|
18844
|
+
// If we're performing a partial overload match and both the source
|
18845
|
+
// and dest parameters provide defaults, assume that there could
|
18846
|
+
// be a match.
|
18847
|
+
if (srcParamInfo.defaultType && destParamInfo.defaultType) {
|
18848
|
+
if ((flags & 32 /* AssignTypeFlags.PartialOverloadOverlap */) !== 0) {
|
18849
|
+
destParamMap.delete(srcParamInfo.param.name);
|
18850
|
+
return;
|
18851
|
+
}
|
18852
|
+
}
|
18853
|
+
const destParamType = destParamInfo.type;
|
18854
|
+
const specializedDestParamType = constraints
|
18855
|
+
? solveAndApplyConstraints(destParamType, constraints)
|
18856
|
+
: destParamType;
|
18857
|
+
if (!assignParam(destParamInfo.type, srcParamType,
|
18858
|
+
/* paramIndex */ undefined, paramDiag?.createAddendum(), constraints, flags, recursionCount)) {
|
18859
|
+
if (paramDiag) {
|
18860
|
+
paramDiag.addMessage(localize_1.LocAddendum.namedParamTypeMismatch().format({
|
18861
|
+
name: srcParamInfo.param.name,
|
18862
|
+
sourceType: printType(specializedDestParamType),
|
18863
|
+
destType: printType(srcParamType),
|
18864
|
+
}));
|
18865
|
+
}
|
18866
|
+
canAssign = false;
|
18810
18867
|
}
|
18868
|
+
if (destParamInfo.defaultType && !srcParamInfo.defaultType) {
|
18869
|
+
diag?.createAddendum().addMessage(localize_1.LocAddendum.functionParamDefaultMissing().format({
|
18870
|
+
name: srcParamInfo.param.name,
|
18871
|
+
}));
|
18872
|
+
canAssign = false;
|
18873
|
+
}
|
18874
|
+
destParamMap.delete(srcParamInfo.param.name);
|
18811
18875
|
});
|
18812
18876
|
}
|
18813
18877
|
// See if there are any unmatched named parameters.
|
@@ -18903,26 +18967,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions, wrapWithLogger) {
|
|
18903
18967
|
if (remainingParams.length > 0 ||
|
18904
18968
|
!effectiveSrcParamSpec ||
|
18905
18969
|
!(0, types_1.isTypeSame)(effectiveSrcParamSpec, effectiveDestParamSpec, { ignoreTypeFlags: true })) {
|
18906
|
-
const
|
18907
|
-
|
18908
|
-
|
18909
|
-
|
18910
|
-
|
18911
|
-
|
18912
|
-
types_1.FunctionType.
|
18913
|
-
|
18914
|
-
|
18915
|
-
|
18916
|
-
|
18917
|
-
|
18918
|
-
|
18919
|
-
|
18920
|
-
|
18921
|
-
if (
|
18922
|
-
|
18923
|
-
|
18924
|
-
|
18925
|
-
|
18970
|
+
const effectiveSrcPosCount = isContra ? destPositionalCount : srcPositionalCount;
|
18971
|
+
const effectiveDestPosCount = isContra ? srcPositionalCount : destPositionalCount;
|
18972
|
+
// If the src and dest both have ParamSpecs but the src has additional positional
|
18973
|
+
// parameters that have not been matched to dest positional parameters (probably due
|
18974
|
+
// to a Concatenate), don't attempt to assign the remaining parameters to the ParamSpec.
|
18975
|
+
if (!effectiveSrcParamSpec || effectiveSrcPosCount >= effectiveDestPosCount) {
|
18976
|
+
const remainingFunction = types_1.FunctionType.createInstance('', '', '', effectiveSrcType.shared.flags | 64 /* FunctionTypeFlags.SynthesizedMethod */, effectiveSrcType.shared.docString);
|
18977
|
+
remainingFunction.shared.deprecatedMessage = effectiveSrcType.shared.deprecatedMessage;
|
18978
|
+
remainingFunction.shared.typeVarScopeId = effectiveSrcType.shared.typeVarScopeId;
|
18979
|
+
remainingFunction.priv.constructorTypeVarScopeId =
|
18980
|
+
effectiveSrcType.priv.constructorTypeVarScopeId;
|
18981
|
+
remainingFunction.shared.methodClass = effectiveSrcType.shared.methodClass;
|
18982
|
+
remainingParams.forEach((param) => {
|
18983
|
+
types_1.FunctionType.addParam(remainingFunction, param);
|
18984
|
+
});
|
18985
|
+
if (effectiveSrcParamSpec) {
|
18986
|
+
types_1.FunctionType.addParamSpecVariadics(remainingFunction, (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec));
|
18987
|
+
}
|
18988
|
+
if (!assignType(effectiveDestParamSpec, remainingFunction,
|
18989
|
+
/* diag */ undefined, constraints, flags)) {
|
18990
|
+
// If we couldn't assign the function to the ParamSpec, see if we can
|
18991
|
+
// assign only the ParamSpec. This is possible if there were no
|
18992
|
+
// remaining parameters.
|
18993
|
+
if (remainingParams.length > 0 ||
|
18994
|
+
!effectiveSrcParamSpec ||
|
18995
|
+
!assignType((0, typeUtils_1.convertToInstance)(effectiveDestParamSpec), (0, typeUtils_1.convertToInstance)(effectiveSrcParamSpec),
|
18996
|
+
/* diag */ undefined, constraints, flags)) {
|
18997
|
+
canAssign = false;
|
18998
|
+
}
|
18926
18999
|
}
|
18927
19000
|
}
|
18928
19001
|
}
|