@@ -649,26 +649,11 @@ def incompatible_argument(
649649 else :
650650 base = extract_type (name )
651651
652- for method , op in op_methods_to_symbols .items ():
653- for variant in method , "__r" + method [2 :]:
654- # FIX: do not rely on textual formatting
655- if name .startswith (f'"{ variant } " of' ):
656- if op == "in" or variant != method :
657- # Reversed order of base/argument.
658- return self .unsupported_operand_types (
659- op , arg_type , base , context , code = codes .OPERATOR
660- )
661- else :
662- return self .unsupported_operand_types (
663- op , base , arg_type , context , code = codes .OPERATOR
664- )
665-
666652 if name .startswith ('"__getitem__" of' ):
667653 return self .invalid_index_type (
668654 arg_type , callee .arg_types [n - 1 ], base , context , code = codes .INDEX
669655 )
670-
671- if name .startswith ('"__setitem__" of' ):
656+ elif name .startswith ('"__setitem__" of' ):
672657 if n == 1 :
673658 return self .invalid_index_type (
674659 arg_type , callee .arg_types [n - 1 ], base , context , code = codes .INDEX
@@ -684,6 +669,20 @@ def incompatible_argument(
684669 message_registry .INCOMPATIBLE_TYPES_IN_ASSIGNMENT .with_additional_msg (info )
685670 )
686671 return self .fail (error_msg .value , context , code = error_msg .code )
672+ elif name .startswith ('"__' ):
673+ for method , op in op_methods_to_symbols .items ():
674+ for variant in method , "__r" + method [2 :]:
675+ # FIX: do not rely on textual formatting
676+ if name .startswith (f'"{ variant } " of' ):
677+ if op == "in" or variant != method :
678+ # Reversed order of base/argument.
679+ return self .unsupported_operand_types (
680+ op , arg_type , base , context , code = codes .OPERATOR
681+ )
682+ else :
683+ return self .unsupported_operand_types (
684+ op , base , arg_type , context , code = codes .OPERATOR
685+ )
687686
688687 target = f"to { name } "
689688
0 commit comments