skreft <skr...@gmail.com> added the comment:

One possible refactor would be.

import operator

   def logical_or(self, other, context=None):
       return self._logical_op(other, operator.__or__, context)

   def logical_xor(self, other, context=None):
       return self._logical_op(other, operator.__xor__, context)

   def logical_and(self, other, context=None):
       return self._logical_op(other, operator.__and__, context)

   def _logical_op(self, other, operation, context=None):
        """Applies a logical operation between self and other's digits."""
        if context is None:
            context = getcontext()

        other = _convert_other(other, raiseit=True)

        if not self._islogical() or not other._islogical():
            return context._raise_error(InvalidOperation)

        # fill to context.prec
        (opa, opb) = self._fill_logical(context, self._int, other._int)

        # make the operation, and clean starting zeroes
        result = "".join([str(operation(int(a), int(b))) for a,b in 
zip(opa,opb)])
        return _dec_from_triple(0, result.lstrip('0') or '0', 0)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13364>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to