File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -900,7 +900,17 @@ def analyze_var(
900900 and call_type .type .is_protocol
901901 and call_type .type .get_method ("__call__" )
902902 ):
903- call_type = get_proper_type (_analyze_member_access ("__call__" , typ , mx ))
903+ # This is ugly, but it reflects the reality that Python treats
904+ # real functions and callable objects differently in class bodies.
905+ # We want to make callback protocols behave like the former.
906+ proto_mx = mx .copy_modified (original_type = typ , self_type = typ , is_lvalue = False )
907+ call_type = get_proper_type (_analyze_member_access ("__call__" , typ , proto_mx ))
908+ if isinstance (call_type , CallableType ):
909+ call_type = call_type .copy_modified (is_bound = False )
910+ elif isinstance (call_type , Overloaded )
911+ call_type = Overloaded (
912+ [it .copy_modified (is_bound = False ) for it in call_type .items ()]
913+ )
904914
905915 # Bound variables with callable types are treated like methods
906916 # (these are usually method aliases like __rmul__ = __mul__).
You can’t perform that action at this time.
0 commit comments