Skip to content

More type hints #3193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
run: |
sudo apt-get install -y eatmydata
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort black
- name: Versions
run: |
gcc --version
Expand Down
9 changes: 4 additions & 5 deletions ports/atmel-samd/bindings/samd/Clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "py/objproperty.h"
#include "py/runtime.h"

//| import typing
//| class Clock:
//| """Identifies a clock on the microcontroller.
//|
Expand All @@ -44,7 +43,7 @@ STATIC void samd_clock_print(const mp_print_t *print, mp_obj_t self_in, mp_print
mp_printf(print, "%q.%q.%q", MP_QSTR_samd, MP_QSTR_clock, self->name);
}

//| enabled: bool = ...
//| enabled: bool
//| """Is the clock enabled? (read-only)"""
//|
STATIC mp_obj_t samd_clock_get_enabled(mp_obj_t self_in) {
Expand All @@ -62,7 +61,7 @@ const mp_obj_property_t samd_clock_enabled_obj = {
},
};

//| parent: typing.Union(Clock | None) = ...
//| parent: Union[Clock, None]
//| """Clock parent. (read-only)"""
//|
STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) {
Expand Down Expand Up @@ -90,7 +89,7 @@ const mp_obj_property_t samd_clock_parent_obj = {
},
};

//| frequency: int = ...
//| frequency: int
//| """Clock frequency in Herz. (read-only)"""
//|
STATIC mp_obj_t samd_clock_get_frequency(mp_obj_t self_in) {
Expand All @@ -108,7 +107,7 @@ const mp_obj_property_t samd_clock_frequency_obj = {
},
};

//| calibration: int = ...
//| calibration: int
//| """Clock calibration. Not all clocks can be calibrated."""
//|
STATIC mp_obj_t samd_clock_get_calibration(mp_obj_t self_in) {
Expand Down
20 changes: 10 additions & 10 deletions shared-bindings/_bleio/Adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
//| ...
//|

//| enabled: bool = ...
//| enabled: bool
//| """State of the BLE adapter."""
//|
STATIC mp_obj_t bleio_adapter_get_enabled(mp_obj_t self) {
Expand All @@ -95,7 +95,7 @@ const mp_obj_property_t bleio_adapter_enabled_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| address: Address = ...
//| address: Address
//| """MAC address of the BLE adapter. (read-only)"""
//|
STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t self) {
Expand All @@ -111,7 +111,7 @@ const mp_obj_property_t bleio_adapter_address_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| name: str = ...
//| 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."""
Expand All @@ -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) -> None:
//| def start_advertising(self, data: ReadableBuffer, *, scan_response: Optional[ReadableBuffer] = 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.
//|
Expand Down Expand Up @@ -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) -> iterable:
//| def start_scan(self, prefixes: ReadableBuffer = b"", *, buffer_size: int = 512, extended: bool = False, timeout: Optional[float] = None, interval: float = 0.1, window: float = 0.1, minimum_rssi: int = -80, active: bool = True) -> Iterable[ScanEntry]:
//| """Starts a BLE scan and returns an iterator of results. Advertisements and scan responses are
//| filtered and returned separately.
//|
Expand Down Expand Up @@ -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: bool = ...
//| advertising: bool
//| """True when the adapter is currently advertising. (read-only)"""
//|
STATIC mp_obj_t bleio_adapter_get_advertising(mp_obj_t self) {
Expand All @@ -317,7 +317,7 @@ const mp_obj_property_t bleio_adapter_advertising_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| connected: bool = ...
//| connected: bool
//| """True when the adapter is connected to another device regardless of who initiated the
//| connection. (read-only)"""
//|
Expand All @@ -334,7 +334,7 @@ const mp_obj_property_t bleio_adapter_connected_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| connections: tuple = ...
//| connections: tuple
//| """Tuple of active connections including those initiated through
//| :py:meth:`_bleio.Adapter.connect`. (read-only)"""
//|
Expand All @@ -350,11 +350,11 @@ const mp_obj_property_t bleio_adapter_connections_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| def connect(self, address: Address, *, timeout: float/int) -> Connection:
//| def connect(self, address: Address, *, timeout: float) -> Connection:
//| """Attempts a connection to the device with the given address.
//|
//| :param Address address: The address of the peripheral to connect to
//| :param float/int timeout: Try to connect for timeout seconds."""
//| :param float timeout: Try to connect for timeout seconds."""
//| ...
//|
STATIC mp_obj_t bleio_adapter_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
Expand Down
14 changes: 7 additions & 7 deletions shared-bindings/_bleio/Address.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ 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: bytes = ...
//| address_bytes: bytes
//| """The bytes that make up the device address (read-only).
//|
//| Note that the ``bytes`` object returned is in little-endian order:
Expand Down Expand Up @@ -108,7 +108,7 @@ const mp_obj_property_t bleio_address_address_bytes_obj = {
(mp_obj_t)&mp_const_none_obj},
};

//| type: int = ...
//| type: int
//| """The address type (read-only).
//|
//| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, `RANDOM_PRIVATE_RESOLVABLE`,
Expand All @@ -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) -> bool:
//| def __eq__(self, other: Address) -> bool:
//| """Two Address objects are equal if their addresses and address types are equal."""
//| ...
//|
Expand Down Expand Up @@ -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: int = ...
//| PUBLIC: int
//| """A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits)."""
//|
//| RANDOM_STATIC: int = ...
//| 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: int = ...
//| 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: int = ...
//| 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[] = {
Expand Down
14 changes: 7 additions & 7 deletions shared-bindings/_bleio/Attribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@

