@zzzen/pyright-internal 1.2.0-dev.20230514 → 1.2.0-dev.20230528
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer/analyzerFileInfo.d.ts +1 -0
- package/dist/analyzer/analyzerFileInfo.js +4 -3
- package/dist/analyzer/analyzerFileInfo.js.map +1 -1
- package/dist/analyzer/backgroundAnalysisProgram.d.ts +17 -15
- package/dist/analyzer/backgroundAnalysisProgram.js +43 -53
- package/dist/analyzer/backgroundAnalysisProgram.js.map +1 -1
- package/dist/analyzer/binder.d.ts +0 -2
- package/dist/analyzer/binder.js +2 -20
- package/dist/analyzer/binder.js.map +1 -1
- package/dist/analyzer/checker.d.ts +1 -1
- package/dist/analyzer/checker.js +65 -32
- package/dist/analyzer/checker.js.map +1 -1
- package/dist/analyzer/commentUtils.js +15 -16
- package/dist/analyzer/commentUtils.js.map +1 -1
- package/dist/analyzer/constraintSolver.js +6 -2
- package/dist/analyzer/constraintSolver.js.map +1 -1
- package/dist/analyzer/constructorTransform.js +8 -4
- package/dist/analyzer/constructorTransform.js.map +1 -1
- package/dist/analyzer/constructors.js +128 -130
- package/dist/analyzer/constructors.js.map +1 -1
- package/dist/analyzer/dataClasses.js +4 -1
- package/dist/analyzer/dataClasses.js.map +1 -1
- package/dist/analyzer/declarationUtils.js +1 -0
- package/dist/analyzer/declarationUtils.js.map +1 -1
- package/dist/analyzer/docStringConversion.js +1 -1
- package/dist/analyzer/enums.js +1 -1
- package/dist/analyzer/enums.js.map +1 -1
- package/dist/analyzer/importResolver.d.ts +4 -4
- package/dist/analyzer/importResolver.js +46 -40
- package/dist/analyzer/importResolver.js.map +1 -1
- package/dist/analyzer/importResult.d.ts +2 -2
- package/dist/analyzer/importStatementUtils.js +2 -2
- package/dist/analyzer/importStatementUtils.js.map +1 -1
- package/dist/analyzer/packageTypeVerifier.js +1 -1
- package/dist/analyzer/packageTypeVerifier.js.map +1 -1
- package/dist/analyzer/parameterUtils.js +7 -7
- package/dist/analyzer/parameterUtils.js.map +1 -1
- package/dist/analyzer/parseTreeUtils.d.ts +1 -0
- package/dist/analyzer/parseTreeUtils.js +23 -40
- package/dist/analyzer/parseTreeUtils.js.map +1 -1
- package/dist/analyzer/parseTreeWalker.js +2 -2
- package/dist/analyzer/parseTreeWalker.js.map +1 -1
- package/dist/analyzer/patternMatching.js +1 -0
- package/dist/analyzer/patternMatching.js.map +1 -1
- package/dist/analyzer/program.d.ts +12 -18
- package/dist/analyzer/program.js +25 -12
- package/dist/analyzer/program.js.map +1 -1
- package/dist/analyzer/protocols.js +3 -1
- package/dist/analyzer/protocols.js.map +1 -1
- package/dist/analyzer/service.d.ts +4 -4
- package/dist/analyzer/service.js +29 -24
- package/dist/analyzer/service.js.map +1 -1
- package/dist/analyzer/sourceFile.d.ts +1 -6
- package/dist/analyzer/sourceFile.js +12 -27
- package/dist/analyzer/sourceFile.js.map +1 -1
- package/dist/analyzer/sourceMapper.js +1 -1
- package/dist/analyzer/sourceMapper.js.map +1 -1
- package/dist/analyzer/typeCacheUtils.d.ts +9 -2
- package/dist/analyzer/typeCacheUtils.js +52 -9
- package/dist/analyzer/typeCacheUtils.js.map +1 -1
- package/dist/analyzer/typeDocStringUtils.js +1 -1
- package/dist/analyzer/typeDocStringUtils.js.map +1 -1
- package/dist/analyzer/typeEvaluator.d.ts +2 -2
- package/dist/analyzer/typeEvaluator.js +257 -143
- package/dist/analyzer/typeEvaluator.js.map +1 -1
- package/dist/analyzer/typeEvaluatorTypes.d.ts +3 -2
- package/dist/analyzer/typeEvaluatorTypes.js.map +1 -1
- package/dist/analyzer/typeGuards.js +3 -2
- package/dist/analyzer/typeGuards.js.map +1 -1
- package/dist/analyzer/typePrinter.js +17 -10
- package/dist/analyzer/typePrinter.js.map +1 -1
- package/dist/analyzer/typeStubWriter.js +2 -2
- package/dist/analyzer/typeStubWriter.js.map +1 -1
- package/dist/analyzer/typeUtils.d.ts +1 -0
- package/dist/analyzer/typeUtils.js +20 -18
- package/dist/analyzer/typeUtils.js.map +1 -1
- package/dist/analyzer/typeVarContext.js +2 -2
- package/dist/analyzer/typeVarContext.js.map +1 -1
- package/dist/analyzer/typedDicts.js +140 -43
- package/dist/analyzer/typedDicts.js.map +1 -1
- package/dist/analyzer/types.d.ts +9 -1
- package/dist/analyzer/types.js +39 -16
- package/dist/analyzer/types.js.map +1 -1
- package/dist/backgroundAnalysisBase.d.ts +25 -19
- package/dist/backgroundAnalysisBase.js +145 -115
- package/dist/backgroundAnalysisBase.js.map +1 -1
- package/dist/backgroundThreadBase.d.ts +1 -1
- package/dist/backgroundThreadBase.js +1 -1
- package/dist/backgroundThreadBase.js.map +1 -1
- package/dist/commands/dumpFileDebugInfoCommand.js +5 -5
- package/dist/commands/dumpFileDebugInfoCommand.js.map +1 -1
- package/dist/common/commandLineOptions.d.ts +1 -0
- package/dist/common/commandLineOptions.js.map +1 -1
- package/dist/common/configOptions.js +1 -1
- package/dist/common/configOptions.js.map +1 -1
- package/dist/common/extensibility.d.ts +2 -4
- package/dist/common/extensibility.js.map +1 -1
- package/dist/common/textRange.d.ts +3 -3
- package/dist/common/textRange.js +17 -8
- package/dist/common/textRange.js.map +1 -1
- package/dist/common/uriParser.d.ts +1 -0
- package/dist/common/uriParser.js +9 -0
- package/dist/common/uriParser.js.map +1 -1
- package/dist/common/workspaceEditUtils.d.ts +1 -1
- package/dist/common/workspaceEditUtils.js +5 -7
- package/dist/common/workspaceEditUtils.js.map +1 -1
- package/dist/languageServerBase.js +6 -4
- package/dist/languageServerBase.js.map +1 -1
- package/dist/languageService/analyzerServiceExecutor.js +1 -0
- package/dist/languageService/analyzerServiceExecutor.js.map +1 -1
- package/dist/languageService/autoImporter.d.ts +3 -3
- package/dist/languageService/autoImporter.js +3 -3
- package/dist/languageService/autoImporter.js.map +1 -1
- package/dist/languageService/callHierarchyProvider.js +3 -2
- package/dist/languageService/callHierarchyProvider.js.map +1 -1
- package/dist/languageService/completionProvider.d.ts +2 -2
- package/dist/languageService/completionProvider.js +42 -35
- package/dist/languageService/completionProvider.js.map +1 -1
- package/dist/languageService/documentSymbolCollector.js +9 -9
- package/dist/languageService/documentSymbolCollector.js.map +1 -1
- package/dist/languageService/referencesProvider.js +1 -1
- package/dist/languageService/referencesProvider.js.map +1 -1
- package/dist/languageService/renameProvider.d.ts +3 -3
- package/dist/languageService/renameProvider.js +6 -6
- package/dist/languageService/renameProvider.js.map +1 -1
- package/dist/languageService/signatureHelpProvider.js +1 -1
- package/dist/languageService/signatureHelpProvider.js.map +1 -1
- package/dist/languageService/symbolIndexer.d.ts +0 -8
- package/dist/languageService/symbolIndexer.js.map +1 -1
- package/dist/localization/localize.d.ts +23 -3
- package/dist/localization/localize.js +13 -3
- package/dist/localization/localize.js.map +1 -1
- package/dist/localization/package.nls.en-us.json +15 -5
- package/dist/parser/parseNodes.d.ts +19 -11
- package/dist/parser/parseNodes.js +27 -19
- package/dist/parser/parseNodes.js.map +1 -1
- package/dist/parser/parser.d.ts +3 -3
- package/dist/parser/parser.js +146 -169
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/stringTokenUtils.d.ts +3 -13
- package/dist/parser/stringTokenUtils.js +8 -181
- package/dist/parser/stringTokenUtils.js.map +1 -1
- package/dist/parser/tokenizer.d.ts +3 -0
- package/dist/parser/tokenizer.js +212 -24
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/tokenizerTypes.d.ts +31 -1
- package/dist/parser/tokenizerTypes.js +51 -1
- package/dist/parser/tokenizerTypes.js.map +1 -1
- package/dist/readonlyAugmentedFileSystem.js +1 -1
- package/dist/readonlyAugmentedFileSystem.js.map +1 -1
- package/dist/tests/docStringConversion.test.js +44 -0
- package/dist/tests/docStringConversion.test.js.map +1 -1
- package/dist/tests/fourslash/fourslash.d.ts +1 -1
- package/dist/tests/fourslash/rename.function.untitledFile.fourslash.d.ts +1 -0
- package/dist/tests/fourslash/rename.function.untitledFile.fourslash.js +17 -0
- package/dist/tests/fourslash/rename.function.untitledFile.fourslash.js.map +1 -0
- 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.d.ts +1 -1
- package/dist/tests/harness/fourslash/testState.js +4 -3
- package/dist/tests/harness/fourslash/testState.js.map +1 -1
- package/dist/tests/importResolver.test.js +3 -3
- package/dist/tests/importResolver.test.js.map +1 -1
- package/dist/tests/textRange.test.d.ts +1 -0
- package/dist/tests/textRange.test.js +45 -0
- package/dist/tests/textRange.test.js.map +1 -0
- package/dist/tests/tokenizer.test.js +280 -58
- package/dist/tests/tokenizer.test.js.map +1 -1
- package/dist/tests/typeEvaluator1.test.js +5 -1
- 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 +11 -1
- package/dist/tests/typeEvaluator3.test.js.map +1 -1
- package/dist/tests/typeEvaluator4.test.js +7 -2
- package/dist/tests/typeEvaluator4.test.js.map +1 -1
- package/dist/tests/typeEvaluator5.test.js +8 -0
- package/dist/tests/typeEvaluator5.test.js.map +1 -1
- package/dist/tests/typePrinter.test.js +3 -3
- package/dist/tests/typePrinter.test.js.map +1 -1
- package/dist/workspaceFactory.js +7 -9
- package/dist/workspaceFactory.js.map +1 -1
- package/package.json +1 -1
@@ -166,7 +166,7 @@ const printExpressionTypes = false;
|
|
166
166
|
exports.maxCodeComplexity = 768;
|
167
167
|
function createTypeEvaluator(importLookup, evaluatorOptions) {
|
168
168
|
const symbolResolutionStack = [];
|
169
|
-
const
|
169
|
+
const asymmetricAccessorAssignmentCache = new Set();
|
170
170
|
const speculativeTypeTracker = new typeCacheUtils_1.SpeculativeTypeTracker();
|
171
171
|
const suppressedNodeStack = [];
|
172
172
|
let functionRecursionMap = new Set();
|
@@ -300,10 +300,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
300
300
|
if (isSpeculativeModeInUse(/* node */ undefined)) {
|
301
301
|
return;
|
302
302
|
}
|
303
|
-
|
303
|
+
asymmetricAccessorAssignmentCache.add(node.id);
|
304
304
|
}
|
305
|
-
function
|
306
|
-
return
|
305
|
+
function isAsymmetricAccessorAssignment(node) {
|
306
|
+
return asymmetricAccessorAssignmentCache.has(node.id);
|
307
307
|
}
|
308
308
|
// Determines whether the specified node is contained within
|
309
309
|
// the function node corresponding to the function that we
|
@@ -822,7 +822,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
822
822
|
let isLiteralString = true;
|
823
823
|
// If all of the format expressions are of type LiteralString, then
|
824
824
|
// the resulting formatted string is also LiteralString.
|
825
|
-
node.
|
825
|
+
node.fieldExpressions.forEach((expr) => {
|
826
826
|
const exprType = getTypeOfExpression(expr).type;
|
827
827
|
(0, typeUtils_1.doForEachSubtype)(exprType, (exprSubtype) => {
|
828
828
|
if (!(0, types_1.isClassInstance)(exprSubtype)) {
|
@@ -858,6 +858,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
858
858
|
return typeResult;
|
859
859
|
}
|
860
860
|
function stripLiteralValue(type) {
|
861
|
+
var _a, _b, _c;
|
862
|
+
// Handle the not-uncommon case where the type is a union that consists
|
863
|
+
// only of literal str or literal int values.
|
864
|
+
if ((0, types_1.isUnion)(type) && type.subtypes.length > 0) {
|
865
|
+
if (((_a = type.literalStrMap) === null || _a === void 0 ? void 0 : _a.size) === type.subtypes.length ||
|
866
|
+
((_b = type.literalIntMap) === null || _b === void 0 ? void 0 : _b.size) === type.subtypes.length ||
|
867
|
+
((_c = type.literalEnumMap) === null || _c === void 0 ? void 0 : _c.size) === type.subtypes.length) {
|
868
|
+
return stripLiteralValue(type.subtypes[0]);
|
869
|
+
}
|
870
|
+
}
|
861
871
|
return (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
862
872
|
if ((0, types_1.isClass)(subtype)) {
|
863
873
|
if (subtype.literalValue !== undefined) {
|
@@ -880,9 +890,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
880
890
|
function getTypeOfParameterAnnotation(paramTypeNode, paramCategory) {
|
881
891
|
return getTypeOfAnnotation(paramTypeNode, {
|
882
892
|
associateTypeVarsWithScope: true,
|
883
|
-
allowTypeVarTuple: paramCategory === 1 /*
|
884
|
-
allowUnpackedTypedDict: paramCategory === 2 /*
|
885
|
-
allowUnpackedTuple: paramCategory === 1 /*
|
893
|
+
allowTypeVarTuple: paramCategory === 1 /* ArgsList */,
|
894
|
+
allowUnpackedTypedDict: paramCategory === 2 /* KwargsDict */,
|
895
|
+
allowUnpackedTuple: paramCategory === 1 /* ArgsList */,
|
886
896
|
});
|
887
897
|
}
|
888
898
|
function getTypeOfAnnotation(node, options) {
|
@@ -1225,7 +1235,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1225
1235
|
type: memberInfo.type,
|
1226
1236
|
classType: memberInfo.classType,
|
1227
1237
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1228
|
-
|
1238
|
+
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1229
1239
|
};
|
1230
1240
|
}
|
1231
1241
|
return undefined;
|
@@ -1272,7 +1282,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
1272
1282
|
return {
|
1273
1283
|
type: memberInfo.type,
|
1274
1284
|
isIncomplete: !!memberInfo.isTypeIncomplete,
|
1275
|
-
|
1285
|
+
isAsymmetricAccessor: memberInfo.isAsymmetricAccessor,
|
1276
1286
|
};
|
1277
1287
|
}
|
1278
1288
|
// Determine whether to use the class or metaclass diagnostic addendum.
|
@@ -2102,7 +2112,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2102
2112
|
setErrorNode: srcExpr,
|
2103
2113
|
setExpectedTypeDiag: expectedTypeDiagAddendum,
|
2104
2114
|
}, 0 /* None */);
|
2105
|
-
if (setTypeResult.
|
2115
|
+
if (setTypeResult.isAsymmetricAccessor) {
|
2106
2116
|
setAsymmetricDescriptorAssignment(target);
|
2107
2117
|
}
|
2108
2118
|
writeTypeCache(target.memberName, { type, isIncomplete: isTypeIncomplete }, 0 /* None */);
|
@@ -2322,6 +2332,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
2322
2332
|
// If this is a TypeVarTuple *Ts, convert it to an unpacked tuple
|
2323
2333
|
// *tuple[*Ts].
|
2324
2334
|
if ((0, types_1.isVariadicTypeVar)(subtype)) {
|
2335
|
+
if (subtype.isVariadicInUnion) {
|
2336
|
+
return subtype;
|
2337
|
+
}
|
2325
2338
|
if (tupleClassType && (0, types_1.isInstantiableClass)(tupleClassType)) {
|
2326
2339
|
return (0, typeUtils_1.convertToInstance)((0, typeUtils_1.specializeTupleClass)(tupleClassType, [{ type: subtype, isUnbounded: false }],
|
2327
2340
|
/* isTypeArgumentExplicit */ true,
|
@@ -3295,7 +3308,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3295
3308
|
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
|
3296
3309
|
let type;
|
3297
3310
|
let isIncomplete = !!baseTypeResult.isIncomplete;
|
3298
|
-
let
|
3311
|
+
let isAsymmetricAccessor;
|
3299
3312
|
const isRequired = false;
|
3300
3313
|
const isNotRequired = false;
|
3301
3314
|
// If the base type was incomplete and unbound, don't proceed
|
@@ -3335,7 +3348,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3335
3348
|
if (baseType.details.isParamSpec) {
|
3336
3349
|
if (memberName === 'args') {
|
3337
3350
|
const paramNode = ParseTreeUtils.getEnclosingParameter(node);
|
3338
|
-
if (!paramNode || paramNode.category !== 1 /*
|
3351
|
+
if (!paramNode || paramNode.category !== 1 /* ArgsList */) {
|
3339
3352
|
addError(localize_1.Localizer.Diagnostic.paramSpecArgsUsage(), node);
|
3340
3353
|
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3341
3354
|
}
|
@@ -3343,7 +3356,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3343
3356
|
}
|
3344
3357
|
if (memberName === 'kwargs') {
|
3345
3358
|
const paramNode = ParseTreeUtils.getEnclosingParameter(node);
|
3346
|
-
if (!paramNode || paramNode.category !== 2 /*
|
3359
|
+
if (!paramNode || paramNode.category !== 2 /* KwargsDict */) {
|
3347
3360
|
addError(localize_1.Localizer.Diagnostic.paramSpecKwargsUsage(), node);
|
3348
3361
|
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3349
3362
|
}
|
@@ -3354,7 +3367,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3354
3367
|
}
|
3355
3368
|
return { type: types_1.UnknownType.create(isIncomplete), isIncomplete };
|
3356
3369
|
}
|
3357
|
-
if (flags &
|
3370
|
+
if (flags & 256 /* ExpectingTypeAnnotation */) {
|
3358
3371
|
if (!isIncomplete) {
|
3359
3372
|
addDiagnostic(AnalyzerNodeInfo.getFileInfo(node).diagnosticRuleSet.reportGeneralTypeIssues, diagnosticRules_1.DiagnosticRule.reportGeneralTypeIssues, localize_1.Localizer.Diagnostic.typeVarNoMember().format({
|
3360
3373
|
type: printType(baseType),
|
@@ -3379,8 +3392,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3379
3392
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
|
3380
3393
|
isIncomplete = true;
|
3381
3394
|
}
|
3382
|
-
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.
|
3383
|
-
|
3395
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3396
|
+
isAsymmetricAccessor = true;
|
3384
3397
|
}
|
3385
3398
|
}
|
3386
3399
|
else {
|
@@ -3397,8 +3410,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3397
3410
|
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isIncomplete) {
|
3398
3411
|
isIncomplete = true;
|
3399
3412
|
}
|
3400
|
-
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.
|
3401
|
-
|
3413
|
+
if (typeResult === null || typeResult === void 0 ? void 0 : typeResult.isAsymmetricAccessor) {
|
3414
|
+
isAsymmetricAccessor = true;
|
3402
3415
|
}
|
3403
3416
|
}
|
3404
3417
|
break;
|
@@ -3598,7 +3611,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3598
3611
|
/* ignoreEmptyContainers */ false);
|
3599
3612
|
}
|
3600
3613
|
}
|
3601
|
-
return { type, isIncomplete,
|
3614
|
+
return { type, isIncomplete, isAsymmetricAccessor, isRequired, isNotRequired };
|
3602
3615
|
}
|
3603
3616
|
function getTypeOfClassMemberName(errorNode, classType, isAccessedThroughObject, memberName, usage, diag, flags, bindToType) {
|
3604
3617
|
var _a, _b;
|
@@ -3733,7 +3746,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3733
3746
|
isClassMember: !memberInfo.isInstanceMember,
|
3734
3747
|
isClassVar: memberInfo.isClassVar,
|
3735
3748
|
classType: memberInfo.classType,
|
3736
|
-
|
3749
|
+
isAsymmetricAccessor: descriptorResult.isAsymmetricAccessor,
|
3737
3750
|
};
|
3738
3751
|
}
|
3739
3752
|
// No attribute of that name was found. If this is a member access
|
@@ -3745,11 +3758,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3745
3758
|
if (generalAttrType) {
|
3746
3759
|
return {
|
3747
3760
|
symbol: undefined,
|
3748
|
-
type: generalAttrType,
|
3761
|
+
type: generalAttrType.type,
|
3749
3762
|
isTypeIncomplete: false,
|
3750
3763
|
isClassMember: false,
|
3751
3764
|
isClassVar: false,
|
3752
|
-
|
3765
|
+
isAsymmetricAccessor: generalAttrType.isAsymmetricAccessor,
|
3753
3766
|
};
|
3754
3767
|
}
|
3755
3768
|
}
|
@@ -3762,7 +3775,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3762
3775
|
function applyDescriptorAccessMethod(type, memberInfo, baseTypeClass, bindToType, isAccessedThroughObject, flags, errorNode, memberName, usage, diag) {
|
3763
3776
|
const treatConstructorAsClassMember = (flags & 16 /* TreatConstructorAsClassMethod */) !== 0;
|
3764
3777
|
let isTypeValid = true;
|
3765
|
-
let
|
3778
|
+
let isAsymmetricAccessor = false;
|
3766
3779
|
type = (0, typeUtils_1.mapSubtypes)(type, (subtype) => {
|
3767
3780
|
var _a, _b, _c;
|
3768
3781
|
const concreteSubtype = makeTopLevelTypeVarsConcrete(subtype);
|
@@ -3947,7 +3960,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
3947
3960
|
// Determine if we're calling __set__ on an asymmetric descriptor or property.
|
3948
3961
|
if (usage.method === 'set' && (0, types_1.isClass)(accessMethod.classType)) {
|
3949
3962
|
if (isAsymmetricDescriptorClass(accessMethod.classType)) {
|
3950
|
-
|
3963
|
+
isAsymmetricAccessor = true;
|
3951
3964
|
}
|
3952
3965
|
}
|
3953
3966
|
if (returnType) {
|
@@ -4051,7 +4064,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4051
4064
|
if (!isTypeValid) {
|
4052
4065
|
return undefined;
|
4053
4066
|
}
|
4054
|
-
return { type,
|
4067
|
+
return { type, isAsymmetricAccessor };
|
4055
4068
|
}
|
4056
4069
|
function isAsymmetricDescriptorClass(classType) {
|
4057
4070
|
var _a;
|
@@ -4085,6 +4098,38 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4085
4098
|
classType.isAsymmetricDescriptor = isAsymmetric;
|
4086
4099
|
return isAsymmetric;
|
4087
4100
|
}
|
4101
|
+
function isClassWithAsymmetricAttributeAccessor(classType) {
|
4102
|
+
var _a;
|
4103
|
+
// If the value has already been cached in this type, return the cached value.
|
4104
|
+
if (classType.isAsymmetricAttributeAccessor !== undefined) {
|
4105
|
+
return classType.isAsymmetricAttributeAccessor;
|
4106
|
+
}
|
4107
|
+
let isAsymmetric = false;
|
4108
|
+
const getterSymbolResult = (0, typeUtils_1.lookUpClassMember)(classType, '__getattr__', 2 /* SkipBaseClasses */);
|
4109
|
+
const setterSymbolResult = (0, typeUtils_1.lookUpClassMember)(classType, '__setattr__', 2 /* SkipBaseClasses */);
|
4110
|
+
if (!getterSymbolResult || !setterSymbolResult) {
|
4111
|
+
isAsymmetric = false;
|
4112
|
+
}
|
4113
|
+
else {
|
4114
|
+
const getterType = getEffectiveTypeOfSymbol(getterSymbolResult.symbol);
|
4115
|
+
const setterType = getEffectiveTypeOfSymbol(setterSymbolResult.symbol);
|
4116
|
+
// If either the setter or getter is an overload (or some other non-function type),
|
4117
|
+
// conservatively assume that it's not asymmetric.
|
4118
|
+
if ((0, types_1.isFunction)(getterType) && (0, types_1.isFunction)(setterType)) {
|
4119
|
+
// If there's no declared return type on the getter, assume it's symmetric.
|
4120
|
+
if (setterType.details.parameters.length >= 3 && getterType.details.declaredReturnType) {
|
4121
|
+
const setterValueType = types_1.FunctionType.getEffectiveParameterType(setterType, 2);
|
4122
|
+
const getterReturnType = (_a = types_1.FunctionType.getSpecializedReturnType(getterType)) !== null && _a !== void 0 ? _a : types_1.UnknownType.create();
|
4123
|
+
if (!(0, types_1.isTypeSame)(setterValueType, getterReturnType)) {
|
4124
|
+
isAsymmetric = true;
|
4125
|
+
}
|
4126
|
+
}
|
4127
|
+
}
|
4128
|
+
}
|
4129
|
+
// Cache the value for next time.
|
4130
|
+
classType.isAsymmetricAttributeAccessor = isAsymmetric;
|
4131
|
+
return isAsymmetric;
|
4132
|
+
}
|
4088
4133
|
// Applies the __getattr__, __setattr__ or __delattr__ method if present.
|
4089
4134
|
function applyAttributeAccessOverride(classType, errorNode, usage, memberName) {
|
4090
4135
|
var _a, _b, _c, _d, _e;
|
@@ -4139,7 +4184,14 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4139
4184
|
const typeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(boundMethodType));
|
4140
4185
|
const callResult = validateCallArguments(errorNode, argList, { type: boundMethodType }, typeVarContext,
|
4141
4186
|
/* skipUnknownArgCheck */ true);
|
4142
|
-
|
4187
|
+
let isAsymmetricAccessor = false;
|
4188
|
+
if (usage.method === 'set') {
|
4189
|
+
isAsymmetricAccessor = isClassWithAsymmetricAttributeAccessor(classType);
|
4190
|
+
}
|
4191
|
+
return {
|
4192
|
+
type: (_e = callResult.returnType) !== null && _e !== void 0 ? _e : types_1.UnknownType.create(),
|
4193
|
+
isAsymmetricAccessor,
|
4194
|
+
};
|
4143
4195
|
}
|
4144
4196
|
}
|
4145
4197
|
}
|
@@ -4475,6 +4527,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4475
4527
|
let isIncomplete = baseTypeResult.isIncomplete;
|
4476
4528
|
let isRequired = false;
|
4477
4529
|
let isNotRequired = false;
|
4530
|
+
let isReadOnly = false;
|
4478
4531
|
const type = mapSubtypesExpandTypeVars(baseTypeResult.type,
|
4479
4532
|
/* conditionFilter */ undefined, (concreteSubtype, unexpandedSubtype) => {
|
4480
4533
|
var _a;
|
@@ -4581,6 +4634,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4581
4634
|
else if (result.isNotRequired) {
|
4582
4635
|
isNotRequired = true;
|
4583
4636
|
}
|
4637
|
+
if (result.isReadOnly) {
|
4638
|
+
isReadOnly = true;
|
4639
|
+
}
|
4584
4640
|
return result.type;
|
4585
4641
|
}
|
4586
4642
|
if ((0, types_1.isClassInstance)(concreteSubtype)) {
|
@@ -4612,7 +4668,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
4612
4668
|
}
|
4613
4669
|
});
|
4614
4670
|
}
|
4615
|
-
return { type, isIncomplete, isRequired, isNotRequired };
|
4671
|
+
return { type, isIncomplete, isReadOnly, isRequired, isNotRequired };
|
4616
4672
|
}
|
4617
4673
|
// Determines the effective variance of the type parameters for a generic
|
4618
4674
|
// type alias. Normally, variance is not important for type aliases, but
|
@@ -6077,7 +6133,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6077
6133
|
if (functionResult.isTypeIncomplete) {
|
6078
6134
|
isTypeIncomplete = true;
|
6079
6135
|
}
|
6080
|
-
|
6136
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
|
6081
6137
|
if (functionResult.argumentErrors) {
|
6082
6138
|
argumentErrors = true;
|
6083
6139
|
}
|
@@ -6123,7 +6179,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6123
6179
|
return (0, typeUtils_1.convertToInstance)(castToType);
|
6124
6180
|
}
|
6125
6181
|
const functionResult = validateOverloadedFunctionArguments(errorNode, argList, { type: expandedSubtype, isIncomplete: callTypeResult.isIncomplete }, typeVarContext, skipUnknownArgCheck, inferenceContext);
|
6126
|
-
|
6182
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
|
6127
6183
|
if (functionResult.isTypeIncomplete) {
|
6128
6184
|
isTypeIncomplete = true;
|
6129
6185
|
}
|
@@ -6265,7 +6321,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6265
6321
|
}
|
6266
6322
|
// Assume this is a call to the constructor.
|
6267
6323
|
const constructorResult = (0, constructors_1.validateConstructorArguments)(evaluatorInterface, errorNode, argList, expandedSubtype, skipUnknownArgCheck, inferenceContext);
|
6268
|
-
|
6324
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, constructorResult.overloadsUsedForCall);
|
6269
6325
|
if (constructorResult.argumentErrors) {
|
6270
6326
|
argumentErrors = true;
|
6271
6327
|
}
|
@@ -6308,7 +6364,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6308
6364
|
/* diag */ undefined, 64 /* SkipAttributeAccessOverride */)) === null || _e === void 0 ? void 0 : _e.type;
|
6309
6365
|
if (memberType) {
|
6310
6366
|
const functionResult = validateCallArguments(errorNode, argList, { type: memberType }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6311
|
-
|
6367
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, functionResult.overloadsUsedForCall);
|
6312
6368
|
if (functionResult.argumentErrors) {
|
6313
6369
|
argumentErrors = true;
|
6314
6370
|
}
|
@@ -6353,7 +6409,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6353
6409
|
case 10 /* TypeVar */: {
|
6354
6410
|
expandedSubtype = (0, typeUtils_1.transformPossibleRecursiveTypeAlias)(expandedSubtype);
|
6355
6411
|
const callResult = validateCallArguments(errorNode, argList, { type: expandedSubtype }, typeVarContext, skipUnknownArgCheck, inferenceContext, recursionCount);
|
6356
|
-
|
6412
|
+
(0, collectionUtils_1.appendArray)(overloadsUsedForCall, callResult.overloadsUsedForCall);
|
6357
6413
|
if (callResult.argumentErrors) {
|
6358
6414
|
argumentErrors = true;
|
6359
6415
|
}
|
@@ -6441,6 +6497,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6441
6497
|
// Build a map of parameters by name.
|
6442
6498
|
const paramMap = new Map();
|
6443
6499
|
paramDetails.params.forEach((paramInfo) => {
|
6500
|
+
(0, debug_1.assert)(paramInfo !== undefined, 'paramInfo is undefined for param name map');
|
6444
6501
|
const param = paramInfo.param;
|
6445
6502
|
if (param.name && param.category === 0 /* Simple */) {
|
6446
6503
|
paramMap.set(param.name, {
|
@@ -6491,8 +6548,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6491
6548
|
if (argList.some((arg) => arg.argumentCategory === 1 /* UnpackedList */)) {
|
6492
6549
|
argList.forEach((arg) => {
|
6493
6550
|
if (arg.name) {
|
6494
|
-
const keywordParamIndex = paramDetails.params.findIndex((paramInfo) =>
|
6495
|
-
paramInfo
|
6551
|
+
const keywordParamIndex = paramDetails.params.findIndex((paramInfo) => {
|
6552
|
+
(0, debug_1.assert)(paramInfo, 'paramInfo entry is undefined fork kwargs check');
|
6553
|
+
return (paramInfo.param.name === arg.name.value &&
|
6554
|
+
paramInfo.param.category === 0 /* Simple */);
|
6555
|
+
});
|
6496
6556
|
// Is this a parameter that can be interpreted as either a keyword or a positional?
|
6497
6557
|
// If so, we'll treat it as a keyword parameter in this case because it's being
|
6498
6558
|
// targeted by a keyword argument.
|
@@ -6570,7 +6630,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6570
6630
|
(0, debug_1.assert)(paramDetails.params[paramIndex], 'paramIndex params entry is undefined');
|
6571
6631
|
const paramType = paramDetails.params[paramIndex].type;
|
6572
6632
|
const paramName = paramDetails.params[paramIndex].param.name;
|
6573
|
-
const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /*
|
6633
|
+
const isParamVariadic = paramDetails.params[paramIndex].param.category === 1 /* ArgsList */ &&
|
6574
6634
|
(0, types_1.isVariadicTypeVar)(paramType);
|
6575
6635
|
if (argList[argIndex].argumentCategory === 1 /* UnpackedList */) {
|
6576
6636
|
let isArgCompatibleWithVariadic = false;
|
@@ -6631,7 +6691,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6631
6691
|
listElementType =
|
6632
6692
|
(_e = (_d = getTypeOfIterator({ type: argType, isIncomplete: argTypeResult.isIncomplete },
|
6633
6693
|
/* isAsync */ false, argList[argIndex].valueExpression)) === null || _d === void 0 ? void 0 : _d.type) !== null && _e !== void 0 ? _e : types_1.UnknownType.create();
|
6634
|
-
if (paramDetails.params[paramIndex].param.category !== 1 /*
|
6694
|
+
if (paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
|
6635
6695
|
matchedUnpackedListOfUnknownLength = true;
|
6636
6696
|
}
|
6637
6697
|
}
|
@@ -6676,16 +6736,15 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6676
6736
|
paramMap.has(paramName)) {
|
6677
6737
|
paramMap.get(paramName).argsReceived++;
|
6678
6738
|
}
|
6679
|
-
if (advanceToNextArg ||
|
6680
|
-
paramDetails.params[paramIndex].param.category === 1 /* VarArgList */) {
|
6739
|
+
if (advanceToNextArg || paramDetails.params[paramIndex].param.category === 1 /* ArgsList */) {
|
6681
6740
|
argIndex++;
|
6682
6741
|
}
|
6683
6742
|
if (isVariadicTypeVarFullyMatched ||
|
6684
|
-
paramDetails.params[paramIndex].param.category !== 1 /*
|
6743
|
+
paramDetails.params[paramIndex].param.category !== 1 /* ArgsList */) {
|
6685
6744
|
paramIndex++;
|
6686
6745
|
}
|
6687
6746
|
}
|
6688
|
-
else if (paramDetails.params[paramIndex].param.category === 1 /*
|
6747
|
+
else if (paramDetails.params[paramIndex].param.category === 1 /* ArgsList */) {
|
6689
6748
|
trySetActive(argList[argIndex], paramDetails.params[paramIndex].param);
|
6690
6749
|
if (paramSpecArgList) {
|
6691
6750
|
paramSpecArgList.push(argList[argIndex]);
|
@@ -6701,7 +6760,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6701
6760
|
effectiveParamType = paramType.tupleTypeArguments[0].type;
|
6702
6761
|
}
|
6703
6762
|
paramCategory = (0, types_1.isVariadicTypeVar)(effectiveParamType)
|
6704
|
-
? 1 /*
|
6763
|
+
? 1 /* ArgsList */
|
6705
6764
|
: 0 /* Simple */;
|
6706
6765
|
if (remainingArgCount <= remainingParamCount) {
|
6707
6766
|
if (remainingArgCount < remainingParamCount) {
|
@@ -6758,7 +6817,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6758
6817
|
let skippedArgsParam = false;
|
6759
6818
|
if (positionalOnlyLimitIndex >= 0 &&
|
6760
6819
|
paramIndex < positionalOnlyLimitIndex &&
|
6761
|
-
paramDetails.params
|
6820
|
+
paramIndex < paramDetails.params.length &&
|
6821
|
+
paramDetails.params[paramIndex].param.category === 1 /* ArgsList */ &&
|
6762
6822
|
!(0, types_1.isParamSpec)(paramDetails.params[paramIndex].param.type)) {
|
6763
6823
|
paramIndex++;
|
6764
6824
|
skippedArgsParam = true;
|
@@ -6779,7 +6839,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6779
6839
|
// because it's permitted to pass zero arguments to *args.
|
6780
6840
|
argsRemainingCount--;
|
6781
6841
|
}
|
6782
|
-
const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /*
|
6842
|
+
const firstArgsParam = paramDetails.params.findIndex((paramInfo) => paramInfo.param.category === 1 /* ArgsList */ && !(0, types_1.isParamSpec)(paramInfo.param.type));
|
6783
6843
|
if (firstArgsParam >= paramIndex && firstArgsParam < positionalOnlyLimitIndex) {
|
6784
6844
|
// If there is another args parameter beyond the current param index,
|
6785
6845
|
// reduce the count by one because it's permitted to pass zero arguments
|
@@ -6841,7 +6901,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6841
6901
|
else if (paramDetails.kwargsIndex !== undefined) {
|
6842
6902
|
const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
|
6843
6903
|
validateArgTypeParams.push({
|
6844
|
-
paramCategory: 2 /*
|
6904
|
+
paramCategory: 2 /* KwargsDict */,
|
6845
6905
|
paramType,
|
6846
6906
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
6847
6907
|
argument: {
|
@@ -6879,7 +6939,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6879
6939
|
unpackedDictionaryArgType = types_1.AnyType.create();
|
6880
6940
|
if (typeResult.type.details.paramSpec) {
|
6881
6941
|
validateArgTypeParams.push({
|
6882
|
-
paramCategory: 2 /*
|
6942
|
+
paramCategory: 2 /* KwargsDict */,
|
6883
6943
|
paramType: typeResult.type.details.paramSpec,
|
6884
6944
|
requiresTypeVarMatching: false,
|
6885
6945
|
argument: argList[argIndex],
|
@@ -6964,7 +7024,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
6964
7024
|
else {
|
6965
7025
|
const paramType = paramDetails.params[paramDetails.kwargsIndex].type;
|
6966
7026
|
validateArgTypeParams.push({
|
6967
|
-
paramCategory: 2 /*
|
7027
|
+
paramCategory: 2 /* KwargsDict */,
|
6968
7028
|
paramType,
|
6969
7029
|
requiresTypeVarMatching: (0, typeUtils_1.requiresSpecialization)(paramType),
|
6970
7030
|
argument: argList[argIndex],
|
@@ -7008,7 +7068,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7008
7068
|
}
|
7009
7069
|
if ((0, types_1.isParamSpec)(argType) && argType.paramSpecAccess === 'args') {
|
7010
7070
|
validateArgTypeParams.push({
|
7011
|
-
paramCategory: 1 /*
|
7071
|
+
paramCategory: 1 /* ArgsList */,
|
7012
7072
|
paramType: typeResult.type.details.paramSpec,
|
7013
7073
|
requiresTypeVarMatching: false,
|
7014
7074
|
argument: argList[argIndex],
|
@@ -7057,7 +7117,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7057
7117
|
// (i.e. an arg starting with a "**"), we will assume that all parameters
|
7058
7118
|
// are matched.
|
7059
7119
|
if (!unpackedDictionaryArgType && !types_1.FunctionType.isDefaultParameterCheckDisabled(typeResult.type)) {
|
7060
|
-
const unassignedParams =
|
7120
|
+
const unassignedParams = Array.from(paramMap.keys()).filter((name) => {
|
7061
7121
|
const entry = paramMap.get(name);
|
7062
7122
|
return !entry || entry.argsReceived < entry.argsNeeded;
|
7063
7123
|
});
|
@@ -7111,6 +7171,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7111
7171
|
// already been matched, see if the type of that *args parameter is a variadic
|
7112
7172
|
// type variable. If so, we'll preprocess those arguments and combine them
|
7113
7173
|
// into a tuple.
|
7174
|
+
(0, debug_1.assert)(paramDetails.argsIndex === undefined || paramDetails.argsIndex < paramDetails.params.length, 'paramDetails.argsIndex params entry is invalid');
|
7114
7175
|
if (paramDetails.argsIndex !== undefined &&
|
7115
7176
|
paramDetails.argsIndex >= 0 &&
|
7116
7177
|
paramDetails.params[paramDetails.argsIndex].param.hasDeclaredType &&
|
@@ -7157,7 +7218,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7157
7218
|
/* isUnpackedTuple */ true));
|
7158
7219
|
}
|
7159
7220
|
const combinedArg = {
|
7160
|
-
paramCategory: 1 /*
|
7221
|
+
paramCategory: 1 /* ArgsList */,
|
7161
7222
|
paramType,
|
7162
7223
|
requiresTypeVarMatching: true,
|
7163
7224
|
argument: {
|
@@ -7207,6 +7268,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7207
7268
|
function validateFunctionArgumentTypesWithContext(errorNode, matchResults, typeVarContext, skipUnknownArgCheck = false, inferenceContext) {
|
7208
7269
|
var _a;
|
7209
7270
|
const type = matchResults.overload;
|
7271
|
+
// Can we safely ignore the inference context (either because it's not provided
|
7272
|
+
// or will have no effect)? If so, we can eliminate a bunch of extra work.
|
7210
7273
|
if (!inferenceContext ||
|
7211
7274
|
(0, types_1.isAnyOrUnknown)(inferenceContext.expectedType) ||
|
7212
7275
|
(0, types_1.isNever)(inferenceContext.expectedType) ||
|
@@ -7236,6 +7299,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7236
7299
|
});
|
7237
7300
|
}
|
7238
7301
|
if (effectiveExpectedType) {
|
7302
|
+
const liveTypeVarScopes = ParseTreeUtils.getTypeVarScopesForNode(errorNode);
|
7239
7303
|
// Prepopulate the typeVarContext based on the specialized expected type if the
|
7240
7304
|
// callee has a declared return type. This will allow us to more closely match
|
7241
7305
|
// the expected type if possible.
|
@@ -7255,7 +7319,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7255
7319
|
}
|
7256
7320
|
if ((0, types_1.isClassInstance)(effectiveExpectedType) && !(0, types_1.isTypeSame)(effectiveReturnType, effectiveExpectedType)) {
|
7257
7321
|
const tempTypeVarContext = new typeVarContext_1.TypeVarContext((0, typeUtils_1.getTypeVarScopeId)(effectiveReturnType));
|
7258
|
-
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext,
|
7322
|
+
(0, constraintSolver_1.populateTypeVarContextBasedOnExpectedType)(evaluatorInterface, effectiveReturnType, effectiveExpectedType, tempTypeVarContext, liveTypeVarScopes);
|
7259
7323
|
const genericReturnType = types_1.ClassType.cloneForSpecialization(effectiveReturnType,
|
7260
7324
|
/* typeArguments */ undefined,
|
7261
7325
|
/* isTypeArgumentExplicit */ false);
|
@@ -7271,6 +7335,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7271
7335
|
});
|
7272
7336
|
}
|
7273
7337
|
}
|
7338
|
+
effectiveExpectedType = (0, typeUtils_1.transformExpectedType)(effectiveExpectedType, liveTypeVarScopes);
|
7274
7339
|
assignType(effectiveReturnType, effectiveExpectedType,
|
7275
7340
|
/* diag */ undefined, typeVarContext,
|
7276
7341
|
/* srcTypeVarContext */ undefined, effectiveFlags | 1024 /* PopulatingExpectedType */);
|
@@ -7367,17 +7432,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7367
7432
|
if (argResult.isTypeIncomplete) {
|
7368
7433
|
isTypeIncomplete = true;
|
7369
7434
|
}
|
7370
|
-
// If we skipped
|
7371
|
-
// add another pass to ensure that we handle all of the
|
7372
|
-
// type variables.
|
7435
|
+
// If we skipped an overload arg or a bare type var during the first pass,
|
7436
|
+
// add another pass to ensure that we handle all of the type variables.
|
7373
7437
|
if (i === 0 && (argResult.skippedOverloadArg || argResult.skippedBareTypeVarExpectedType)) {
|
7374
7438
|
passCount++;
|
7375
7439
|
}
|
7376
7440
|
});
|
7377
7441
|
});
|
7378
7442
|
}
|
7379
|
-
// Lock the type var map so it cannot be modified
|
7380
|
-
// arguments in a second pass.
|
7443
|
+
// Lock the type var map so it cannot be modified when revalidating
|
7444
|
+
// the arguments in a second pass.
|
7381
7445
|
typeVarContext.lock();
|
7382
7446
|
}
|
7383
7447
|
let sawParamSpecArgs = false;
|
@@ -7465,21 +7529,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7465
7529
|
type.details.typeVarScopeId === types_1.WildcardTypeVarScopeId) {
|
7466
7530
|
eliminateUnsolvedInUnions = false;
|
7467
7531
|
}
|
7468
|
-
//
|
7469
|
-
// if they were not solved. However, if the return type is a
|
7470
|
-
// Callable, we'll leave the TypeVars unsolved because
|
7471
|
-
// the call below to adjustCallableReturnType will "detach" these
|
7472
|
-
// TypeVars from the scope of this function and "attach" them to
|
7473
|
-
// the scope of the callable.
|
7474
|
-
let unknownIfNotFound = !(0, types_1.isFunction)(returnType);
|
7475
|
-
// We'll also leave TypeVars unsolved if the call is a recursive
|
7532
|
+
// We'll leave TypeVars unsolved if the call is a recursive
|
7476
7533
|
// call to a generic function.
|
7477
|
-
const
|
7478
|
-
if (typeVarScopes.some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope))) {
|
7479
|
-
unknownIfNotFound = false;
|
7480
|
-
}
|
7534
|
+
const unknownIfNotFound = !ParseTreeUtils.getTypeVarScopesForNode(errorNode).some((typeVarScope) => typeVarContext.hasSolveForScope(typeVarScope));
|
7481
7535
|
let specializedReturnType = (0, typeUtils_1.applySolvedTypeVars)(returnType, typeVarContext, {
|
7482
7536
|
unknownIfNotFound,
|
7537
|
+
unknownExemptTypeVars: getUnknownExemptTypeVarsForReturnType(type, returnType),
|
7483
7538
|
useUnknownOverDefault: skipUnknownArgCheck,
|
7484
7539
|
eliminateUnsolvedInUnions,
|
7485
7540
|
applyInScopePlaceholders: true,
|
@@ -7532,6 +7587,32 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7532
7587
|
overloadsUsedForCall: argumentErrors ? [] : [type],
|
7533
7588
|
};
|
7534
7589
|
}
|
7590
|
+
// In general, all in-scope type variables left in a return type should be
|
7591
|
+
// replaced with Unknown. However, if the return type is a callable that uses
|
7592
|
+
// type vars that are found nowhere within the function's input parameters,
|
7593
|
+
// we'll treat these as though they're scoped to the callable and leave them
|
7594
|
+
// unsolved.
|
7595
|
+
function getUnknownExemptTypeVarsForReturnType(functionType, returnType) {
|
7596
|
+
if ((0, types_1.isFunction)(returnType) && !returnType.details.name) {
|
7597
|
+
const returnTypeScopeId = returnType.details.typeVarScopeId;
|
7598
|
+
// If one or more type vars found within the return type are scoped to
|
7599
|
+
// the functionType but don't appear anywhere else within the functionType's
|
7600
|
+
// input parameters, rescope them to the return type callable so they are
|
7601
|
+
// not replaced with Unknown.
|
7602
|
+
if (returnTypeScopeId && functionType.details.typeVarScopeId) {
|
7603
|
+
let typeVarsInReturnType = (0, typeUtils_1.getTypeVarArgumentsRecursive)(returnType);
|
7604
|
+
// Remove any type variables that appear in the function's input parameters.
|
7605
|
+
functionType.details.parameters.forEach((param, index) => {
|
7606
|
+
if (param.hasDeclaredType) {
|
7607
|
+
const typeVarsInInputParam = (0, typeUtils_1.getTypeVarArgumentsRecursive)(param.type);
|
7608
|
+
typeVarsInReturnType = typeVarsInReturnType.filter((returnTypeVar) => !typeVarsInInputParam.some((inputTypeVar) => (0, types_1.isTypeSame)(returnTypeVar, inputTypeVar)));
|
7609
|
+
}
|
7610
|
+
});
|
7611
|
+
return typeVarsInReturnType;
|
7612
|
+
}
|
7613
|
+
}
|
7614
|
+
return [];
|
7615
|
+
}
|
7535
7616
|
function adjustCallableReturnType(returnType) {
|
7536
7617
|
// If the return type includes a generic Callable type, set the type var
|
7537
7618
|
// scope to a wildcard to allow these type vars to be solved. This won't
|
@@ -7611,8 +7692,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7611
7692
|
if (positionalIndexLimit < 0) {
|
7612
7693
|
positionalIndexLimit = paramSpecParams.length;
|
7613
7694
|
}
|
7614
|
-
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /*
|
7615
|
-
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /*
|
7695
|
+
const argsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 1 /* ArgsList */);
|
7696
|
+
const kwargsParam = paramSpecParams.find((paramInfo) => paramInfo.category === 2 /* KwargsDict */);
|
7616
7697
|
const signatureTracker = new typeUtils_1.UniqueSignatureTracker();
|
7617
7698
|
let sawUnpackedListArgument = false;
|
7618
7699
|
let sawUnpackedDictArgument = false;
|
@@ -7672,7 +7753,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7672
7753
|
else if (arg.argumentCategory === 1 /* UnpackedList */) {
|
7673
7754
|
sawUnpackedListArgument = true;
|
7674
7755
|
// See if there is an *args parameter.
|
7675
|
-
const argsParam = paramSpecParams.find((param) => param.category === 1 /*
|
7756
|
+
const argsParam = paramSpecParams.find((param) => param.category === 1 /* ArgsList */ && param.name);
|
7676
7757
|
if (argsParam && paramMap.has(argsParam.name)) {
|
7677
7758
|
// TODO - validate args type
|
7678
7759
|
paramMap.delete(argsParam.name);
|
@@ -7682,7 +7763,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7682
7763
|
sawUnpackedDictArgument = true;
|
7683
7764
|
(0, debug_1.assert)(arg.argumentCategory === 2 /* UnpackedDictionary */);
|
7684
7765
|
// See if there is an *kwargs parameter.
|
7685
|
-
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /*
|
7766
|
+
const kwargsParam = paramSpecParams.find((param) => param.category === 2 /* KwargsDict */);
|
7686
7767
|
if (kwargsParam && paramMap.has(kwargsParam.name)) {
|
7687
7768
|
// TODO - validate kwargs type
|
7688
7769
|
paramMap.delete(kwargsParam.name);
|
@@ -7691,7 +7772,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7691
7772
|
});
|
7692
7773
|
// Report any missing parameters.
|
7693
7774
|
if (!reportedArgError) {
|
7694
|
-
let unassignedParams =
|
7775
|
+
let unassignedParams = Array.from(paramMap.keys());
|
7695
7776
|
// Parameters that have defaults can be left unspecified.
|
7696
7777
|
unassignedParams = unassignedParams.filter((name) => {
|
7697
7778
|
const paramInfo = paramMap.get(name);
|
@@ -7810,7 +7891,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
7810
7891
|
// If we're assigning to a var arg dictionary with a TypeVar type,
|
7811
7892
|
// strip literals before performing the assignment. This is used in
|
7812
7893
|
// places like a dict constructor.
|
7813
|
-
if (argParam.paramCategory === 2 /*
|
7894
|
+
if (argParam.paramCategory === 2 /* KwargsDict */ && (0, types_1.isTypeVar)(argParam.paramType)) {
|
7814
7895
|
argType = stripLiteralValue(argType);
|
7815
7896
|
}
|
7816
7897
|
// If there's a constraint filter, apply it to top-level type variables
|
@@ -8400,7 +8481,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
8400
8481
|
else if (baseClass.literalValue !== undefined) {
|
8401
8482
|
addError(localize_1.Localizer.Diagnostic.newTypeLiteral(), argList[1].node || errorNode);
|
8402
8483
|
}
|
8403
|
-
|
8484
|
+
let classFlags = baseClass.details.flags & ~(1 /* BuiltInClass */ | 2 /* SpecialBuiltIn */);
|
8485
|
+
classFlags |= 4096 /* Final */;
|
8404
8486
|
const classType = types_1.ClassType.createInstantiable(className, ParseTreeUtils.getClassFullName(errorNode, fileInfo.moduleName, className), fileInfo.moduleName, fileInfo.filePath, classFlags, ParseTreeUtils.getTypeSourceId(errorNode),
|
8405
8487
|
/* declaredMetaclass */ undefined, baseClass.details.effectiveMetaclass);
|
8406
8488
|
classType.details.baseClasses.push(isBaseClassAny ? types_1.AnyType.create() : baseClass);
|
@@ -9183,28 +9265,28 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9183
9265
|
type: types_1.UnknownType.create(),
|
9184
9266
|
});
|
9185
9267
|
}
|
9268
|
+
// Handle the case where the expected type contains a ParamSpec.
|
9269
|
+
if (expectedFunctionType === null || expectedFunctionType === void 0 ? void 0 : expectedFunctionType.details.paramSpec) {
|
9270
|
+
functionType.details.paramSpec = expectedFunctionType.details.paramSpec;
|
9271
|
+
}
|
9186
9272
|
const expectedReturnType = expectedFunctionType
|
9187
9273
|
? getFunctionEffectiveReturnType(expectedFunctionType)
|
9188
9274
|
: undefined;
|
9189
9275
|
// If we're speculatively evaluating the lambda, create another speculative
|
9190
9276
|
// evaluation scope for the return expression and do not allow retention
|
9191
9277
|
// of the cached types.
|
9192
|
-
|
9278
|
+
// We need to set allowCacheRetention to false because we don't want to
|
9279
|
+
// cache the type of the lambda return expression because it depends on
|
9280
|
+
// the parameter types that we set above, and the speculative type cache
|
9281
|
+
// doesn't know about that context.
|
9282
|
+
useSpeculativeMode(isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete) ? node.expression : undefined, () => {
|
9193
9283
|
const returnTypeResult = getTypeOfExpression(node.expression,
|
9194
9284
|
/* flags */ undefined, (0, typeUtils_1.makeInferenceContext)(expectedReturnType));
|
9195
9285
|
functionType.inferredReturnType = returnTypeResult.type;
|
9196
9286
|
if (returnTypeResult.isIncomplete) {
|
9197
9287
|
isIncomplete = true;
|
9198
9288
|
}
|
9199
|
-
};
|
9200
|
-
// We need to set allowCacheRetention to false because we don't want to
|
9201
|
-
// cache the type of the lambda return expression because it depends on
|
9202
|
-
// the parameter types that we set above, and the speculative type cache
|
9203
|
-
// doesn't know about that context.
|
9204
|
-
useSpeculativeMode(isSpeculativeModeInUse(node) || (inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.isTypeIncomplete) ? node.expression : undefined, () => {
|
9205
|
-
inferLambdaReturnType();
|
9206
|
-
},
|
9207
|
-
/* allowCacheRetention */ false);
|
9289
|
+
}, inferenceContext === null || inferenceContext === void 0 ? void 0 : inferenceContext.expectedType);
|
9208
9290
|
// Mark the function type as no longer being evaluated.
|
9209
9291
|
functionType.details.flags &= ~131072 /* PartiallyEvaluated */;
|
9210
9292
|
return { type: functionType, isIncomplete };
|
@@ -9213,13 +9295,16 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9213
9295
|
var _a;
|
9214
9296
|
let isIncomplete = false;
|
9215
9297
|
let typeErrors = false;
|
9298
|
+
// If any of the "for" clauses are marked async or any of the "if" clauses
|
9299
|
+
// or the final expression contain an "await" operator anywhere within
|
9300
|
+
// the expression, it is treated as an async generator.
|
9216
9301
|
let isAsync = node.forIfNodes.some((comp) => {
|
9217
9302
|
return ((comp.nodeType === 33 /* ListComprehensionFor */ && comp.isAsync) ||
|
9218
9303
|
(comp.nodeType === 34 /* ListComprehensionIf */ &&
|
9219
|
-
comp.testExpression
|
9304
|
+
ParseTreeUtils.containsAwaitNode(comp.testExpression)));
|
9220
9305
|
});
|
9221
9306
|
let type = types_1.UnknownType.create();
|
9222
|
-
if (node.expression
|
9307
|
+
if (ParseTreeUtils.containsAwaitNode(node.expression)) {
|
9223
9308
|
isAsync = true;
|
9224
9309
|
}
|
9225
9310
|
let expectedElementType;
|
@@ -9459,12 +9544,12 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9459
9544
|
const paramName = `__p${index.toString()}`;
|
9460
9545
|
if ((0, types_1.isVariadicTypeVar)(entryType)) {
|
9461
9546
|
validateVariadicTypeVarIsUnpacked(entryType, entry.node);
|
9462
|
-
paramCategory = 1 /*
|
9547
|
+
paramCategory = 1 /* ArgsList */;
|
9463
9548
|
noteSawUnpacked(entry);
|
9464
9549
|
}
|
9465
9550
|
else if (validateTypeArg(entry, { allowUnpackedTuples: true })) {
|
9466
9551
|
if ((0, types_1.isUnpackedClass)(entryType)) {
|
9467
|
-
paramCategory = 1 /*
|
9552
|
+
paramCategory = 1 /* ArgsList */;
|
9468
9553
|
noteSawUnpacked(entry);
|
9469
9554
|
}
|
9470
9555
|
}
|
@@ -9764,7 +9849,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9764
9849
|
}
|
9765
9850
|
return (0, typeUtils_1.synthesizeTypeVarForSelfCls)(enclosingClassTypeResult.classType, /* isClsParam */ true);
|
9766
9851
|
}
|
9767
|
-
function
|
9852
|
+
function createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags) {
|
9768
9853
|
// If no type arguments are provided, the resulting type
|
9769
9854
|
// depends on whether we're evaluating a type annotation or
|
9770
9855
|
// we're in some other context.
|
@@ -9772,7 +9857,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9772
9857
|
return { type: classType };
|
9773
9858
|
}
|
9774
9859
|
if (!typeArgs || typeArgs.length !== 1) {
|
9775
|
-
addError(
|
9860
|
+
addError(classType.details.name === 'ReadOnly'
|
9861
|
+
? localize_1.Localizer.Diagnostic.readOnlyArgCount()
|
9862
|
+
: classType.details.name === 'Required'
|
9863
|
+
? localize_1.Localizer.Diagnostic.requiredArgCount()
|
9864
|
+
: localize_1.Localizer.Diagnostic.notRequiredArgCount(), errorNode);
|
9776
9865
|
return { type: classType };
|
9777
9866
|
}
|
9778
9867
|
const typeArgType = typeArgs[0].type;
|
@@ -9791,17 +9880,35 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9791
9880
|
if ((flags & 1048576 /* AllowRequired */) !== 0) {
|
9792
9881
|
isUsageLegal = true;
|
9793
9882
|
}
|
9794
|
-
|
9795
|
-
|
9796
|
-
|
9883
|
+
let isReadOnly = typeArgs[0].isReadOnly;
|
9884
|
+
let isRequired = typeArgs[0].isRequired;
|
9885
|
+
let isNotRequired = typeArgs[0].isNotRequired;
|
9886
|
+
if (classType.details.name === 'ReadOnly') {
|
9887
|
+
// Nested ReadOnly are not allowed.
|
9888
|
+
if (typeArgs[0].isReadOnly) {
|
9889
|
+
isUsageLegal = false;
|
9890
|
+
}
|
9891
|
+
isReadOnly = true;
|
9892
|
+
}
|
9893
|
+
else {
|
9894
|
+
// Nested Required/NotRequired are not allowed.
|
9895
|
+
if (typeArgs[0].isRequired || typeArgs[0].isNotRequired) {
|
9896
|
+
isUsageLegal = false;
|
9897
|
+
}
|
9898
|
+
isRequired = classType.details.name === 'Required';
|
9899
|
+
isNotRequired = classType.details.name === 'NotRequired';
|
9797
9900
|
}
|
9901
|
+
isRequired = classType.details.name === 'Required';
|
9902
|
+
isNotRequired = classType.details.name === 'NotRequired';
|
9798
9903
|
if (!isUsageLegal) {
|
9799
|
-
addError(
|
9800
|
-
? localize_1.Localizer.Diagnostic.
|
9801
|
-
:
|
9904
|
+
addError(classType.details.name === 'ReadOnly'
|
9905
|
+
? localize_1.Localizer.Diagnostic.readOnlyNotInTypedDict()
|
9906
|
+
: classType.details.name === 'Required'
|
9907
|
+
? localize_1.Localizer.Diagnostic.requiredNotInTypedDict()
|
9908
|
+
: localize_1.Localizer.Diagnostic.notRequiredNotInTypedDict(), errorNode);
|
9802
9909
|
return { type: types_1.ClassType.cloneForSpecialization(classType, [(0, typeUtils_1.convertToInstance)(typeArgType)], !!typeArgs) };
|
9803
9910
|
}
|
9804
|
-
return { type: typeArgType, isRequired, isNotRequired
|
9911
|
+
return { type: typeArgType, isReadOnly, isRequired, isNotRequired };
|
9805
9912
|
}
|
9806
9913
|
function createUnpackType(classType, errorNode, typeArgs, flags) {
|
9807
9914
|
// If no type arguments are provided, the resulting type
|
@@ -9888,6 +9995,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
9888
9995
|
}
|
9889
9996
|
return {
|
9890
9997
|
type: types_1.TypeBase.cloneForAnnotated(typeArgs[0].type),
|
9998
|
+
isReadOnly: typeArgs[0].isReadOnly,
|
9891
9999
|
isRequired: typeArgs[0].isRequired,
|
9892
10000
|
isNotRequired: typeArgs[0].isNotRequired,
|
9893
10001
|
};
|
@@ -10166,7 +10274,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10166
10274
|
// methods that are abstract are overridden and shouldn't
|
10167
10275
|
// cause the TypedDict to be marked as abstract.
|
10168
10276
|
if ((0, types_1.isInstantiableClass)(baseClass) && types_1.ClassType.isBuiltIn(baseClass, '_TypedDict')) {
|
10169
|
-
baseClass.details.flags &= ~
|
10277
|
+
baseClass.details.flags &= ~1024 /* SupportsAbstractMethods */;
|
10170
10278
|
}
|
10171
10279
|
}
|
10172
10280
|
}
|
@@ -10222,6 +10330,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10222
10330
|
['NoReturn', { alias: '', module: 'builtins' }],
|
10223
10331
|
['Never', { alias: '', module: 'builtins' }],
|
10224
10332
|
['LiteralString', { alias: '', module: 'builtins' }],
|
10333
|
+
['ReadOnly', { alias: '', module: 'builtins' }],
|
10225
10334
|
]);
|
10226
10335
|
const aliasMapEntry = specialTypes.get(assignedName);
|
10227
10336
|
if (aliasMapEntry) {
|
@@ -10611,7 +10720,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10611
10720
|
argType = types_1.UnknownType.create();
|
10612
10721
|
}
|
10613
10722
|
else {
|
10614
|
-
argType = getTypeOfExpression(arg.valueExpression, exprFlags).type;
|
10723
|
+
argType = makeTopLevelTypeVarsConcrete(getTypeOfExpression(arg.valueExpression, exprFlags).type);
|
10615
10724
|
}
|
10616
10725
|
// In some stub files, classes are conditionally defined (e.g. based
|
10617
10726
|
// on platform type). We'll assume that the conditional logic is correct
|
@@ -10708,7 +10817,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10708
10817
|
// built-in protocol classes.
|
10709
10818
|
if (types_1.ClassType.supportsAbstractMethods(argType) ||
|
10710
10819
|
(types_1.ClassType.isProtocolClass(argType) && !types_1.ClassType.isBuiltIn(argType))) {
|
10711
|
-
classType.details.flags |=
|
10820
|
+
classType.details.flags |= 1024 /* SupportsAbstractMethods */;
|
10712
10821
|
}
|
10713
10822
|
if (types_1.ClassType.isPropertyClass(argType)) {
|
10714
10823
|
classType.details.flags |= 2048 /* PropertyClass */;
|
@@ -10760,16 +10869,20 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10760
10869
|
metaclassNode = arg.valueExpression;
|
10761
10870
|
}
|
10762
10871
|
}
|
10763
|
-
else if (
|
10764
|
-
|
10872
|
+
else if (types_1.ClassType.isTypedDictClass(classType) &&
|
10873
|
+
(arg.name.value === 'total' || arg.name.value === 'readonly')) {
|
10874
|
+
// The "total" and "readonly" parameters apply only for TypedDict classes.
|
10765
10875
|
// PEP 589 specifies that the parameter must be either True or False.
|
10766
10876
|
const constArgValue = (0, staticExpressions_1.evaluateStaticBoolExpression)(arg.valueExpression, fileInfo.executionEnvironment, fileInfo.definedConstants);
|
10767
10877
|
if (constArgValue === undefined) {
|
10768
|
-
addError(localize_1.Localizer.Diagnostic.
|
10878
|
+
addError(localize_1.Localizer.Diagnostic.typedDictBoolParam().format({ name: arg.name.value }), arg.valueExpression);
|
10769
10879
|
}
|
10770
|
-
else if (!constArgValue) {
|
10880
|
+
else if (arg.name.value === 'total' && !constArgValue) {
|
10771
10881
|
classType.details.flags |= 256 /* CanOmitDictValues */;
|
10772
10882
|
}
|
10883
|
+
else if (arg.name.value === 'readonly' && constArgValue) {
|
10884
|
+
classType.details.flags |= 512 /* DictValuesReadOnly */;
|
10885
|
+
}
|
10773
10886
|
}
|
10774
10887
|
else {
|
10775
10888
|
// Collect arguments that will be passed to the `__init_subclass__`
|
@@ -10906,7 +11019,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10906
11019
|
classType.details.flags |= 1048576 /* EnumClass */;
|
10907
11020
|
}
|
10908
11021
|
else if (types_1.ClassType.isBuiltIn(metaclassType, 'ABCMeta')) {
|
10909
|
-
classType.details.flags |=
|
11022
|
+
classType.details.flags |= 1024 /* SupportsAbstractMethods */;
|
10910
11023
|
}
|
10911
11024
|
}
|
10912
11025
|
}
|
@@ -10981,7 +11094,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
10981
11094
|
// This needs to be done after dataclass processing.
|
10982
11095
|
if (classType.details.localSlotsNames) {
|
10983
11096
|
let isLimitedToSlots = true;
|
10984
|
-
const extendedSlotsNames =
|
11097
|
+
const extendedSlotsNames = Array.from(classType.details.localSlotsNames);
|
10985
11098
|
classType.details.baseClasses.forEach((baseClass) => {
|
10986
11099
|
if ((0, types_1.isInstantiableClass)(baseClass)) {
|
10987
11100
|
if (!types_1.ClassType.isBuiltIn(baseClass, 'object') &&
|
@@ -11821,17 +11934,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11821
11934
|
param.defaultValue.constType === 26 /* None */ &&
|
11822
11935
|
!(0, typeUtils_1.isOptionalType)(type) &&
|
11823
11936
|
!AnalyzerNodeInfo.getFileInfo(param).diagnosticRuleSet.strictParameterNoneValue) {
|
11824
|
-
|
11825
|
-
}
|
11826
|
-
else if ((0, types_1.isTypeVar)(type) && param.defaultValue && type.scopeType === 1 /* Function */) {
|
11827
|
-
// Handle the case where a default argument type is provided when the
|
11828
|
-
// parameter is annotated with a "raw" function-scoped type variable, as in:
|
11829
|
-
// "def foo(value: T = 3)"
|
11830
|
-
// In this case, we need to include the default value type in a union.
|
11831
|
-
const defaultArgType = getTypeOfExpression(param.defaultValue, 1 /* ConvertEllipsisToAny */, (0, typeUtils_1.makeInferenceContext)(type)).type;
|
11832
|
-
if (!(0, types_1.isAny)(defaultArgType)) {
|
11833
|
-
type = (0, types_1.combineTypes)([type, defaultArgType]);
|
11834
|
-
}
|
11937
|
+
return (0, types_1.combineTypes)([type, types_1.NoneType.createInstance()]);
|
11835
11938
|
}
|
11836
11939
|
return type;
|
11837
11940
|
}
|
@@ -11915,7 +12018,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11915
12018
|
case 0 /* Simple */: {
|
11916
12019
|
return type;
|
11917
12020
|
}
|
11918
|
-
case 1 /*
|
12021
|
+
case 1 /* ArgsList */: {
|
11919
12022
|
if ((0, types_1.isTypeVar)(type) && type.paramSpecAccess) {
|
11920
12023
|
return type;
|
11921
12024
|
}
|
@@ -11928,7 +12031,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
11928
12031
|
}
|
11929
12032
|
return types_1.UnknownType.create();
|
11930
12033
|
}
|
11931
|
-
case 2 /*
|
12034
|
+
case 2 /* KwargsDict */: {
|
11932
12035
|
// Leave a ParamSpec alone.
|
11933
12036
|
if ((0, types_1.isTypeVar)(type) && type.paramSpecAccess) {
|
11934
12037
|
return type;
|
@@ -12886,9 +12989,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
12886
12989
|
getTypeOfAnnotation(annotationNode, {
|
12887
12990
|
isVariableAnnotation: ((_a = annotationNode.parent) === null || _a === void 0 ? void 0 : _a.nodeType) === 54 /* TypeAnnotation */,
|
12888
12991
|
allowUnpackedTuple: annotationParent.nodeType === 41 /* Parameter */ &&
|
12889
|
-
annotationParent.category === 1 /*
|
12992
|
+
annotationParent.category === 1 /* ArgsList */,
|
12890
12993
|
allowUnpackedTypedDict: annotationParent.nodeType === 41 /* Parameter */ &&
|
12891
|
-
annotationParent.category === 2 /*
|
12994
|
+
annotationParent.category === 2 /* KwargsDict */,
|
12892
12995
|
});
|
12893
12996
|
return;
|
12894
12997
|
}
|
@@ -13364,8 +13467,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13364
13467
|
return { type: createUnpackType(classType, errorNode, typeArgs, flags) };
|
13365
13468
|
}
|
13366
13469
|
case 'Required':
|
13367
|
-
case 'NotRequired':
|
13368
|
-
|
13470
|
+
case 'NotRequired':
|
13471
|
+
case 'ReadOnly': {
|
13472
|
+
return createRequiredOrReadOnlyType(classType, errorNode, typeArgs, flags);
|
13369
13473
|
}
|
13370
13474
|
case 'Self': {
|
13371
13475
|
return { type: createSelfType(classType, errorNode, typeArgs) };
|
@@ -13803,11 +13907,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
13803
13907
|
// types, under the assumption that we're performing speculative evaluations.
|
13804
13908
|
// If speculativeNode is undefined, speculative mode is not used. This is
|
13805
13909
|
// useful in cases where we conditionally want to use speculative mode.
|
13806
|
-
function useSpeculativeMode(speculativeNode, callback,
|
13910
|
+
function useSpeculativeMode(speculativeNode, callback, dependentType) {
|
13807
13911
|
if (!speculativeNode) {
|
13808
13912
|
return callback();
|
13809
13913
|
}
|
13810
|
-
speculativeTypeTracker.enterSpeculativeContext(speculativeNode,
|
13914
|
+
speculativeTypeTracker.enterSpeculativeContext(speculativeNode, dependentType);
|
13811
13915
|
try {
|
13812
13916
|
const result = callback();
|
13813
13917
|
speculativeTypeTracker.leaveSpeculativeContext();
|
@@ -16005,10 +16109,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16005
16109
|
/* diag */ undefined, destTypeVarContextClone, srcTypeVarContextClone, flags, recursionCount)) {
|
16006
16110
|
filteredOverloads.push(overload);
|
16007
16111
|
if (destTypeVarContextClone) {
|
16008
|
-
|
16112
|
+
(0, collectionUtils_1.appendArray)(destTypeVarSignatures, destTypeVarContextClone.getSignatureContexts());
|
16009
16113
|
}
|
16010
16114
|
if (srcTypeVarContextClone) {
|
16011
|
-
|
16115
|
+
(0, collectionUtils_1.appendArray)(srcTypeVarSignatures, srcTypeVarContextClone.getSignatureContexts());
|
16012
16116
|
}
|
16013
16117
|
}
|
16014
16118
|
});
|
@@ -16562,7 +16666,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16562
16666
|
const srcPositionalsToPack = srcDetails.params.slice(destDetails.argsIndex, srcLastToPackIndex - suffixLength);
|
16563
16667
|
const srcTupleTypes = [];
|
16564
16668
|
srcPositionalsToPack.forEach((entry) => {
|
16565
|
-
if (entry.param.category === 1 /*
|
16669
|
+
if (entry.param.category === 1 /* ArgsList */) {
|
16566
16670
|
if ((0, types_1.isUnpackedVariadicTypeVar)(entry.type)) {
|
16567
16671
|
srcTupleTypes.push({ type: entry.type, isUnbounded: false });
|
16568
16672
|
}
|
@@ -16594,7 +16698,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16594
16698
|
...srcDetails.params.slice(0, destDetails.argsIndex),
|
16595
16699
|
{
|
16596
16700
|
param: {
|
16597
|
-
category: 1 /*
|
16701
|
+
category: 1 /* ArgsList */,
|
16598
16702
|
name: '_arg_combined',
|
16599
16703
|
isNameSynthesized: true,
|
16600
16704
|
hasDeclaredType: true,
|
@@ -16606,9 +16710,9 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16606
16710
|
},
|
16607
16711
|
...srcDetails.params.slice(destDetails.argsIndex + srcPositionalsToPack.length, srcDetails.params.length),
|
16608
16712
|
];
|
16609
|
-
const argsIndex = srcDetails.params.findIndex((param) => param.param.category === 1 /*
|
16713
|
+
const argsIndex = srcDetails.params.findIndex((param) => param.param.category === 1 /* ArgsList */);
|
16610
16714
|
srcDetails.argsIndex = argsIndex >= 0 ? argsIndex : undefined;
|
16611
|
-
const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /*
|
16715
|
+
const kwargsIndex = srcDetails.params.findIndex((param) => param.param.category === 2 /* KwargsDict */);
|
16612
16716
|
srcDetails.kwargsIndex = kwargsIndex >= 0 ? kwargsIndex : undefined;
|
16613
16717
|
const firstKeywordOnlyIndex = srcDetails.params.findIndex((param) => param.source === parameterUtils_1.ParameterSource.KeywordOnly);
|
16614
16718
|
srcDetails.firstKeywordOnlyIndex = firstKeywordOnlyIndex >= 0 ? firstKeywordOnlyIndex : undefined;
|
@@ -16646,8 +16750,8 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16646
16750
|
if (destParamName && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(destParamName) && !(0, symbolNameUtils_1.isPrivateOrProtectedName)(srcParamName)) {
|
16647
16751
|
const isDestPositionalOnly = destParam.source === parameterUtils_1.ParameterSource.PositionOnly;
|
16648
16752
|
if (!isDestPositionalOnly &&
|
16649
|
-
destParam.param.category !== 1 /*
|
16650
|
-
srcParam.param.category !== 1 /*
|
16753
|
+
destParam.param.category !== 1 /* ArgsList */ &&
|
16754
|
+
srcParam.param.category !== 1 /* ArgsList */ &&
|
16651
16755
|
destParamName !== srcParamName) {
|
16652
16756
|
diag === null || diag === void 0 ? void 0 : diag.createAddendum().addMessage(localize_1.Localizer.DiagnosticAddendum.functionParamName().format({
|
16653
16757
|
srcName: srcParamName,
|
@@ -16943,7 +17047,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
16943
17047
|
matchedParamCount++;
|
16944
17048
|
}
|
16945
17049
|
}
|
16946
|
-
else if (
|
17050
|
+
else if ((0, types_1.isPositionOnlySeparator)(p) && remainingParams.length === 0) {
|
16947
17051
|
// Don't bother pushing a position-only separator if it
|
16948
17052
|
// is the first remaining param.
|
16949
17053
|
}
|
@@ -17272,7 +17376,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17272
17376
|
baseParam.category === 0 /* Simple */ &&
|
17273
17377
|
baseParam.name !== overrideParam.name) {
|
17274
17378
|
if (overrideParam.category === 0 /* Simple */) {
|
17275
|
-
if (enforceParamNames) {
|
17379
|
+
if (enforceParamNames && !baseParam.isNameSynthesized) {
|
17276
17380
|
if (overrideParamDetails.params[i].source === parameterUtils_1.ParameterSource.PositionOnly) {
|
17277
17381
|
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
17278
17382
|
index: i + 1,
|
@@ -17292,11 +17396,13 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17292
17396
|
}
|
17293
17397
|
else if (i < overrideParamDetails.positionOnlyParamCount &&
|
17294
17398
|
i >= baseParamDetails.positionOnlyParamCount) {
|
17295
|
-
|
17296
|
-
|
17297
|
-
|
17298
|
-
|
17299
|
-
|
17399
|
+
if (!baseParam.isNameSynthesized) {
|
17400
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.overrideParamNamePositionOnly().format({
|
17401
|
+
index: i + 1,
|
17402
|
+
baseName: baseParam.name || '*',
|
17403
|
+
}));
|
17404
|
+
canOverride = false;
|
17405
|
+
}
|
17300
17406
|
}
|
17301
17407
|
else {
|
17302
17408
|
const baseParamType = baseParamDetails.params[i].type;
|
@@ -17407,6 +17513,11 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17407
17513
|
canOverride = false;
|
17408
17514
|
}
|
17409
17515
|
}
|
17516
|
+
// Verify that one or the other method doesn't contain a ParamSpec.
|
17517
|
+
if (baseMethod.details.paramSpec && !overrideMethod.details.paramSpec) {
|
17518
|
+
diag === null || diag === void 0 ? void 0 : diag.addMessage(localize_1.Localizer.DiagnosticAddendum.paramSpecMissingInOverride());
|
17519
|
+
canOverride = false;
|
17520
|
+
}
|
17410
17521
|
// Now check the return type.
|
17411
17522
|
const baseReturnType = getFunctionEffectiveReturnType(baseMethod);
|
17412
17523
|
const overrideReturnType = getFunctionEffectiveReturnType(overrideMethod);
|
@@ -17783,7 +17894,10 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17783
17894
|
const textValue = node.strings[0].value;
|
17784
17895
|
// Determine the offset within the file where the string
|
17785
17896
|
// literal's contents begin.
|
17786
|
-
|
17897
|
+
let valueOffset = node.strings[0].start;
|
17898
|
+
if (node.strings[0].nodeType === 49 /* String */) {
|
17899
|
+
valueOffset += node.strings[0].token.prefixLength + node.strings[0].token.quoteMarkLength;
|
17900
|
+
}
|
17787
17901
|
const parseOptions = new parser_1.ParseOptions();
|
17788
17902
|
parseOptions.isStubFile = fileInfo.isStubFile;
|
17789
17903
|
parseOptions.pythonVersion = fileInfo.executionEnvironment.pythonVersion;
|
@@ -17859,7 +17973,7 @@ function createTypeEvaluator(importLookup, evaluatorOptions) {
|
|
17859
17973
|
validateOverloadedFunctionArguments,
|
17860
17974
|
isAfterNodeReachable,
|
17861
17975
|
isNodeReachable,
|
17862
|
-
isAsymmetricDescriptorAssignment,
|
17976
|
+
isAsymmetricDescriptorAssignment: isAsymmetricAccessorAssignment,
|
17863
17977
|
suppressDiagnostics,
|
17864
17978
|
getDeclarationsForStringNode,
|
17865
17979
|
getDeclarationsForNameNode,
|