Skip to content

Commit 7f4eb00

Browse files
Fix type errors
1 parent 7bab569 commit 7f4eb00

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

mypy/checker.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6236,11 +6236,9 @@ def find_isinstance_check_helper(
62366236
consider_runtime_isinstance=False,
62376237
),
62386238
)
6239-
elif isinstance(node.callee, CallExpr):
6239+
elif isinstance(node.callee, CallExpr) and len(node.args) != 0:
62406240
# Handle case where callee is a call expression like E()(x)
62416241
# where E() returns an object with __call__ method that has TypeGuard
6242-
if len(node.args) == 0:
6243-
return {}, {}
62446242
callee_type = get_proper_type(self.lookup_type(node.callee))
62456243
if isinstance(callee_type, Instance):
62466244
call_member = find_member(
@@ -6255,33 +6253,25 @@ def find_isinstance_check_helper(
62556253
# Handle keyword arguments similar to RefExpr case
62566254
expr = collapse_walrus(node.args[0]) # Default to first positional arg
62576255
if node.arg_kinds[0] != nodes.ARG_POS:
6258-
# the first argument might be used as a kwarg
6259-
if isinstance(call_type, (CallableType, Overloaded)):
6260-
if isinstance(call_type, Overloaded):
6261-
# Use first overload for argument name lookup
6262-
first_callable = call_type.items[0]
6256+
if call_type.arg_names:
6257+
name = call_type.arg_names[0]
6258+
if name in node.arg_names:
6259+
idx = node.arg_names.index(name)
6260+
# we want the idx-th variable to be narrowed
6261+
expr = collapse_walrus(node.args[idx])
62636262
else:
6264-
first_callable = call_type
6265-
6266-
if first_callable.arg_names:
6267-
name = first_callable.arg_names[0]
6268-
if name in node.arg_names:
6269-
idx = node.arg_names.index(name)
6270-
# we want the idx-th variable to be narrowed
6271-
expr = collapse_walrus(node.args[idx])
6272-
else:
6273-
kind = (
6274-
"guard"
6275-
if call_type.type_guard is not None
6276-
else "narrower"
6277-
)
6278-
self.fail(
6279-
message_registry.TYPE_GUARD_POS_ARG_REQUIRED.format(
6280-
kind
6281-
),
6282-
node,
6283-
)
6284-
return {}, {}
6263+
kind = (
6264+
"guard"
6265+
if call_type.type_guard is not None
6266+
else "narrower"
6267+
)
6268+
self.fail(
6269+
message_registry.TYPE_GUARD_POS_ARG_REQUIRED.format(
6270+
kind
6271+
),
6272+
node,
6273+
)
6274+
return {}, {}
62856275

62866276
if literal(expr) == LITERAL_TYPE:
62876277
# Apply the same TypeGuard narrowing logic

0 commit comments

Comments
 (0)