This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abarnert
Recipients Ramchandra Apte, abarnert, christian.heimes, georg.brandl, gvanrossum, josh.r, martin.panter, pitrou, rhettinger, serhiy.storchaka, terry.reedy, vstinner
Date 2016-01-08.00:42:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452213731.3.0.984520347521.issue19251@psf.upfronthosting.co.za>
In-reply-to
Content
For what it's worth, I looked at some old code (a clean re-implementation of a crypto algorithm in Python, used as a unit test for production code in C++) and found this:

class BytesBits(bytes):
    # from a quick test, 1.12us in NumPy, 1.39us in C, 2.55us this way, 46.1us with bytes(genexpr), so we don't need numpy
    def _bitwise(self, other, op):
        iself = int.from_bytes(self, 'little')
        iother = int.from_bytes(other, 'little')
        b = op(iself, iother)
        return b.to_bytes(len(self), 'little')
    def __or__(self, other):
        return self._bitwise(other, int.__or__)
    __ror__ = __or__
    def __and__(self, other):
        return self._bitwise(other, int.__and__)
    __rand__ = __and__
    def __xor__(self, other):
        return self._bitwise(other, int.__xor__)
    __rxor__ = __xor__
    
It doesn't do as much error checking as you want, but it was good enough for my purposes.

At any rate, the fact that it's trivial to wrap this up yourself (and even more so if you just write functions called band/bor/bxor instead of wrapping them up in a subclass) implies to me that, if it's not used all that often, it doesn't need to be on the builtin types.
History
Date User Action Args
2016-01-08 00:42:11abarnertsetrecipients: + abarnert, gvanrossum, georg.brandl, rhettinger, terry.reedy, pitrou, vstinner, christian.heimes, Ramchandra Apte, martin.panter, serhiy.storchaka, josh.r
2016-01-08 00:42:11abarnertsetmessageid: <1452213731.3.0.984520347521.issue19251@psf.upfronthosting.co.za>
2016-01-08 00:42:11abarnertlinkissue19251 messages
2016-01-08 00:42:10abarnertcreate