def call_highest_priority(method_name):
 def priority_decorator(func):
  @wraps(func)
  def binary_op_wrapper(self, other):
   if hasattr(other, '_op_priority'):
    if (other._op_priority > self._op_priority):
     try:
      f = getattr(other, method_name)
     except AttributeError:
      pass
     else:
      return f(self)
   return func(self, other)
  return binary_op_wrapper
 return priority_decorator

def call_highest_priority ( method_name ) : def priority_decorator ( func ) : @ wraps ( func ) def binary_op_wrapper ( self , other ) : if hasattr ( other , '_op_priority' ) : if ( other . _op_priority > self . _op_priority ) : try : f = getattr ( other , method_name ) except AttributeError : pass else : return f ( self ) return func ( self , other ) return binary_op_wrapper return priority_decorator
a decorator for binary special methods to handle _op_priority .