@@ -635,14 +635,22 @@ def _defined_method(self: RuntimeExpr, *args, __name: str = name, **kwargs):
635635
636636
637637for name , r_method in itertools .product (NUMERIC_BINARY_METHODS , (False , True )):
638+ method_name = f"__r{ name [2 :]} " if r_method else name
638639
639- def _numeric_binary_method (self : object , other : object , name : str = name , r_method : bool = r_method ) -> object :
640+ def _numeric_binary_method (
641+ self : object , other : object , name : str = name , r_method : bool = r_method , method_name : str = method_name
642+ ) -> object :
640643 """
641644 Implements numeric binary operations.
642645
643646 Tries to find the minimum cost conversion of either the LHS or the RHS, by finding all methods with either
644647 the LHS or the RHS as exactly the right type and then upcasting the other to that type.
645648 """
649+ # First check if we have a preserved method for this:
650+ if isinstance (self , RuntimeExpr ) and (
651+ (preserved_method := self .__egg_class_decl__ .preserved_methods .get (method_name )) is not None
652+ ):
653+ return preserved_method .__get__ (self )(other )
646654 # 1. switch if reversed method
647655 if r_method :
648656 self , other = other , self
@@ -668,7 +676,6 @@ def _numeric_binary_method(self: object, other: object, name: str = name, r_meth
668676 fn = RuntimeFunction (Thunk .value (self .__egg_decls__ ), Thunk .value (method_ref ), self )
669677 return fn (other )
670678
671- method_name = f"__r{ name [2 :]} " if r_method else name
672679 setattr (RuntimeExpr , method_name , _numeric_binary_method )
673680
674681
0 commit comments