@@ -641,7 +641,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
641
641
642
642
if name : # Special method names
643
643
if name in nodes .reverse_op_method_set :
644
- self .check_reverse_op_method (item , typ , name )
644
+ self .check_reverse_op_method (item , typ , name , defn )
645
645
elif name in ('__getattr__' , '__getattribute__' ):
646
646
self .check_getattr_method (typ , defn , name )
647
647
elif name == '__setattr__' :
@@ -820,13 +820,24 @@ def is_trivial_body(self, block: Block) -> bool:
820
820
isinstance (stmt .expr , EllipsisExpr )))
821
821
822
822
def check_reverse_op_method (self , defn : FuncItem , typ : CallableType ,
823
- method : str ) -> None :
823
+ method : str , context : Context ) -> None :
824
824
"""Check a reverse operator method such as __radd__."""
825
825
826
826
# This used to check for some very obscure scenario. It now
827
827
# just decides whether it's worth calling
828
828
# check_overlapping_op_methods().
829
829
830
+ # First check for a valid signature
831
+ method_type = CallableType ([AnyType (TypeOfAny .special_form ),
832
+ AnyType (TypeOfAny .special_form )],
833
+ [nodes .ARG_POS , nodes .ARG_POS ],
834
+ [None , None ],
835
+ AnyType (TypeOfAny .special_form ),
836
+ self .named_type ('builtins.function' ))
837
+ if not is_subtype (typ , method_type ):
838
+ self .msg .invalid_signature (typ , context )
839
+ return
840
+
830
841
if method in ('__eq__' , '__ne__' ):
831
842
# These are defined for all objects => can't cause trouble.
832
843
return
@@ -839,9 +850,8 @@ def check_reverse_op_method(self, defn: FuncItem, typ: CallableType,
839
850
if isinstance (ret_type , Instance ):
840
851
if ret_type .type .fullname () == 'builtins.object' :
841
852
return
842
- # Plausibly the method could have too few arguments, which would result
843
- # in an error elsewhere.
844
- if len (typ .arg_types ) <= 2 :
853
+
854
+ if len (typ .arg_types ) == 2 :
845
855
# TODO check self argument kind
846
856
847
857
# Check for the issue described above.
0 commit comments