From a65c03c6c07fa8b092f7cd8d02c81e9ef8cd4a50 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 5 Nov 2014 16:30:34 +0000 Subject: py: Allow +, in, and compare ops between bytes and bytearray/array. Eg b"123" + bytearray(2) now works. This patch actually decreases code size while adding functionality: 32-bit unix down by 128 bytes, stmhal down by 84 bytes. --- tests/basics/bytes_add.py | 9 +++++++++ tests/basics/bytes_compare2.py | 11 ++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/basics/bytes_add.py (limited to 'tests') diff --git a/tests/basics/bytes_add.py b/tests/basics/bytes_add.py new file mode 100644 index 000000000..1288d5ac3 --- /dev/null +++ b/tests/basics/bytes_add.py @@ -0,0 +1,9 @@ +# test bytes + other + +print(b"123" + b"456") +print(b"123" + bytearray(2)) + +import array + +print(b"123" + array.array('i', [1])) +print(b"\x01\x02" + array.array('b', [1, 2])) diff --git a/tests/basics/bytes_compare2.py b/tests/basics/bytes_compare2.py index 769d76b11..02516de93 100644 --- a/tests/basics/bytes_compare2.py +++ b/tests/basics/bytes_compare2.py @@ -1,7 +1,12 @@ -import array - print(b"1" == 1) print(b"123" == bytearray(b"123")) print(b"123" == "123") -# CPyhon gives False here +print(b'123' < bytearray(b"124")) +print(b'123' > bytearray(b"122")) +print(bytearray(b"23") in b"1234") + +import array + +print(array.array('b', [1, 2]) in b'\x01\x02\x03') +# CPython gives False here #print(b"\x01\x02\x03" == array.array("B", [1, 2, 3])) -- cgit v1.2.3