Skip to content

Commit

Permalink
Ensure we iterate over the longest in bitwise on bigbitdata.
Browse files Browse the repository at this point in the history
Replaces #2810
  • Loading branch information
coleifer committed Dec 1, 2023
1 parent 6286684 commit 110faf3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -5118,7 +5118,8 @@ def _bitwise_op(self, other, op):
else:
raise ValueError('Incompatible data-type')
buf = bytearray(b'\x00' * max(len(self), len(other)))
for i, (a, b) in enumerate(zip(self._buffer, data)):
it = itertools.zip_longest(self._buffer, data, fillvalue=0)
for i, (a, b) in enumerate(it):
buf[i] = op(a, b)
return buf

Expand Down
10 changes: 10 additions & 0 deletions tests/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,16 @@ def test_bigbit_field_bitwise(self):
b1.data ^= b3.data
self.assertEqual(b1.data._buffer, b'\x8b')

b1.data = b'\x11'
self.assertEqual(b1.data & b'\xff\xff', b'\x11\x00')
self.assertEqual(b1.data | b'\xff\xff', b'\xff\xff')
self.assertEqual(b1.data ^ b'\xff\xff', b'\xee\xff')

b1.data = b'\x11\x11'
self.assertEqual(b1.data & b'\xff', b'\x11\x00')
self.assertEqual(b1.data | b'\xff', b'\xff\x11')
self.assertEqual(b1.data ^ b'\xff', b'\xee\x11')

def test_bigbit_field_bulk_create(self):
b1, b2, b3 = Bits(), Bits(), Bits()
b1.data.set_bit(1)
Expand Down

0 comments on commit 110faf3

Please sign in to comment.