subclass_native_buffer.py 326 B

12345678910111213141516
  1. # test when we subclass a type with the buffer protocol
  2. class my_bytes(bytes):
  3. pass
  4. b1 = my_bytes([0, 1])
  5. b2 = my_bytes([2, 3])
  6. b3 = bytes([4, 5])
  7. # addition will use the buffer protocol on the RHS
  8. print(b1 + b2)
  9. print(b1 + b3)
  10. print(b3 + b1)
  11. # bytearray construction will use the buffer protocol
  12. print(bytearray(b1))