From 26f1fd00719ef0c5dc904e9b6f03ad2a90e2abdc Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 2 Jul 2020 14:11:25 -0400 Subject: [PATCH] Added type hints to _bleio --- shared-bindings/_bleio/Adapter.c | 26 ++++++++--------- shared-bindings/_bleio/Address.c | 20 ++++++------- shared-bindings/_bleio/Attribute.c | 16 +++++------ shared-bindings/_bleio/Characteristic.c | 28 +++++++++---------- shared-bindings/_bleio/CharacteristicBuffer.c | 12 ++++---- shared-bindings/_bleio/Connection.c | 16 +++++------ shared-bindings/_bleio/Descriptor.c | 8 +++--- shared-bindings/_bleio/PacketBuffer.c | 8 +++--- shared-bindings/_bleio/ScanEntry.c | 14 +++++----- shared-bindings/_bleio/ScanResults.c | 6 ++-- shared-bindings/_bleio/Service.c | 8 +++--- shared-bindings/_bleio/UUID.c | 12 ++++---- shared-bindings/_bleio/__init__.c | 8 +++--- 13 files changed, 91 insertions(+), 91 deletions(-) diff --git a/shared-bindings/_bleio/Adapter.c b/shared-bindings/_bleio/Adapter.c index 13acb9d3cf..5aab9eca5b 100644 --- a/shared-bindings/_bleio/Adapter.c +++ b/shared-bindings/_bleio/Adapter.c @@ -65,13 +65,13 @@ //| connections and also initiate connections.""" //| -//| def __init__(self, ): +//| def __init__(self): //| """You cannot create an instance of `_bleio.Adapter`. //| Use `_bleio.adapter` to access the sole instance available.""" //| ... //| -//| enabled: Any = ... +//| enabled: bool = ... //| """State of the BLE adapter.""" //| STATIC mp_obj_t bleio_adapter_get_enabled(mp_obj_t self) { @@ -95,7 +95,7 @@ const mp_obj_property_t bleio_adapter_enabled_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| address: Any = ... +//| address: str = ... //| """MAC address of the BLE adapter. (read-only)""" //| STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t self) { @@ -111,7 +111,7 @@ const mp_obj_property_t bleio_adapter_address_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| name: Any = ... +//| name: str = ... //| """name of the BLE adapter used once connected. //| The name is "CIRCUITPY" + the last four hex digits of ``adapter.address``, //| to make it easy to distinguish multiple CircuitPython boards.""" @@ -135,7 +135,7 @@ const mp_obj_property_t bleio_adapter_name_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| def start_advertising(self, data: buf, *, scan_response: buf = None, connectable: bool = True, anonymous: bool = False, timeout: int = 0, interval: float = 0.1) -> Any: +//| def start_advertising(self, data: buf, *, scan_response: buf = None, connectable: bool = True, anonymous: bool = False, timeout: int = 0, interval: float = 0.1) -> None: //| """Starts advertising until `stop_advertising` is called or if connectable, another device //| connects to us. //| @@ -202,7 +202,7 @@ STATIC mp_obj_t bleio_adapter_start_advertising(mp_uint_t n_args, const mp_obj_t } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_advertising_obj, 2, bleio_adapter_start_advertising); -//| def stop_advertising(self, ) -> Any: +//| def stop_advertising(self) -> None: //| """Stop sending advertising packets.""" //| ... //| @@ -215,7 +215,7 @@ STATIC mp_obj_t bleio_adapter_stop_advertising(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_advertising_obj, bleio_adapter_stop_advertising); -//| def start_scan(self, prefixes: sequence = b"", *, buffer_size: int = 512, extended: bool = False, timeout: float = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> Any: +//| def start_scan(self, prefixes: sequence = b"", *, buffer_size: int = 512, extended: bool = False, timeout: float = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> iterable: //| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are //| filtered and returned separately. //| @@ -288,7 +288,7 @@ STATIC mp_obj_t bleio_adapter_start_scan(size_t n_args, const mp_obj_t *pos_args } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_start_scan_obj, 1, bleio_adapter_start_scan); -//| def stop_scan(self, ) -> Any: +//| def stop_scan(self) -> None: //| """Stop the current scan.""" //| ... //| @@ -301,7 +301,7 @@ STATIC mp_obj_t bleio_adapter_stop_scan(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_stop_scan_obj, bleio_adapter_stop_scan); -//| advertising: Any = ... +//| advertising: bool = ... //| """True when the adapter is currently advertising. (read-only)""" //| STATIC mp_obj_t bleio_adapter_get_advertising(mp_obj_t self) { @@ -317,7 +317,7 @@ const mp_obj_property_t bleio_adapter_advertising_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| connected: Any = ... +//| connected: bool = ... //| """True when the adapter is connected to another device regardless of who initiated the //| connection. (read-only)""" //| @@ -334,7 +334,7 @@ const mp_obj_property_t bleio_adapter_connected_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| connections: Any = ... +//| connections: tuple = ... //| """Tuple of active connections including those initiated through //| :py:meth:`_bleio.Adapter.connect`. (read-only)""" //| @@ -350,7 +350,7 @@ const mp_obj_property_t bleio_adapter_connections_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| def connect(self, address: Address, *, timeout: float/int) -> Any: +//| def connect(self, address: Address, *, timeout: float/int) -> Adapter.connect: //| """Attempts a connection to the device with the given address. //| //| :param Address address: The address of the peripheral to connect to @@ -380,7 +380,7 @@ STATIC mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_adapter_connect_obj, 2, bleio_adapter_connect); -//| def erase_bonding(self, ) -> Any: +//| def erase_bonding(self) -> None: //| """Erase all bonding information stored in flash memory.""" //| ... //| diff --git a/shared-bindings/_bleio/Address.c b/shared-bindings/_bleio/Address.c index 9beaff2ab2..87bae19cee 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: buf, address_type: Any): +//| def __init__(self, address: Union[bytes, bytearray, memoryview], address_type: int): //| """Create a new Address object encapsulating the address value. //| The value itself can be one of: //| @@ -77,8 +77,8 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -//| address_bytes: Any = ... -//| r"""The bytes that make up the device address (read-only). +//| address_bytes: bytes = ... +//| """The bytes that make up the device address (read-only). //| //| Note that the ``bytes`` object returned is in little-endian order: //| The least significant byte is ``address_bytes[0]``. So the address will @@ -108,7 +108,7 @@ const mp_obj_property_t bleio_address_address_bytes_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| type: Any = ... +//| type: int = ... //| """The address type (read-only). //| //| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, `RANDOM_PRIVATE_RESOLVABLE`, @@ -128,7 +128,7 @@ const mp_obj_property_t bleio_address_type_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| def __eq__(self, other: Any) -> Any: +//| def __eq__(self, other: bytes) -> Optional[bool]: //| """Two Address objects are equal if their addresses and address types are equal.""" //| ... //| @@ -154,7 +154,7 @@ STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_o } } -//| def __hash__(self, ) -> Any: +//| def __hash__(self) -> Optional[int]: //| """Returns a hash for the Address data.""" //| ... //| @@ -187,17 +187,17 @@ STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_pr buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); } -//| PUBLIC: Any = ... +//| PUBLIC: bytes = ... //| """A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits).""" //| -//| RANDOM_STATIC: Any = ... +//| RANDOM_STATIC: int = ... //| """A randomly generated address that does not change often. It may never change or may change after //| a power cycle.""" //| -//| RANDOM_PRIVATE_RESOLVABLE: Any = ... +//| RANDOM_PRIVATE_RESOLVABLE: int = ... //| """An address that is usable when the peer knows the other device's secret Identity Resolving Key (IRK).""" //| -//| RANDOM_PRIVATE_NON_RESOLVABLE: Any = ... +//| RANDOM_PRIVATE_NON_RESOLVABLE: int = ... //| """A randomly generated address that changes on every connection.""" //| STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = { diff --git a/shared-bindings/_bleio/Attribute.c b/shared-bindings/_bleio/Attribute.c index 6c47c87ba8..79f45da94d 100644 --- a/shared-bindings/_bleio/Attribute.c +++ b/shared-bindings/_bleio/Attribute.c @@ -36,32 +36,32 @@ //| :py:class:`~Characteristic` and :py:class:`~Descriptor`, //| but is not defined as a Python superclass of those classes.""" //| -//| def __init__(self, ): +//| def __init__(self): //| """You cannot create an instance of :py:class:`~_bleio.Attribute`.""" //| ... //| STATIC const mp_rom_map_elem_t bleio_attribute_locals_dict_table[] = { -//| NO_ACCESS: Any = ... +//| NO_ACCESS: int = ... //| """security mode: access not allowed""" //| -//| OPEN: Any = ... +//| OPEN: int = ... //| """security_mode: no security (link is not encrypted)""" //| -//| ENCRYPT_NO_MITM: Any = ... +//| ENCRYPT_NO_MITM: int = ... //| """security_mode: unauthenticated encryption, without man-in-the-middle protection""" //| -//| ENCRYPT_WITH_MITM: Any = ... +//| ENCRYPT_WITH_MITM: int = ... //| """security_mode: authenticated encryption, with man-in-the-middle protection""" //| -//| LESC_ENCRYPT_WITH_MITM: Any = ... +//| LESC_ENCRYPT_WITH_MITM: int = ... //| """security_mode: LESC encryption, with man-in-the-middle protection""" //| -//| SIGNED_NO_MITM: Any = ... +//| SIGNED_NO_MITM: int = ... //| """security_mode: unauthenticated data signing, without man-in-the-middle protection""" //| -//| SIGNED_WITH_MITM: Any = ... +//| SIGNED_WITH_MITM: int = ... //| """security_mode: authenticated data signing, without man-in-the-middle protection""" //| { MP_ROM_QSTR(MP_QSTR_NO_ACCESS), MP_ROM_INT(SECURITY_MODE_NO_ACCESS) }, diff --git a/shared-bindings/_bleio/Characteristic.c b/shared-bindings/_bleio/Characteristic.c index 785b677d67..e4c81d8c27 100644 --- a/shared-bindings/_bleio/Characteristic.c +++ b/shared-bindings/_bleio/Characteristic.c @@ -37,7 +37,7 @@ //| """Stores information about a BLE service characteristic and allows reading //| and writing of the characteristic's value.""" //| -//| def __init__(self, ): +//| def __init__(self): //| """There is no regular constructor for a Characteristic. A new local Characteristic can be created //| and attached to a Service by calling `add_to_service()`. //| Remote Characteristic objects are created by `Connection.discover_remote_services()` @@ -45,7 +45,7 @@ //| ... //| -//| def add_to_service(self, service: Service, uuid: UUID, *, properties: int = 0, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length: int = 20, fixed_length: bool = False, initial_value: buf = None) -> Any: +//| def add_to_service(self, service: Service, uuid: UUID, *, properties: int = 0, read_perm: int = Attribute.OPEN, write_perm: int = Attribute.OPEN, max_length: int = 20, fixed_length: bool = False, initial_value: buf = None) -> Characteristic: //| """Create a new Characteristic object, and add it to this Service. //| //| :param Service service: The service that will provide this characteristic @@ -141,7 +141,7 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_characteristic_add_to_service_obj, -//| properties: Any = ... +//| properties: int = ... //| """An int bitmask representing which properties are set, specified as bitwise or'ing of //| of these possible values. //| `BROADCAST`, `INDICATE`, `NOTIFY`, `READ`, `WRITE`, `WRITE_NO_RESPONSE`.""" @@ -160,7 +160,7 @@ const mp_obj_property_t bleio_characteristic_properties_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| uuid: Any = ... +//| uuid: Optional[UUID] = ... //| """The UUID of this characteristic. (read-only) //| //| Will be ``None`` if the 128-bit UUID for this characteristic is not known.""" @@ -180,7 +180,7 @@ const mp_obj_property_t bleio_characteristic_uuid_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| value: Any = ... +//| value: bytearray = ... //| """The value of this characteristic.""" //| STATIC mp_obj_t bleio_characteristic_get_value(mp_obj_t self_in) { @@ -211,7 +211,7 @@ const mp_obj_property_t bleio_characteristic_value_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| descriptors: Any = ... +//| descriptors: Descriptor = ... //| """A tuple of :py:class:`Descriptor` that describe this characteristic. (read-only)""" //| STATIC mp_obj_t bleio_characteristic_get_descriptors(mp_obj_t self_in) { @@ -241,7 +241,7 @@ const mp_obj_property_t bleio_characteristic_descriptors_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| service: Any = ... +//| service: Service = ... //| """The Service this Characteristic is a part of.""" //| STATIC mp_obj_t bleio_characteristic_get_service(mp_obj_t self_in) { @@ -258,7 +258,7 @@ const mp_obj_property_t bleio_characteristic_service_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| def set_cccd(self, *, notify: bool = False, indicate: float = False) -> Any: +//| def set_cccd(self, *, notify: bool = False, indicate: float = False) -> None: //| """Set the remote characteristic's CCCD to enable or disable notification and indication. //| //| :param bool notify: True if Characteristic should receive notifications of remote writes @@ -291,22 +291,22 @@ STATIC const mp_rom_map_elem_t bleio_characteristic_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_cccd), MP_ROM_PTR(&bleio_characteristic_set_cccd_obj) }, // Bitmask constants to represent properties -//| BROADCAST: Any = ... +//| BROADCAST: int = ... //| """property: allowed in advertising packets""" //| -//| INDICATE: Any = ... +//| INDICATE: int = ... //| """property: server will indicate to the client when the value is set and wait for a response""" //| -//| NOTIFY: Any = ... +//| NOTIFY: int = ... //| """property: server will notify the client when the value is set""" //| -//| READ: Any = ... +//| READ: int = ... //| """property: clients may read this characteristic""" //| -//| WRITE: Any = ... +//| WRITE: int = ... //| """property: clients may write this characteristic; a response will be sent back""" //| -//| WRITE_NO_RESPONSE: Any = ... +//| WRITE_NO_RESPONSE: int = ... //| """property: clients may write this characteristic; no response will be sent back""" //| { MP_ROM_QSTR(MP_QSTR_BROADCAST), MP_ROM_INT(CHAR_PROP_BROADCAST) }, diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c index 6cbd587c64..ee5a8ea332 100644 --- a/shared-bindings/_bleio/CharacteristicBuffer.c +++ b/shared-bindings/_bleio/CharacteristicBuffer.c @@ -100,7 +100,7 @@ STATIC void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { // These are standard stream methods. Code is in py/stream.c. // -//| def read(self, nbytes: Any = None) -> Any: +//| def read(self, nbytes: int = None) -> Optional[bytes]: //| """Read characters. If ``nbytes`` is specified then read at most that many //| bytes. Otherwise, read everything that arrives until the connection //| times out. Providing the number of bytes expected is highly recommended @@ -110,14 +110,14 @@ STATIC void check_for_deinit(bleio_characteristic_buffer_obj_t *self) { //| :rtype: bytes or None""" //| ... //| -//| def readinto(self, buf: Any) -> Any: +//| def readinto(self, buf: Union[bytearray, memoryview]) -> Optional[int]: //| """Read bytes into the ``buf``. Read at most ``len(buf)`` bytes. //| //| :return: number of bytes read and stored into ``buf`` //| :rtype: int or None (on a non-blocking error)""" //| ... //| -//| def readline(self, ) -> Any: +//| def readline(self) -> bytes: //| """Read a line, ending in a newline character. //| //| :return: the line read @@ -167,7 +167,7 @@ STATIC mp_uint_t bleio_characteristic_buffer_ioctl(mp_obj_t self_in, mp_uint_t r return ret; } -//| in_waiting: Any = ... +//| in_waiting: int = ... //| """The number of bytes in the input buffer, available to be read""" //| STATIC mp_obj_t bleio_characteristic_buffer_obj_get_in_waiting(mp_obj_t self_in) { @@ -184,7 +184,7 @@ const mp_obj_property_t bleio_characteristic_buffer_in_waiting_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| def reset_input_buffer(self, ) -> Any: +//| def reset_input_buffer(self) -> None: //| """Discard any unread characters in the input buffer.""" //| ... //| @@ -196,7 +196,7 @@ STATIC mp_obj_t bleio_characteristic_buffer_obj_reset_input_buffer(mp_obj_t self } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_buffer_reset_input_buffer_obj, bleio_characteristic_buffer_obj_reset_input_buffer); -//| def deinit(self, ) -> Any: +//| def deinit(self) -> None: //| """Disable permanently.""" //| ... //| diff --git a/shared-bindings/_bleio/Connection.c b/shared-bindings/_bleio/Connection.c index 0a96d8a111..64e2baefa3 100644 --- a/shared-bindings/_bleio/Connection.c +++ b/shared-bindings/_bleio/Connection.c @@ -68,13 +68,13 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) { } } -//| def __init__(self, ): +//| def __init__(self): //| """Connections cannot be made directly. Instead, to initiate a connection use `Adapter.connect`. //| Connections may also be made when another device initiates a connection. To use a Connection //| created by a peer, read the `Adapter.connections` property. //| ... //| -//| def disconnect(self, ) -> Any: +//| def disconnect(self) -> Any: //| ""Disconnects from the remote peripheral. Does nothing if already disconnected.""" //| ... //| @@ -87,7 +87,7 @@ STATIC mp_obj_t bleio_connection_disconnect(mp_obj_t self_in) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_disconnect_obj, bleio_connection_disconnect); -//| def pair(self, *, bond: Any = True) -> Any: +//| def pair(self, *, bond: bool = True) -> None: //| """Pair to the peer to improve security.""" //| ... //| @@ -109,7 +109,7 @@ STATIC mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_pair_obj, 1, bleio_connection_pair); -//| def discover_remote_services(self, service_uuids_whitelist: iterable = None) -> Any: +//| def discover_remote_services(self, service_uuids_whitelist: iterable = None) -> Tuple(_bleio.Service, ...): //| """Do BLE discovery for all services or for the given service UUIDS, //| to find their handles and characteristics, and return the discovered services. //| `Connection.connected` must be True. @@ -152,7 +152,7 @@ STATIC mp_obj_t bleio_connection_discover_remote_services(mp_uint_t n_args, cons } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_connection_discover_remote_services_obj, 1, bleio_connection_discover_remote_services); -//| connected: Any = ... +//| connected: bool = ... //| """True if connected to the remote peer.""" //| STATIC mp_obj_t bleio_connection_get_connected(mp_obj_t self_in) { @@ -170,7 +170,7 @@ const mp_obj_property_t bleio_connection_connected_obj = { }; -//| paired: Any = ... +//| paired: bool = ... //| """True if paired to the remote peer.""" //| STATIC mp_obj_t bleio_connection_get_paired(mp_obj_t self_in) { @@ -188,7 +188,7 @@ const mp_obj_property_t bleio_connection_paired_obj = { }; -//| connection_interval: Any = ... +//| connection_interval: float = ... //| """Time between transmissions in milliseconds. Will be multiple of 1.25ms. Lower numbers //| increase speed and decrease latency but increase power consumption. //| @@ -206,7 +206,7 @@ STATIC mp_obj_t bleio_connection_get_connection_interval(mp_obj_t self_in) { } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_get_connection_interval_obj, bleio_connection_get_connection_interval); -//| attribute: Any = ... +//| attribute: int = ... //| """The maximum number of data bytes that can be sent in a single transmission, //| not including overhead bytes. //| diff --git a/shared-bindings/_bleio/Descriptor.c b/shared-bindings/_bleio/Descriptor.c index 9d70208494..b478e85e12 100644 --- a/shared-bindings/_bleio/Descriptor.c +++ b/shared-bindings/_bleio/Descriptor.c @@ -39,7 +39,7 @@ //| Descriptors are attached to BLE characteristics and provide contextual //| information about the characteristic.""" //| -//| def __init__(self, ): +//| def __init__(self): //| """There is no regular constructor for a Descriptor. A new local Descriptor can be created //| and attached to a Characteristic by calling `add_to_characteristic()`. //| Remote Descriptor objects are created by `Connection.discover_remote_services()` @@ -132,7 +132,7 @@ STATIC mp_obj_t bleio_descriptor_add_to_characteristic(size_t n_args, const mp_o STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_descriptor_add_to_characteristic_fun_obj, 3, bleio_descriptor_add_to_characteristic); STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_descriptor_add_to_characteristic_obj, MP_ROM_PTR(&bleio_descriptor_add_to_characteristic_fun_obj)); -//| uuid: Any = ... +//| uuid: UUID = ... //| """The descriptor uuid. (read-only)""" //| STATIC mp_obj_t bleio_descriptor_get_uuid(mp_obj_t self_in) { @@ -150,7 +150,7 @@ const mp_obj_property_t bleio_descriptor_uuid_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| characteristic: Any = ... +//| characteristic: Characteristic = ... //| """The Characteristic this Descriptor is a part of.""" //| STATIC mp_obj_t bleio_descriptor_get_characteristic(mp_obj_t self_in) { @@ -167,7 +167,7 @@ const mp_obj_property_t bleio_descriptor_characteristic_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| value: Any = ... +//| value: Union[bytearray, memoryview] = ... //| """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 907bfabd27..a5b017312c 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: Any) -> Any: +//| def readinto(self, buf: Union[bytearray, memoryview]) -> 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. //| @@ -117,7 +117,7 @@ STATIC mp_obj_t bleio_packet_buffer_readinto(mp_obj_t self_in, mp_obj_t buffer_o } STATIC MP_DEFINE_CONST_FUN_OBJ_2(bleio_packet_buffer_readinto_obj, bleio_packet_buffer_readinto); -//| def write(self, data: Any, *, header: Any = None) -> Any: +//| def write(self, data: bytes, *, header: bytes = None) -> int: //| """Writes all bytes from data into the same outgoing packet. The bytes from header are included //| before data when the pending packet is currently empty. //| @@ -169,7 +169,7 @@ STATIC mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_ } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_packet_buffer_write_obj, 1, bleio_packet_buffer_write); -//| def deinit(self) -> Any: +//| def deinit(self) -> None: //| """Disable permanently.""" //| ... STATIC mp_obj_t bleio_packet_buffer_deinit(mp_obj_t self_in) { @@ -184,7 +184,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_packet_buffer_deinit_obj, bleio_packet_bu //| The name `packet_size` is deprecated and //| will be removed in CircuitPython 6.0.0.""" //| -//| incoming_packet_length: Any = ... +//| incoming_packet_length: int = ... //| """Maximum length in bytes of a packet we are reading.""" //| STATIC mp_obj_t bleio_packet_buffer_get_incoming_packet_length(mp_obj_t self_in) { diff --git a/shared-bindings/_bleio/ScanEntry.c b/shared-bindings/_bleio/ScanEntry.c index 905bea81d2..f8d769cabe 100644 --- a/shared-bindings/_bleio/ScanEntry.c +++ b/shared-bindings/_bleio/ScanEntry.c @@ -41,11 +41,11 @@ //| it has no user-visible constructor.""" //| -//| def __init__(self, ): +//| def __init__(self): //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... //| -//| def matches(self, prefixes: Any, *, all: Any = True) -> Any: +//| def matches(self, prefixes: ScanEntry, *, all: bool = True) -> bool: //| """Returns True if the ScanEntry matches all prefixes when ``all`` is True. This is stricter //| than the scan filtering which accepts any advertisements that match any of the prefixes //| where all is False.""" @@ -70,7 +70,7 @@ STATIC mp_obj_t bleio_scanentry_matches(mp_uint_t n_args, const mp_obj_t *pos_ar } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanentry_matches_obj, 2, bleio_scanentry_matches); -//| address: Any = ... +//| address: _bleio.Address = ... //| """The address of the device (read-only), of type `_bleio.Address`.""" //| STATIC mp_obj_t bleio_scanentry_get_address(mp_obj_t self_in) { @@ -86,7 +86,7 @@ const mp_obj_property_t bleio_scanentry_address_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| advertisement_bytes: Any = ... +//| advertisement_bytes: bytes = ... //| """All the advertisement data present in the packet, returned as a ``bytes`` object. (read-only)""" //| STATIC mp_obj_t scanentry_get_advertisement_bytes(mp_obj_t self_in) { @@ -102,7 +102,7 @@ const mp_obj_property_t bleio_scanentry_advertisement_bytes_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| rssi: Any = ... +//| rssi: int = ... //| """The signal strength of the device at the time of the scan, in integer dBm. (read-only)""" //| STATIC mp_obj_t scanentry_get_rssi(mp_obj_t self_in) { @@ -118,7 +118,7 @@ const mp_obj_property_t bleio_scanentry_rssi_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| connectable: Any = ... +//| connectable: bool = ... //| """True if the device can be connected to. (read-only)""" //| STATIC mp_obj_t scanentry_get_connectable(mp_obj_t self_in) { @@ -134,7 +134,7 @@ const mp_obj_property_t bleio_scanentry_connectable_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| scan_response: Any = ... +//| scan_response: bool = ... //| """True if the entry was a scan response. (read-only)""" //| STATIC mp_obj_t scanentry_get_scan_response(mp_obj_t self_in) { diff --git a/shared-bindings/_bleio/ScanResults.c b/shared-bindings/_bleio/ScanResults.c index 6077dcbdae..bc9d55c80f 100644 --- a/shared-bindings/_bleio/ScanResults.c +++ b/shared-bindings/_bleio/ScanResults.c @@ -46,15 +46,15 @@ STATIC mp_obj_t scanresults_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -//| def __init__(self, ): +//| def __init__(self): //| """Cannot be instantiated directly. Use `_bleio.Adapter.start_scan`.""" //| ... //| -//| def __iter__(self, ) -> Any: +//| def __iter__(self) -> __iter__: //| """Returns itself since it is the iterator.""" //| ... //| -//| def __next__(self, ) -> Any: +//| def __next__(self) -> _bleio.ScanEntry: //| """Returns the next `_bleio.ScanEntry`. Blocks if none have been received and scanning is still //| active. Raises `StopIteration` if scanning is finished and no other results are available.""" //| ... diff --git a/shared-bindings/_bleio/Service.c b/shared-bindings/_bleio/Service.c index 5ca7504f27..5cda11de4e 100644 --- a/shared-bindings/_bleio/Service.c +++ b/shared-bindings/_bleio/Service.c @@ -73,7 +73,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(service); } -//| characteristics: Any = ... +//| characteristics: Tuple(Characteristic, ...) = ... //| """A tuple of :py:class:`Characteristic` designating the characteristics that are offered by //| this service. (read-only)""" //| @@ -92,7 +92,7 @@ const mp_obj_property_t bleio_service_characteristics_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| remote: Any = ... +//| remote: bool = ... //| """True if this is a service provided by a remote device. (read-only)""" //| STATIC mp_obj_t bleio_service_get_remote(mp_obj_t self_in) { @@ -109,7 +109,7 @@ const mp_obj_property_t bleio_service_remote_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| secondary: Any = ... +//| secondary: bool = ... //| """True if this is a secondary service. (read-only)""" //| STATIC mp_obj_t bleio_service_get_secondary(mp_obj_t self_in) { @@ -126,7 +126,7 @@ const mp_obj_property_t bleio_service_secondary_obj = { (mp_obj_t)&mp_const_none_obj }, }; -//| uuid: Any = ... +//| uuid: Optional[UUID] = ... //| """The UUID of this service. (read-only) //| //| Will be ``None`` if the 128-bit UUID for this service is not known.""" diff --git a/shared-bindings/_bleio/UUID.c b/shared-bindings/_bleio/UUID.c index 78161b9566..a36cade6a0 100644 --- a/shared-bindings/_bleio/UUID.c +++ b/shared-bindings/_bleio/UUID.c @@ -36,7 +36,7 @@ //| class UUID: //| """A 16-bit or 128-bit UUID. Can be used for services, characteristics, descriptors and more.""" //| -//| def __init__(self, value: Any): +//| def __init__(self, value: Union[int, typing.ByteString]): //| """Create a new UUID or UUID object encapsulating the uuid value. //| The value can be one of: //| @@ -120,7 +120,7 @@ STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, co return MP_OBJ_FROM_PTR(self); } -//| uuid16: Any = ... +//| uuid16: int = ... //| """The 16-bit part of the UUID. (read-only) //| //| :type: int""" @@ -139,7 +139,7 @@ const mp_obj_property_t bleio_uuid_uuid16_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| uuid128: Any = ... +//| uuid128: bytes = ... //| """The 128-bit value of the UUID //| Raises AttributeError if this is a 16-bit UUID. (read-only) //| @@ -165,7 +165,7 @@ const mp_obj_property_t bleio_uuid_uuid128_obj = { (mp_obj_t)&mp_const_none_obj}, }; -//| size: Any = ... +//| size: int = ... //| """128 if this UUID represents a 128-bit vendor-specific UUID. 16 if this UUID represents a //| 16-bit Bluetooth SIG assigned UUID. (read-only) 32-bit UUIDs are not currently supported. //| @@ -186,7 +186,7 @@ const mp_obj_property_t bleio_uuid_size_obj = { }; -//| def pack_into(self, buffer: Any, offset: Any = 0) -> Any: +//| def pack_into(self, buffer: Union[bytearray, memoryview], offset: int = 0) -> None: //| """Packs the UUID into the given buffer at the given offset.""" //| ... //| @@ -248,7 +248,7 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -//| def __eq__(self, other: Any) -> Any: +//| def __eq__(self, other: UUID) -> Optional[bool]: //| """Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit.""" //| ... //| diff --git a/shared-bindings/_bleio/__init__.c b/shared-bindings/_bleio/__init__.c index 90b185f79a..8778e94eda 100644 --- a/shared-bindings/_bleio/__init__.c +++ b/shared-bindings/_bleio/__init__.c @@ -60,7 +60,7 @@ //| class BluetoothError: -//| def __init__(self, Exception: Any): +//| def __init__(self, Exception: Exception): //| """Catch all exception for Bluetooth related errors.""" //| ... MP_DEFINE_BLEIO_EXCEPTION(BluetoothError, Exception) @@ -73,7 +73,7 @@ NORETURN void mp_raise_bleio_BluetoothError(const compressed_string_t* fmt, ...) nlr_raise(exception); } //| class ConnectionError: -//| def __init__(self, BluetoothError: Any): +//| def __init__(self, BluetoothError: _bleio.BluetoothError): //| """Raised when a connection is unavailable.""" //| ... //| @@ -87,7 +87,7 @@ NORETURN void mp_raise_bleio_ConnectionError(const compressed_string_t* fmt, ... } //| class RoleError: -//| def __init__(self, BluetoothError: Any): +//| def __init__(self, BluetoothError: _bleio.BluetoothError): //| """Raised when a resource is used as the mismatched role. For example, if a local CCCD is //| attempted to be set but they can only be set when remote.""" //| ... @@ -97,7 +97,7 @@ NORETURN void mp_raise_bleio_RoleError(const compressed_string_t* msg) { mp_raise_msg(&mp_type_bleio_RoleError, msg); } //| class SecurityError: -//| def __init__(self, BluetoothError: Any): +//| def __init__(self, BluetoothError: _bleio.BluetoothError): //| """Raised when a security related error occurs.""" //| ... //|