Skip to content

Commit

Permalink
Add and correct some type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Jul 24, 2020
1 parent 5437084 commit 54a342a
Show file tree
Hide file tree
Showing 52 changed files with 266 additions and 230 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
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
3 changes: 1 addition & 2 deletions ports/atmel-samd/bindings/samd/Clock.c
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 Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions shared-bindings/_bleio/Adapter.c
Expand Up @@ -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: 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 @@ -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
2 changes: 1 addition & 1 deletion shared-bindings/_bleio/Address.c
Expand Up @@ -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
2 changes: 1 addition & 1 deletion shared-bindings/_bleio/Characteristic.c
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
8 changes: 4 additions & 4 deletions shared-bindings/_bleio/Connection.c
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: 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
2 changes: 1 addition & 1 deletion shared-bindings/_bleio/UUID.c
Expand Up @@ -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) -> bool:
//| def __eq__(self, other: UUID) -> bool:
//| """Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit."""
//| ...
//|
Expand Down
27 changes: 25 additions & 2 deletions shared-bindings/_pew/PewPew.c
Expand Up @@ -45,8 +45,31 @@
//| used internally by it. All user-visible interactions are done through
//| that library."""
//|

//| def __init__(self, buffer: ReadableBuffer, rows: List[DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut], cols: List[DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut, DigitalInOut], buttons: DigitalInOut) -> None:
//| def __init__(
//| self,
//| buffer: ReadableBuffer,
//| rows: List[
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| ],
//| cols: List[
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| digitalio.DigitalInOut,
//| ],
//| buttons: digitalio.DigitalInOut,
//| ) -> None:
//| """Initializes matrix scanning routines.
//|
//| The ``buffer`` is a 64 byte long ``bytearray`` that stores what should
Expand Down
14 changes: 10 additions & 4 deletions shared-bindings/_pixelbuf/PixelBuf.c
Expand Up @@ -221,7 +221,7 @@ const mp_obj_property_t pixelbuf_pixelbuf_auto_write_obj = {
(mp_obj_t)&mp_const_none_obj},
};

//| byteorder: string = ...
//| byteorder: str = ...
//| """byteorder string for the buffer (read-only)"""
//|
STATIC mp_obj_t pixelbuf_pixelbuf_obj_get_byteorder(mp_obj_t self_in) {
Expand Down Expand Up @@ -257,7 +257,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_show(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pixelbuf_pixelbuf_show_obj, pixelbuf_pixelbuf_show);

//| def fill(color: Union[int, Tuple[int, int, int]]) -> None:
//| def fill(self, color: Union[int, Tuple[int, int, int]]) -> None:
//| """Fills the given pixelbuf with the given color."""
//| ...
//|
Expand All @@ -269,13 +269,19 @@ STATIC mp_obj_t pixelbuf_pixelbuf_fill(mp_obj_t self_in, mp_obj_t value) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pixelbuf_pixelbuf_fill_obj, pixelbuf_pixelbuf_fill);

//| def __getitem__(self, index: int) -> Tuple[int, int, int, Union[int, float]]:
//| @overload
//| def __getitem__(self, index: slice) -> Tuple[Tuple, ...]: ...
//| def __getitem__(self, index: int) -> Tuple:
//| """Returns the pixel value at the given index as a tuple of (Red, Green, Blue[, White]) values
//| between 0 and 255. When in PWM (DotStar) mode, the 4th tuple value is a float of the pixel
//| intensity from 0-1.0."""
//| ...
//|
//| def __setitem__(self, index: int, value: Union[int, Tuple[int, int, int, Union[int, float]]]) -> PixelBuf:
//| @overload
//| def __setitem__(self, index: slice, value: Tuple[Union[int, Tuple, List], ...]) -> None: ...
//| @overload
//| def __setitem__(self, index: slice, value: List[Union[int, Tuple, List]]) -> None: ...
//| def __setitem__(self, index: int, value: Union[int, Tuple, List]) -> None:
//| """Sets the pixel value at the given index. Value can either be a tuple or integer. Tuples are
//| The individual (Red, Green, Blue[, White]) values between 0 and 255. If given an integer, the
//| red, green and blue values are packed into the lower three bytes (0xRRGGBB).
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/_pixelbuf/__init__.c
Expand Up @@ -41,12 +41,12 @@
//| Byteorders are configured with strings, such as "RGB" or "RGBD"."""
// TODO: Pull in docs from pypixelbuf.

//| def colorwheel(n: int) -> int:
//| def colorwheel(n: float) -> int:
//| """C implementation of the common wheel() function found in many examples.
//| Returns the colorwheel RGB value as an integer value for n (usable in :py:class:`PixelBuf`, neopixel, and dotstar)."""
//| ...
//|
//| def wheel(n: Any) -> Any:
//| def wheel(n: float) -> int:
//| """Use of wheel() is deprecated. Please use colorwheel()."""
//|

Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/_stage/__init__.c
Expand Up @@ -39,7 +39,7 @@
//| The `_stage` module contains native code to speed-up the ```stage`` Library
//| <https://github.com/python-ugame/circuitpython-stage>`_."""
//|
//| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> Any:
//| def render(x0: int, y0: int, x1: int, y1: int, layers: list, buffer: bytearray, display: displayio.Display, scale: int, background: int) -> None:
//| """Render and send to the display a fragment of the screen.
//|
//| :param int x0: Left edge of the fragment.
Expand Down
7 changes: 3 additions & 4 deletions shared-bindings/aesio/aes.c
Expand Up @@ -12,7 +12,7 @@
//| class AES:
//| """Encrypt and decrypt AES streams"""
//|
//| def __init__(self, key: Optional[ReadableBuffer], mode: int=0, iv: ReadableBuffer=None, segment_size: int=8) -> None:
//| def __init__(self, key: Optional[ReadableBuffer], mode: int = 0, iv: ReadableBuffer = None, segment_size: int = 8) -> None:
//| """Create a new AES state with the given key.
//|
//| :param bytearray key: A 16-, 24-, or 32-byte key
Expand Down Expand Up @@ -152,7 +152,7 @@ STATIC void validate_length(aesio_aes_obj_t *self, size_t src_length,
}
}

//| def encrypt_into(src: ReadableBuffer, dest: WriteableBuffer) -> None:
//| def encrypt_into(self, src: ReadableBuffer, dest: WriteableBuffer) -> None:
//| """Encrypt the buffer from ``src`` into ``dest``.
//|
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
Expand Down Expand Up @@ -183,8 +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: ReadableBuffer, dest: WriteableBuffer) -> None:
//|
//| def decrypt_into(self, src: ReadableBuffer, dest: WriteableBuffer) -> None:
//| """Decrypt the buffer from ``src`` into ``dest``.
//| For ECB mode, the buffers must be 16 bytes long. For CBC mode, the
//| buffers must be a multiple of 16 bytes, and must be equal length. For
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiomixer/Mixer.c
Expand Up @@ -211,7 +211,7 @@ const mp_obj_property_t audiomixer_mixer_voice_obj = {
(mp_obj_t)&mp_const_none_obj},
};

//| def play(self, sample: Union[audiomixer.WaveFile, audiocore.RawSample, audiomixer.Mixer], *, voice: int = 0, loop: bool = False) -> None:
//| def play(self, sample: Union[audiocore.WaveFile, audiocore.RawSample, Mixer], *, voice: int = 0, loop: bool = False) -> None:
//| """Plays the sample once when loop=False and continuously when loop=True.
//| Does not block. Use `playing` to block.
//|
Expand Down

0 comments on commit 54a342a

Please sign in to comment.