@@ -6526,33 +6526,35 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
6526
6526
// Speculatively attempt the call. We may need to replace the index
6527
6527
// type with 'int', and we don't want to emit errors before we know
6528
6528
// which type to use.
6529
- useSpeculativeMode(node, () => {
6530
- callResult = validateCallArguments(node, argList, { type: itemMethodType });
6531
-
6532
- if (callResult.argumentErrors) {
6533
- // If the object supports "__index__" magic method, convert
6534
- // the index it to an int and try again.
6535
- if (isClassInstance(positionalIndexType) && keywordArgs.length === 0 && unpackedDictArgs.length === 0) {
6536
- const altArgList = [...argList];
6537
- altArgList[0] = { ...altArgList[0] };
6538
- const indexMethod = getTypeOfObjectMember(node, positionalIndexType, '__index__');
6539
-
6540
- if (indexMethod) {
6541
- const intType = getBuiltInObject(node, 'int');
6542
- if (isClassInstance(intType)) {
6543
- altArgList[0].type = intType;
6529
+ if (keywordArgs.length === 0 && unpackedDictArgs.length === 0 && positionalArgs.length === 1) {
6530
+ useSpeculativeMode(node, () => {
6531
+ callResult = validateCallArguments(node, argList, { type: itemMethodType });
6532
+
6533
+ if (callResult.argumentErrors) {
6534
+ // If the object supports "__index__" magic method, convert
6535
+ // the index to an int and try again.
6536
+ if (isClassInstance(positionalIndexType)) {
6537
+ const altArgList = [...argList];
6538
+ altArgList[0] = { ...altArgList[0] };
6539
+ const indexMethod = getTypeOfObjectMember(node, positionalIndexType, '__index__');
6540
+
6541
+ if (indexMethod) {
6542
+ const intType = getBuiltInObject(node, 'int');
6543
+ if (isClassInstance(intType)) {
6544
+ altArgList[0].type = intType;
6545
+ }
6544
6546
}
6545
- }
6546
6547
6547
- callResult = validateCallArguments(node, altArgList, { type: itemMethodType });
6548
+ callResult = validateCallArguments(node, altArgList, { type: itemMethodType });
6548
6549
6549
- // We were successful, so replace the arg list.
6550
- if (!callResult.argumentErrors) {
6551
- argList = altArgList;
6550
+ // We were successful, so replace the arg list.
6551
+ if (!callResult.argumentErrors) {
6552
+ argList = altArgList;
6553
+ }
6552
6554
}
6553
6555
}
6554
- }
6555
- });
6556
+ });
6557
+ }
6556
6558
6557
6559
callResult = validateCallArguments(node, argList, { type: itemMethodType });
6558
6560
0 commit comments