@@ -5670,22 +5670,29 @@ def find_isinstance_check_helper(self, node: Expression) -> tuple[TypeMap, TypeM
5670
5670
if node .arg_kinds [0 ] != nodes .ARG_POS :
5671
5671
# the first argument might be used as a kwarg
5672
5672
called_type = get_proper_type (self .lookup_type (node .callee ))
5673
- assert isinstance (called_type , (CallableType , Overloaded ))
5673
+
5674
+ # TODO: there are some more cases in check_call() to handle.
5675
+ if isinstance (called_type , Instance ):
5676
+ call = find_member (
5677
+ "__call__" , called_type , called_type , is_operator = True
5678
+ )
5679
+ if call is not None :
5680
+ called_type = get_proper_type (call )
5674
5681
5675
5682
# *assuming* the overloaded function is correct, there's a couple cases:
5676
5683
# 1) The first argument has different names, but is pos-only. We don't
5677
5684
# care about this case, the argument must be passed positionally.
5678
5685
# 2) The first argument allows keyword reference, therefore must be the
5679
5686
# same between overloads.
5680
- name = called_type . items [ 0 ]. arg_names [ 0 ]
5681
-
5682
- if name in node .arg_names :
5683
- idx = node .arg_names .index (name )
5684
- # we want the idx-th variable to be narrowed
5685
- expr = collapse_walrus (node .args [idx ])
5686
- else :
5687
- self .fail (message_registry .TYPE_GUARD_POS_ARG_REQUIRED , node )
5688
- return {}, {}
5687
+ if isinstance ( called_type , ( CallableType , Overloaded )):
5688
+ name = called_type . items [ 0 ]. arg_names [ 0 ]
5689
+ if name in node .arg_names :
5690
+ idx = node .arg_names .index (name )
5691
+ # we want the idx-th variable to be narrowed
5692
+ expr = collapse_walrus (node .args [idx ])
5693
+ else :
5694
+ self .fail (message_registry .TYPE_GUARD_POS_ARG_REQUIRED , node )
5695
+ return {}, {}
5689
5696
if literal (expr ) == LITERAL_TYPE :
5690
5697
# Note: we wrap the target type, so that we can special case later.
5691
5698
# Namely, for isinstance() we use a normal meet, while TypeGuard is
0 commit comments