STATIC const mp_rom_map_elem_t bleio_attribute_locals_dict_table[] = {

//| NO_ACCESS: int = ...
//| NO_ACCESS: int
//| """security mode: access not allowed"""
//|
//| OPEN: int = ...
//| OPEN: int
//| """security_mode: no security (link is not encrypted)"""
//|
//| ENCRYPT_NO_MITM: int = ...
//| ENCRYPT_NO_MITM: int
//| """security_mode: unauthenticated encryption, without man-in-the-middle protection"""
//|
//| ENCRYPT_WITH_MITM: int = ...
//| ENCRYPT_WITH_MITM: int
//| """security_mode: authenticated encryption, with man-in-the-middle protection"""
//|
//| LESC_ENCRYPT_WITH_MITM: int = ...
//| LESC_ENCRYPT_WITH_MITM: int
//| """security_mode: LESC encryption, with man-in-the-middle protection"""
//|
//| SIGNED_NO_MITM: int = ...
//| SIGNED_NO_MITM: int
//| """security_mode: unauthenticated data signing, without man-in-the-middle protection"""
//|
//| SIGNED_WITH_MITM: int = ...
//| 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) },
Expand Down
26 changes: 13 additions & 13 deletions shared-bindings/_bleio/Characteristic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> Characteristic:
//| 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: Optional[ReadableBuffer] = None) -> Characteristic:
//| """Create a new Characteristic object, and add it to this Service.
//|
//| :param Service service: The service that will provide this characteristic
Expand Down Expand Up @@ -141,7 +141,7 @@ STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bleio_characteristic_add_to_service_obj,



//| properties: int = ...
//| 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`."""
Expand All @@ -160,7 +160,7 @@ const mp_obj_property_t bleio_characteristic_properties_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| uuid: Optional[UUID] = ...
//| uuid: Optional[UUID]
//| """The UUID of this characteristic. (read-only)
//|
//| Will be ``None`` if the 128-bit UUID for this characteristic is not known."""
Expand All @@ -180,7 +180,7 @@ const mp_obj_property_t bleio_characteristic_uuid_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| value: bytearray = ...
//| value: bytearray
//| """The value of this characteristic."""
//|
STATIC mp_obj_t bleio_characteristic_get_value(mp_obj_t self_in) {
Expand Down Expand Up @@ -211,7 +211,7 @@ const mp_obj_property_t bleio_characteristic_value_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| descriptors: Descriptor = ...
//| 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) {
Expand Down Expand Up @@ -241,7 +241,7 @@ const mp_obj_property_t bleio_characteristic_descriptors_obj = {
(mp_obj_t)&mp_const_none_obj },
};

//| service: Service = ...
//| service: Service
//| """The Service this Characteristic is a part of."""
//|
STATIC mp_obj_t bleio_characteristic_get_service(mp_obj_t self_in) {
Expand All @@ -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) -> None:
//| def set_cccd(self, *, notify: bool = False, indicate: bool = 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
Expand Down Expand Up @@ -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: int = ...
//| BROADCAST: int
//| """property: allowed in advertising packets"""
//|
//| INDICATE: int = ...
//| INDICATE: int
//| """property: server will indicate to the client when the value is set and wait for a response"""
//|
//| NOTIFY: int = ...
//| NOTIFY: int
//| """property: server will notify the client when the value is set"""
//|
//| READ: int = ...
//| READ: int
//| """property: clients may read this characteristic"""
//|
//| WRITE: int = ...
//| WRITE: int
//| """property: clients may write this characteristic; a response will be sent back"""
//|
//| WRITE_NO_RESPONSE: int = ...
//| 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) },
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/_bleio/CharacteristicBuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: int = None) -> Optional[bytes]:
//| def read(self, nbytes: Optional[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
Expand Down Expand Up @@ -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: int = ...
//| 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) {
Expand Down
16 changes: 8 additions & 8 deletions shared-bindings/_bleio/Connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
//| def __init__(self) -> None:
//| """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.
//| created by a peer, read the `Adapter.connections` property."""
//| ...
//|
//| def disconnect(self) -> Any:
//| ""Disconnects from the remote peripheral. Does nothing if already disconnected."""
//| def disconnect(self) -> None:
//| """Disconnects from the remote peripheral. Does nothing if already disconnected."""
//| ...
//|
STATIC mp_obj_t bleio_connection_disconnect(mp_obj_t self_in) {
Expand Down Expand Up @@ -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) -> Service:
//| def discover_remote_services(self, service_uuids_whitelist: Optional[Iterable[UUID]] = None) -> Tuple[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.
Expand Down Expand Up @@ -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: bool = ...
//| connected: bool
//| """True if connected to the remote peer."""
//|
STATIC mp_obj_t bleio_connection_get_connected(mp_obj_t self_in) {
Expand All @@ -170,7 +170,7 @@ const mp_obj_property_t bleio_connection_connected_obj = {
};


//| paired: bool = ...
//| paired: bool
//| """True if paired to the remote peer."""
//|
STATIC mp_obj_t bleio_connection_get_paired(mp_obj_t self_in) {
Expand All @@ -188,7 +188,7 @@ const mp_obj_property_t bleio_connection_paired_obj = {
};


//| connection_interval: float = ...
//| 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.
//|
Expand All @@ -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: int = ...
//| attribute: int
//| """The maximum number of data bytes that can be sent in a single transmission,
//| not including overhead bytes.
//|
Expand Down
Loading