From 9b4ffc05710873e69bfeed209d0f7ebd8fb2f259 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 2 Jul 2020 17:47:52 -0400 Subject: [PATCH] Changed unions to ReadableBuffer and WriteableBuffer --- shared-bindings/_bleio/Address.c | 2 +- shared-bindings/_bleio/CharacteristicBuffer.c | 2 +- shared-bindings/_bleio/Descriptor.c | 2 +- shared-bindings/_bleio/PacketBuffer.c | 2 +- shared-bindings/_bleio/UUID.c | 2 +- shared-bindings/aesio/aes.c | 6 +++--- shared-bindings/audiobusio/PDMIn.c | 2 +- shared-bindings/audiocore/WaveFile.c | 2 +- shared-bindings/audiomp3/MP3Decoder.c | 2 +- shared-bindings/bitbangio/I2C.c | 6 +++--- shared-bindings/bitbangio/SPI.c | 6 +++--- shared-bindings/busio/I2C.c | 6 +++--- shared-bindings/busio/SPI.c | 4 ++-- shared-bindings/busio/UART.c | 4 ++-- 14 files changed, 24 insertions(+), 24 deletions(-) diff --git a/shared-bindings/_bleio/Address.c b/shared-bindings/_bleio/Address.c index 87bae19cee..06fb58d76a 100644 --- a/shared-bindings/_bleio/Address.c +++ b/shared-bindings/_bleio/Address.c @@ -38,7 +38,7 @@ //| """Encapsulates the address of a BLE device.""" //| -//| def __init__(self, address: Union[bytes, bytearray, memoryview], address_type: int): +//| def __init__(self, address: ReadableBuffer, address_type: int): //| """Create a new Address object encapsulating the address value. //| The value itself can be one of: //| diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c index ee5a8ea332..efe27e5d2a 100644 --- a/shared-bindings/_bleio/CharacteristicBuffer.c +++ b/shared-bindings/_bleio/CharacteristicBuffer.c @@ -110,7 +110,7 @@ STATIC void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { //| :rtype: bytes or None""" //| ... //| -//| def readinto(self, buf: Union[bytearray, memoryview]) -> Optional[int]: +//| def readinto(self, buf: WriteableBuffer) -> Optional[int]: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. //| //| :return: number of bytes read and stored into ``buf`` diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c index b478e85e12..6382221a16 100644 --- a/shared-bindings/_bleio/Descriptor.c +++ b/shared-bindings/_bleio/Descriptor.c @@ -167,7 +167,7 @@ const mp_obj_property_t bleio_descriptor_characteristic_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| value: Union[bytearray, memoryview] = ... +//| value: WriteableBuffer = ... //| """The value of this descriptor.""" //| STATIC mp_obj_t bleio_descriptor_get_value(mp_obj_t self_in) { diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c index a5b017312c..7645a25aaa 100644 --- a/shared-bindings/_bleio/PacketBuffer.c +++ b/shared-bindings/_bleio/PacketBuffer.c @@ -93,7 +93,7 @@ STATIC void check_for_deinit(bleio_packet_buffer_obj_t *self) { } } -//| def readinto(self, buf: Union[bytearray, memoryview]) -> int: +//| def readinto(self, buf: WriteableBuffer) -> int: //| """Reads a single BLE packet into the ``buf``. Raises an exception if the next packet is longer //| than the given buffer. Use `packet_size` to read the maximum length of a single packet. //| diff --git a/shared-bindings/_bleio/UUID.c b/shared-bindings/_bleio/UUID.c index a36cade6a0..823275f900 100644 --- a/shared-bindings/_bleio/UUID.c +++ b/shared-bindings/_bleio/UUID.c @@ -186,7 +186,7 @@ const mp_obj_property_t bleio_uuid_size_obj = { }; -//| def pack_into(self, buffer: Union[bytearray, memoryview], offset: int = 0) -> None: +//| def pack_into(self, buffer: WriteableBuffer, offset: int = 0) -> None: //| """Packs the UUID into the given buffer at the given offset.""" //| ... //| diff --git a/shared-bindings/aesio/aes.c b/shared-bindings/aesio/aes.c index c8d4ee82ca..df6d0c5676 100644 --- a/shared-bindings/aesio/aes.c +++ b/shared-bindings/aesio/aes.c @@ -12,7 +12,7 @@ //| class AES: //| """Encrypt and decrypt AES streams""" //| -//| def __init__(self, key: Union[bytes, bytearray, memoryview], mode: int=0, iv: Union[bytes, bytearray, memoryview]=None, segment_size: int=8) -> AES: +//| def __init__(self, key: ReadableBuffer, mode: int=0, iv: ReadableBuffer=None, segment_size: int=8) -> AES: //| """Create a new AES state with the given key. //| //| :param bytearray key: A 16-, 24-, or 32-byte key @@ -152,7 +152,7 @@ STATIC void validate_length(aesio_aes_obj_t *self, size_t src_length, } } -//| def encrypt_into(src: Union[bytearray, memoryview], dest: Union[bytearray, memoryview]) -> None: +//| def encrypt_into(src: WriteableBuffer, dest: WriteableBuffer) -> None: //| """Encrypt the buffer from ``src`` into ``dest``. //| //| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the @@ -183,7 +183,7 @@ STATIC mp_obj_t aesio_aes_encrypt_into(mp_obj_t aesio_obj, mp_obj_t src, STATIC MP_DEFINE_CONST_FUN_OBJ_3(aesio_aes_encrypt_into_obj, aesio_aes_encrypt_into); -//| def decrypt_into(src: Union[bytearray, memoryview], dest: Union[bytearray, memoryview]) -> None: +//| def decrypt_into(src: WriteableBuffer, dest: WriteableBuffer) -> None: //| //| """Decrypt the buffer from ``src`` into ``dest``. //| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index cfb19d7ce3..329c7bde53 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -168,7 +168,7 @@ STATIC mp_obj_t audiobusio_pdmin_obj___exit__(size_t n_args, const mp_obj_t *arg STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4, audiobusio_pdmin_obj___exit__); -//| def record(self, destination: Union[bytearray, memoryview], destination_length: int) -> None: +//| def record(self, destination: WriteableBuffer, destination_length: int) -> None: //| """Records destination_length bytes of samples to destination. This is //| blocking. //| diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c index 4eed5eaca5..838447f2e1 100644 --- a/shared-bindings/audiocore/WaveFile.c +++ b/shared-bindings/audiocore/WaveFile.c @@ -40,7 +40,7 @@ //| be 8 bit unsigned or 16 bit signed. If a buffer is provided, it will be used instead of allocating //| an internal buffer.""" //| -//| def __init__(self, file: typing.BinaryIO, buffer: Union[bytes, bytearray, memoryview]): +//| def __init__(self, file: typing.BinaryIO, buffer: ReadableBuffer): //| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. //| //| :param typing.BinaryIO file: Already opened wave file diff --git a/shared-bindings/audiomp3/MP3Decoder.c b/shared-bindings/audiomp3/MP3Decoder.c index a4fd6e61f6..68c27169ff 100644 --- a/shared-bindings/audiomp3/MP3Decoder.c +++ b/shared-bindings/audiomp3/MP3Decoder.c @@ -37,7 +37,7 @@ //| class MP3: //| """Load a mp3 file for audio playback""" //| -//| def __init__(self, file: typing.BinaryIO, buffer: Union[bytearray, memoryview]): +//| def __init__(self, file: typing.BinaryIO, buffer: WriteableBuffer): //| //| """Load a .mp3 file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. //| diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index b10110430e..710275b2f6 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -165,7 +165,7 @@ STATIC mp_obj_t bitbangio_i2c_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_i2c_unlock_obj, bitbangio_i2c_obj_unlock); -//| def readfrom_into(self, address: int, buffer: Union[bytearray, memoryview], *, start: int = 0, end: int = None) -> None: +//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = None) -> None: //| """Read into ``buffer`` from the device selected by ``address``. //| The number of bytes read will be the length of ``buffer``. //| At least one byte must be read. @@ -217,7 +217,7 @@ STATIC mp_obj_t bitbangio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_a } MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_readfrom_into_obj, 3, bitbangio_i2c_readfrom_into); -//| def writeto(self, address: int, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None, stop: bool = True) -> None: +//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = None, stop: bool = True) -> None: //| """Write the bytes from ``buffer`` to the device selected by ``address`` and then transmits a //| stop bit. Use `writeto_then_readfrom` when needing a write, no stop and repeated start //| before a read. @@ -277,7 +277,7 @@ STATIC mp_obj_t bitbangio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, m STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bitbangio_i2c_writeto_obj, 1, bitbangio_i2c_writeto); -//| def writeto_then_readfrom(self, address: int, out_buffer: Union[bytearray, memoryview], in_buffer: Union[bytes, bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: +//| def writeto_then_readfrom(self, address: int, out_buffer: WriteableBuffer, in_buffer: ReadableBuffer, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: //| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop //| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and //| ``in_buffer`` can be the same buffer because they are used sequentially. diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 597d8602be..90483e3ebf 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -200,7 +200,7 @@ STATIC mp_obj_t bitbangio_spi_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(bitbangio_spi_unlock_obj, bitbangio_spi_obj_unlock); -//| def write(self, buf: Union[bytes, bytearray, memoryview]) -> None: +//| def write(self, buf: ReadableBuffer) -> None: //| """Write the data contained in ``buf``. Requires the SPI being locked. //| If the buffer is empty, nothing happens.""" //| ... @@ -224,7 +224,7 @@ STATIC mp_obj_t bitbangio_spi_write(mp_obj_t self_in, mp_obj_t wr_buf) { MP_DEFINE_CONST_FUN_OBJ_2(bitbangio_spi_write_obj, bitbangio_spi_write); -//| def readinto(self, buf: Union[bytearray, memoryview]) -> None: +//| def readinto(self, buf: WriteableBuffer) -> None: //| """Read into the buffer specified by ``buf`` while writing zeroes. //| Requires the SPI being locked. //| If the number of bytes to read is 0, nothing happens.""" @@ -248,7 +248,7 @@ STATIC mp_obj_t bitbangio_spi_readinto(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bitbangio_spi_readinto_obj, 2, 2, bitbangio_spi_readinto); -//| def write_readinto(self, buffer_out: Union[bytes, bytearray, memoryview], buffer_in: Union[bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: +//| def write_readinto(self, buffer_out: ReadableBuffer, buffer_in: WriteableBuffer, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: //| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``. //| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]`` //| must be equal. diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 2b3497c422..cf38fdce60 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -176,7 +176,7 @@ STATIC mp_obj_t busio_i2c_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_i2c_unlock_obj, busio_i2c_obj_unlock); -//| def readfrom_into(self, address: int, buffer: Union[bytearray, memoryview], *, start: int = 0, end: int = None) -> None: +//| def readfrom_into(self, address: int, buffer: WriteableBuffer, *, start: int = 0, end: int = None) -> None: //| """Read into ``buffer`` from the device selected by ``address``. //| The number of bytes read will be the length of ``buffer``. //| At least one byte must be read. @@ -228,7 +228,7 @@ STATIC mp_obj_t busio_i2c_readfrom_into(size_t n_args, const mp_obj_t *pos_args, } MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_readfrom_into_obj, 3, busio_i2c_readfrom_into); -//| def writeto(self, address: int, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None, stop: bool = True) -> None: +//| def writeto(self, address: int, buffer: ReadableBuffer, *, start: int = 0, end: int = None, stop: bool = True) -> None: //| """Write the bytes from ``buffer`` to the device selected by ``address``. //| Transmits a stop bit when stop is True. Setting stop=False is deprecated and stop will be //| removed in CircuitPython 6.x. Use `writeto_then_readfrom` when needing a write, no stop and @@ -287,7 +287,7 @@ STATIC mp_obj_t busio_i2c_writeto(size_t n_args, const mp_obj_t *pos_args, mp_ma } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(busio_i2c_writeto_obj, 1, busio_i2c_writeto); -//| def writeto_then_readfrom(self, address: int, out_buffer: Union[bytes, bytearray, memoryview], in_buffer: Union[bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: +//| def writeto_then_readfrom(self, address: int, out_buffer: ReadableBuffer, in_buffer: WriteableBuffer, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: //| """Write the bytes from ``out_buffer`` to the device selected by ``address``, generate no stop //| bit, generate a repeated start and read into ``in_buffer``. ``out_buffer`` and //| ``in_buffer`` can be the same buffer because they are used sequentially. diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index e5b0da4a65..38c1bcc0e7 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -228,7 +228,7 @@ STATIC mp_obj_t busio_spi_obj_unlock(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(busio_spi_unlock_obj, busio_spi_obj_unlock); -//| def write(self, buffer: Union[bytes, bytearray, memoryview], *, start: int = 0, end: int = None) -> None: +//| def write(self, buffer: ReadableBuffer, *, start: int = 0, end: int = None) -> None: //| """Write the data contained in ``buffer``. The SPI object must be locked. //| If the buffer is empty, nothing happens. //| @@ -314,7 +314,7 @@ STATIC mp_obj_t busio_spi_readinto(size_t n_args, const mp_obj_t *pos_args, mp_m } MP_DEFINE_CONST_FUN_OBJ_KW(busio_spi_readinto_obj, 2, busio_spi_readinto); -//| def write_readinto(self, buffer_out: Union[bytes, bytearray, memoryview], buffer_in: Union[bytes, bytearray, memoryview], *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: +//| def write_readinto(self, buffer_out: ReadableBuffer, buffer_in: ReadableBuffer, *, out_start: int = 0, out_end: int = None, in_start: int = 0, in_end: int = None) -> None: //| """Write out the data in ``buffer_out`` while simultaneously reading data into ``buffer_in``. //| The SPI object must be locked. //| The lengths of the slices defined by ``buffer_out[out_start:out_end]`` and ``buffer_in[in_start:in_end]`` diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 2ce1467bbb..fd51d5d3b6 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -190,7 +190,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_ //| ... //| -//| def readinto(self, buf: Union[bytearray, memoryview]) -> Optional[int]: +//| def readinto(self, buf: WriteableBuffer) -> Optional[int]: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. //| //| :return: number of bytes read and stored into ``buf`` @@ -208,7 +208,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(busio_uart___exit___obj, 4, 4, busio_ //| ... //| -//| def write(self, buf: Union[bytearray, memoryview]) -> Optional[int]: +//| def write(self, buf: WriteableBuffer) -> Optional[int]: //| """Write the buffer of bytes to the bus. //| //| *New in CircuitPython 4.0:* ``buf`` must be bytes, not a string.