Add and correct some type hints

This commit is contained in:
Taku Fukada 2020-07-24 03:22:41 +09:00
parent 543708416b
commit 54a342a7f5
52 changed files with 266 additions and 230 deletions

View File

@ -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

View File

@ -30,7 +30,6 @@
#include "py/objproperty.h"
#include "py/runtime.h"
//| import typing
//| class Clock:
//| """Identifies a clock on the microcontroller.
//|
@ -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) {

View File

@ -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.
//|
@ -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.
//|
@ -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) {

View File

@ -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."""
//| ...
//|

View File

@ -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

View File

@ -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) {
@ -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.

View File

@ -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."""
//| ...
//|

View File

@ -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

View File

@ -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) {
@ -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."""
//| ...
//|
@ -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).

View File

@ -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()."""
//|

View File

@ -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.

View File

@ -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
@ -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
@ -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

View File

@ -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.
//|

View File

@ -126,13 +126,12 @@ static void check_lock(busio_i2c_obj_t *self) {
}
//| def scan(self) -> list:
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
//| list of those that respond.
//|
//| """Scan all I2C addresses between 0x08 and 0x77 inclusive and return a
//| list of those that respond.
//|
//| :return: List of device ids on the I2C bus
//| :rtype: list"""
//| ...
//| :return: List of device ids on the I2C bus
//| :rtype: list"""
//| ...
//|
STATIC mp_obj_t busio_i2c_scan(mp_obj_t self_in) {
busio_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -177,19 +176,19 @@ 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: 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.
//| """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.
//|
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like
//| ``buf[start:end]`` will so it saves memory.
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like
//| ``buf[start:end]`` will so it saves memory.
//|
//| :param int address: 7-bit device address
//| :param bytearray buffer: buffer to write into
//| :param int start: Index to start writing at
//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)``"""
//| ...
//| :param int address: 7-bit device address
//| :param bytearray buffer: buffer to write into
//| :param int start: Index to start writing at
//| :param int end: Index to write up to but not include. Defaults to ``len(buffer)``"""
//| ...
//|
// Shared arg parsing for readfrom_into and writeto_then_readfrom.
STATIC void readfrom(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end) {
@ -229,21 +228,21 @@ 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: ReadableBuffer, *, start: int = 0, end: int = None, stop: bool = True) -> None:
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and
//| then transmit a stop bit.
//| """Write the bytes from ``buffer`` to the device selected by ``address`` and
//| then transmit a stop bit.
//|
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like
//| ``buffer[start:end]`` will so it saves memory.
//| If ``start`` or ``end`` is provided, then the buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like
//| ``buffer[start:end]`` will so it saves memory.
//|
//| Writing a buffer or slice of length zero is permitted, as it can be used
//| to poll for the existence of a device.
//| riting a buffer or slice of length zero is permitted, as it can be used
//| to poll for the existence of a device.
//|
//| :param int address: 7-bit device address
//| :param bytearray buffer: buffer containing the bytes to write
//| :param int start: Index to start writing from
//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)``"""
//| ...
//| :param int address: 7-bit device address
//| :param bytearray buffer: buffer containing the bytes to write
//| :param int start: Index to start writing from
//| :param int end: Index to read up to but not include. Defaults to ``len(buffer)``"""
//| ...
//|
// Shared arg parsing for writeto and writeto_then_readfrom.
STATIC void writeto(busio_i2c_obj_t *self, mp_int_t address, mp_obj_t buffer, int32_t start, mp_int_t end, bool stop) {
@ -283,22 +282,22 @@ 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: 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.
//| """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.
//|
//| If ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
//| will so it saves memory.
//| f ``start`` or ``end`` is provided, then the corresponding buffer will be sliced
//| as if ``buffer[start:end]``. This will not cause an allocation like ``buf[start:end]``
//| will so it saves memory.
//|
//| :param int address: 7-bit device address
//| :param bytearray out_buffer: buffer containing the bytes to write
//| :param bytearray in_buffer: buffer to write into
//| :param int out_start: Index to start writing from
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
//| :param int in_start: Index to start writing at
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
//| ...
//| :param int address: 7-bit device address
//| :param bytearray out_buffer: buffer containing the bytes to write
//| :param bytearray in_buffer: buffer to write into
//| :param int out_start: Index to start writing from
//| :param int out_end: Index to read up to but not include. Defaults to ``len(buffer)``
//| :param int in_start: Index to start writing at
//| :param int in_end: Index to write up to but not include. Defaults to ``len(buffer)``"""
//| ...
//|
STATIC mp_obj_t busio_i2c_writeto_then_readfrom(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_address, ARG_out_buffer, ARG_in_buffer, ARG_out_start, ARG_out_end, ARG_in_start, ARG_in_end };

View File

@ -53,7 +53,7 @@ STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_arg
return MP_OBJ_FROM_PTR(self);
}
//| def deinit(self):
//| def deinit(self) -> None:
//| """Deinitializes the Counter and releases any hardware resources for reuse."""
//|
STATIC mp_obj_t countio_counter_deinit(mp_obj_t self_in) {
@ -69,12 +69,12 @@ STATIC void check_for_deinit(countio_counter_obj_t *self) {
}
}
//| def __enter__(self):
//| def __enter__(self) -> Counter:
//| """No-op used by Context Managers."""
//|
// Provided by context manager helper.
//| def __exit__(self):
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//|
@ -113,7 +113,7 @@ const mp_obj_property_t countio_counter_count_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| def reset(self):
//| def reset(self) -> None:
//| """Resets the count back to 0."""
//|
STATIC mp_obj_t countio_counter_reset(mp_obj_t self_in){

View File

@ -107,13 +107,13 @@ STATIC void check_for_deinit(digitalio_digitalinout_obj_t *self) {
}
//| def switch_to_output(self, value: bool = False, drive_mode: digitalio.DriveMode = digitalio.DriveMode.PUSH_PULL) -> None:
//| """Set the drive mode and value and then switch to writing out digital
//| values.
//| """Set the drive mode and value and then switch to writing out digital
//| values.
//|
//| :param bool value: default value to set upon switching
//| :param ~digitalio.DriveMode drive_mode: drive mode for the output
//| """
//| ...
//| :param bool value: default value to set upon switching
//| :param ~digitalio.DriveMode drive_mode: drive mode for the output
//| """
//| ...
//|
STATIC mp_obj_t digitalio_digitalinout_switch_to_output(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_value, ARG_drive_mode };
@ -228,7 +228,7 @@ const mp_obj_property_t digitalio_digitalio_direction_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| value: Bool = ...
//| value: bool = ...
//| """The digital logic level of the pin."""
//|
STATIC mp_obj_t digitalio_digitalinout_obj_get_value(mp_obj_t self_in) {

View File

@ -49,7 +49,7 @@
//| Most people should not use this class directly. Use a specific display driver instead that will
//| contain the initialization sequence at minimum."""
//|
//| def __init__(self, display_bus: displayio, init_sequence: buffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, set_vertical_scroll: int = 0, backlight_pin: Optional[microcontroller.Pin] = None, brightness_command: int = None, brightness: bool = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60) -> None:
//| def __init__(self, display_bus: Union[FourWire, ParallelBus], init_sequence: ReadableBuffer, *, width: int, height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, color_depth: int = 16, grayscale: bool = False, pixels_in_byte_share_row: bool = True, bytes_per_cell: int = 1, reverse_pixels_in_byte: bool = False, set_column_command: int = 0x2a, set_row_command: int = 0x2b, write_ram_command: int = 0x2c, set_vertical_scroll: int = 0, backlight_pin: Optional[microcontroller.Pin] = None, brightness_command: int = None, brightness: bool = 1.0, auto_brightness: bool = False, single_byte_bounds: bool = False, data_as_commands: bool = False, auto_refresh: bool = True, native_frames_per_second: int = 60) -> None:
//| r"""Create a Display object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
//|
//| The ``init_sequence`` is bitpacked to minimize the ram impact. Every command begins with a
@ -341,7 +341,6 @@ const mp_obj_property_t displayio_display_auto_brightness_obj = {
//| width: int = ...
//| Gets the width of the board
//|
//|
STATIC mp_obj_t displayio_display_obj_get_width(mp_obj_t self_in) {
displayio_display_obj_t *self = native_display(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_width(self));
@ -358,7 +357,6 @@ const mp_obj_property_t displayio_display_width_obj = {
//| height: int = ...
//| """Gets the height of the board"""
//|
//|
STATIC mp_obj_t displayio_display_obj_get_height(mp_obj_t self_in) {
displayio_display_obj_t *self = native_display(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_get_height(self));

View File

@ -49,7 +49,7 @@
//| Most people should not use this class directly. Use a specific display driver instead that will
//| contain the startup and shutdown sequences at minimum."""
//|
//| def __init__(self, display_bus: displayio, start_sequence: buffer, stop_sequence: buffer, *, width: int, height: int, ram_width: int, ram_height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, set_column_window_command: Optional[int] = None, set_row_window_command: Optional[int] = None, single_byte_bounds: bool = False, write_black_ram_command: int, black_bits_inverted: bool = False, write_color_ram_command: Optional[int] = None, color_bits_inverted: bool = False, highlight_color: int = 0x000000, refresh_display_command: int, refresh_time: float = 40, busy_pin: Optional[microcontroller.Pin] = None, busy_state: bool = True, seconds_per_frame: float = 180, always_toggle_chip_select: bool = False) -> None:
//| def __init__(self, display_bus: displayio, start_sequence: ReadableBuffer, stop_sequence: ReadableBuffer, *, width: int, height: int, ram_width: int, ram_height: int, colstart: int = 0, rowstart: int = 0, rotation: int = 0, set_column_window_command: Optional[int] = None, set_row_window_command: Optional[int] = None, single_byte_bounds: bool = False, write_black_ram_command: int, black_bits_inverted: bool = False, write_color_ram_command: Optional[int] = None, color_bits_inverted: bool = False, highlight_color: int = 0x000000, refresh_display_command: int, refresh_time: float = 40, busy_pin: Optional[microcontroller.Pin] = None, busy_state: bool = True, seconds_per_frame: float = 180, always_toggle_chip_select: bool = False) -> None:
//| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `displayio.ParallelBus`).
//|
//| The ``start_sequence`` and ``stop_sequence`` are bitpacked to minimize the ram impact. Every

View File

@ -264,7 +264,8 @@ STATIC mp_obj_t displayio_group_obj_remove(mp_obj_t self_in, mp_obj_t layer) {
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_group_remove_obj, displayio_group_obj_remove);
//| def __bool__(self) -> bool: ...
//| def __bool__(self) -> bool:
//| ...
//|
//| def __len__(self) -> int:
//| """Returns the number of layers in a Group"""

View File

@ -69,7 +69,7 @@
//| while True:
//| pass"""
//|
//| def __init__(self, file: file) -> None:
//| def __init__(self, file: typing.BinaryIO) -> None:
//| """Create an OnDiskBitmap object with the given file.
//|
//| :param file file: The open bitmap file"""

View File

@ -36,12 +36,6 @@
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
//| class Palette:
//| """Map a pixel palette_index to a full color. Colors are transformed to the display's format internally to
//| save memory."""
@ -70,7 +64,8 @@ STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_a
return MP_OBJ_FROM_PTR(self);
}
//| def __bool__(self) -> bool: ...
//| def __bool__(self) -> bool:
//| ...
//|
//| def __len__(self) -> int:
//| """Returns the number of colors in a Palette"""
@ -86,7 +81,11 @@ STATIC mp_obj_t group_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
}
}
//| def __setitem__(self, index: int, value: Union[int, ReadableBuffer]) -> Optional[int]:
//| def __getitem__(self, index: int) -> Optional[int]:
//| r"""Return the pixel color at the given index as an integer."""
//| ...
//|
//| def __setitem__(self, index: int, value: Union[int, ReadableBuffer, Tuple[int, int, int]]) -> None:
//| r"""Sets the pixel color at the given index. The index should be an integer in the range 0 to color_count-1.
//|
//| The value argument represents a color, and can be from 0x000000 to 0xFFFFFF (to represent an RGB value).
@ -149,7 +148,8 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val
return mp_const_none;
}
//| def make_transparent(self, palette_index: int) -> None: ...
//| def make_transparent(self, palette_index: int) -> None:
//| ...
//|
STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_t palette_index_obj) {
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);
@ -163,7 +163,8 @@ STATIC mp_obj_t displayio_palette_obj_make_transparent(mp_obj_t self_in, mp_obj_
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_palette_make_transparent_obj, displayio_palette_obj_make_transparent);
//| def make_opaque(self, palette_index: int) -> None: ...
//| def make_opaque(self, palette_index: int) -> None:
//| ...
//|
STATIC mp_obj_t displayio_palette_obj_make_opaque(mp_obj_t self_in, mp_obj_t palette_index_obj) {
displayio_palette_t *self = MP_OBJ_TO_PTR(self_in);

View File

@ -48,7 +48,7 @@
//|
//| A single tile grid is also known as a Sprite."""
//|
//| def __init__(self, bitmap: displayio.Bitmap, *, pixel_shader: displayio.Palette, width: int = 1, height: int = 1, tile_width: int = None, tile_height: int = None, default_tile: int = 0, x: int = 0, y: int = 0) -> None:
//| def __init__(self, bitmap: Bitmap, *, pixel_shader: Palette, width: int = 1, height: int = 1, tile_width: int = None, tile_height: int = None, default_tile: int = 0, x: int = 0, y: int = 0) -> None:
//| """Create a TileGrid object. The bitmap is source for 2d pixels. The pixel_shader is used to
//| convert the value and its location to a display native pixel color. This may be a simple color
//| palette lookup, a gradient, a pattern or a color transformer.

View File

@ -94,7 +94,7 @@ static framebufferio_framebufferdisplay_obj_t* native_display(mp_obj_t display_o
return MP_OBJ_TO_PTR(native_display);
}
//| def show(self, group: Group) -> None:
//| def show(self, group: displayio.Group) -> None:
//| """Switches to displaying the given group of layers. When group is None, the default
//| CircuitPython terminal will be shown.
//|

View File

@ -69,8 +69,17 @@
//| buttons = pad.get_pressed()
//| time.sleep(0.1)"""
//|
//| def __init__(self, b1: DigitalInOut, b2: DigitalInOut, b3: DigitalInOut, b4: DigitalInOut, b5: DigitalInOut, b6: DigitalInOut, b7: DigitalInOut, b8: DigitalInOut) -> None:
//| def __init__(
//| self,
//| b1: digitalio.DigitalInOut,
//| b2: digitalio.DigitalInOut,
//| b3: digitalio.DigitalInOut,
//| b4: digitalio.DigitalInOut,
//| b5: digitalio.DigitalInOut,
//| b6: digitalio.DigitalInOut,
//| b7: digitalio.DigitalInOut,
//| b8: digitalio.DigitalInOut,
//| ) -> None:
//| """Initializes button scanning routines.
//|
//| The ``b1``-``b8`` parameters are ``DigitalInOut`` objects, which

View File

@ -36,7 +36,7 @@
//| class GamePadShift:
//| """Scan buttons for presses through a shift register"""
//|
//| def __init__(self, clock: DigitalInOut, data: DigitalInOut, latch: DigitalInOut) -> None:
//| def __init__(self, clock: digitalio.DigitalInOut, data: digitalio.DigitalInOut, latch: digitalio.DigitalInOut) -> None:
//| """Initializes button scanning routines.
//|
//| The ``clock``, ``data`` and ``latch`` parameters are ``DigitalInOut``

View File

@ -168,7 +168,7 @@ const mp_obj_property_t gnss_timestamp_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| fix: gnss.PositionFix = ...
//| fix: PositionFix = ...
//| """Fix mode."""
//|
STATIC mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) {

View File

@ -11,19 +11,13 @@
//| """Enum-like class to define the position fix mode."""
//|
//| INVALID: PositionFix = ...
//| """No measurement.
//|
//| :type PositionFix:"""
//| """No measurement."""
//|
//| FIX_2D: PositionFix = ...
//| """2D fix.
//|
//| :type PositionFix:"""
//| """2D fix."""
//|
//| FIX_3D: PositionFix = ...
//| """3D fix.
//|
//| :type gnss.PositionFix:"""
//| """3D fix."""
//|
const mp_obj_type_t gnss_positionfix_type;

View File

@ -10,30 +10,20 @@
//| def __init__(self) -> None:
//| """Enum-like class to define the satellite system type."""
//|
//| GPS: SatelliteSystem = ...
//| """Global Positioning System.
//| GPS: SatelliteSystem
//| """Global Positioning System."""
//|
//| :type gnss.SatelliteSystem:"""
//| GLONASS: SatelliteSystem
//| """GLObal NAvigation Satellite System."""
//|
//| GLONASS: SatelliteSystem = ...
//| """GLObal NAvigation Satellite System.
//| SBAS: SatelliteSystem
//| """Satellite Based Augmentation System."""
//|
//| :type gnss.SatelliteSystem:"""
//| QZSS_L1CA: SatelliteSystem
//| """Quasi-Zenith Satellite System L1C/A."""
//|
//| SBAS: SatelliteSystem = ...
//| """Satellite Based Augmentation System.
//|
//| :type gnss.SatelliteSystem:"""
//|
//| QZSS_L1CA: SatelliteSystem = ...
//| """Quasi-Zenith Satellite System L1C/A.
//|
//| :type gnss.SatelliteSystem:"""
//|
//| QZSS_L1S: SatelliteSystem = ...
//| """Quasi-Zenith Satellite System L1S.
//|
//| :type gnss.SatelliteSystem:"""
//| QZSS_L1S: SatelliteSystem
//| """Quasi-Zenith Satellite System L1S."""
//|
const mp_obj_type_t gnss_satellitesystem_type;

View File

@ -79,10 +79,10 @@ STATIC NORETURN void math_error(void) {
#define log2(x) (log(x) * 1.442695040888963407354163704)
#endif
//| e: float = ...
//| e: float
//| """base of the natural logarithm"""
//|
//| pi: float = ...
//| pi: float
//| """the ratio of a circle's circumference to its diameter"""
//|
@ -126,7 +126,7 @@ STATIC NORETURN void math_error(void) {
//| """Return the absolute value of ``x``."""
//| ...
//|
//| def floor(x: float) -> float:
//| def floor(x: float) -> int:
//| """Return an integer, being ``x`` rounded towards negative infinity."""
//| ...
//|

View File

@ -35,7 +35,7 @@
//| class AllocationAlarm:
//|
//| def __init__(self, *, minimum_block_count=1):
//| def __init__(self, *, minimum_block_count: int = 1) -> None:
//| """Throw an exception when an allocation of ``minimum_block_count`` or more blocks
//| occurs while active.
//|
@ -76,7 +76,7 @@ STATIC mp_obj_t memorymonitor_allocationalarm_make_new(const mp_obj_type_t *type
return MP_OBJ_FROM_PTR(self);
}
//| def ignore(self, count) -> AllocationAlarm:
//| def ignore(self, count: int) -> AllocationAlarm:
//| """Sets the number of applicable allocations to ignore before raising the exception.
//| Automatically set back to zero at context exit.
//|
@ -98,7 +98,7 @@ STATIC mp_obj_t memorymonitor_allocationalarm_obj_ignore(mp_obj_t self_in, mp_ob
}
MP_DEFINE_CONST_FUN_OBJ_2(memorymonitor_allocationalarm_ignore_obj, memorymonitor_allocationalarm_obj_ignore);
//| def __enter__(self) -> memorymonitor.AllocationAlarm:
//| def __enter__(self) -> AllocationAlarm:
//| """Enables the alarm."""
//| ...
//|

View File

@ -35,7 +35,7 @@
//| class AllocationSize:
//|
//| def __init__(self):
//| def __init__(self) -> None:
//| """Tracks the number of allocations in power of two buckets.
//|
//| It will have 16 16-bit buckets to track allocation counts. It is total allocations
@ -72,7 +72,7 @@ STATIC mp_obj_t memorymonitor_allocationsize_make_new(const mp_obj_type_t *type,
return MP_OBJ_FROM_PTR(self);
}
//| def __enter__(self, ) -> Any:
//| def __enter__(self) -> AllocationSize:
//| """Clears counts and resumes tracking."""
//| ...
//|
@ -83,7 +83,7 @@ STATIC mp_obj_t memorymonitor_allocationsize_obj___enter__(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationsize___enter___obj, memorymonitor_allocationsize_obj___enter__);
//| def __exit__(self, ) -> Any:
//| def __exit__(self) -> None:
//| """Automatically pauses allocation tracking when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
@ -112,7 +112,7 @@ const mp_obj_property_t memorymonitor_allocationsize_bytes_per_block_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| def __len__(self, ) -> Any:
//| def __len__(self) -> int:
//| """Returns the number of allocation buckets.
//|
//| This allows you to::
@ -131,7 +131,7 @@ STATIC mp_obj_t memorymonitor_allocationsize_unary_op(mp_unary_op_t op, mp_obj_t
}
}
//| def __getitem__(self, index: Any) -> Any:
//| def __getitem__(self, index: int) -> Optional[int]:
//| """Returns the allocation count for the given bucket.
//|
//| This allows you to::

View File

@ -36,10 +36,9 @@
//| """Memory monitoring helpers"""
//|
//| class AllocationError:
//| def __init__(self, Exception: Any):
//| """Catchall exception for allocation related errors."""
//| ...
//| class AllocationError(Exception):
//| """Catchall exception for allocation related errors."""
//| ...
MP_DEFINE_MEMORYMONITOR_EXCEPTION(AllocationError, Exception)
NORETURN void mp_raise_memorymonitor_AllocationError(const compressed_string_t* fmt, ...) {

View File

@ -133,7 +133,7 @@ STATIC mp_obj_t mcu_reset(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_reset_obj, mcu_reset);
//| nvm: Any = ...
//| nvm: Optional[nvm.ByteArray] = ...
//| """Available non-volatile memory.
//| This object is the sole instance of `nvm.ByteArray` when available or ``None`` otherwise.
//|

View File

@ -37,7 +37,7 @@
//| serial connection and the optional secondary connection."""
//|
//| def get_secondary_terminal() -> secondary_terminal:
//| def get_secondary_terminal() -> Optional[typing.BinaryIO]:
//| """Returns the current secondary terminal."""
//| ...
//|
@ -46,7 +46,7 @@ STATIC mp_obj_t multiterminal_obj_get_secondary_terminal() {
}
MP_DEFINE_CONST_FUN_OBJ_0(multiterminal_get_secondary_terminal_obj, multiterminal_obj_get_secondary_terminal);
//| def set_secondary_terminal(stream: stream) -> None:
//| def set_secondary_terminal(stream: Optional[typing.BinaryIO]) -> None:
//| """Read additional input from the given stream and write out back to it.
//| This doesn't replace the core stream (usually UART or native USB) but is
//| mixed in instead.

View File

@ -51,11 +51,11 @@
//| neopixel_write.neopixel_write(pin, pixel_off)"""
//|
//| def neopixel_write(digitalinout: digitalio.DigitalInOut, buf: bytearray) -> None:
//| """Write buf out on the given DigitalInOut.
//| """Write buf out on the given DigitalInOut.
//|
//| :param digitalinout: the DigitalInOut to output with
//| :param buf: The bytes to clock out. No assumption is made about color order"""
//| ...
//| :param digitalinout: the DigitalInOut to output with
//| :param buf: The bytes to clock out. No assumption is made about color order"""
//| ...
STATIC mp_obj_t neopixel_write_neopixel_write_(mp_obj_t digitalinout_obj, mp_obj_t buf) {
if (!MP_OBJ_IS_TYPE(digitalinout_obj, &digitalio_digitalinout_type)) {
mp_raise_TypeError_varg(translate("Expected a %q"), digitalio_digitalinout_type.name);

View File

@ -49,7 +49,8 @@
//| ...
//|
//| def __bool__(self) -> bool: ...
//| def __bool__(self) -> bool:
//| ...
//|
//| def __len__(self) -> int:
//| """Return the length. This is used by (`len`)"""
@ -70,6 +71,18 @@ STATIC const mp_rom_map_elem_t nvm_bytearray_locals_dict_table[] = {
STATIC MP_DEFINE_CONST_DICT(nvm_bytearray_locals_dict, nvm_bytearray_locals_dict_table);
//| @overload
//| def __getitem__(self, index: slice) -> bytearray: ...
//| def __getitem__(self, index: int) -> int:
//| """Returns the value at the given index."""
//| ...
//|
//| @overload
//| def __setitem__(self, index: slice, value: ReadableBuffer) -> None: ...
//| def __setitem__(self, index: int, value: int) -> None:
//| """Set the value at the given index."""
//| ...
//|
STATIC mp_obj_t nvm_bytearray_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
if (value == MP_OBJ_NULL) {
// delete item

View File

@ -54,7 +54,7 @@ STATIC mp_obj_t os_uname(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(os_uname_obj, os_uname);
//| def chdir(path: string) -> None:
//| def chdir(path: str) -> None:
//| """Change current directory."""
//| ...
//|
@ -65,7 +65,7 @@ mp_obj_t os_chdir(mp_obj_t path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(os_chdir_obj, os_chdir);
//| def getcwd() -> string:
//| def getcwd() -> str:
//| """Get the current directory."""
//| ...
//|
@ -74,7 +74,7 @@ mp_obj_t os_getcwd(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(os_getcwd_obj, os_getcwd);
//| def listdir(dir: string) -> string:
//| def listdir(dir: str) -> str:
//| """With no argument, list the current directory. Otherwise list the given directory."""
//| ...
//|
@ -89,7 +89,7 @@ mp_obj_t os_listdir(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(os_listdir_obj, 0, 1, os_listdir);
//| def mkdir(path: string) -> None:
//| def mkdir(path: str) -> None:
//| """Create a new directory."""
//| ...
//|
@ -100,7 +100,7 @@ mp_obj_t os_mkdir(mp_obj_t path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(os_mkdir_obj, os_mkdir);
//| def remove(path: string) -> None:
//| def remove(path: str) -> None:
//| """Remove a file."""
//| ...
//|
@ -111,7 +111,7 @@ mp_obj_t os_remove(mp_obj_t path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(os_remove_obj, os_remove);
//| def rmdir(path: string) -> None:
//| def rmdir(path: str) -> None:
//| """Remove a directory."""
//| ...
//|
@ -123,7 +123,7 @@ mp_obj_t os_rename(mp_obj_t old_path_in, mp_obj_t new_path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_2(os_rename_obj, os_rename);
//| def rename(old_path: string, new_path: string) -> string:
//| def rename(old_path: str, new_path: str) -> str:
//| """Rename a file."""
//| ...
//|
@ -134,7 +134,7 @@ mp_obj_t os_rmdir(mp_obj_t path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(os_rmdir_obj, os_rmdir);
//| def stat(path: string) -> string:
//| def stat(path: str) -> str:
//| """Get the status of a file or directory.
//|
//| .. note:: On builds without long integers, the number of seconds
@ -149,7 +149,7 @@ mp_obj_t os_stat(mp_obj_t path_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(os_stat_obj, os_stat);
//| def statvfs(path: string) -> Tuple[string, string, string, string, string, string, string, string, string, string]:
//| def statvfs(path: str) -> Tuple[str, str, str, str, str, str, str, str, str, str]:
//| """Get the status of a fileystem.
//|
//| Returns a tuple with the filesystem information in the following order:
@ -189,7 +189,7 @@ STATIC mp_obj_t os_sync(void) {
}
MP_DEFINE_CONST_FUN_OBJ_0(os_sync_obj, os_sync);
//| def urandom(size: int) -> string:
//| def urandom(size: int) -> str:
//| """Returns a string of *size* random bytes based on a hardware True Random
//| Number Generator. When not available, it will raise a NotImplementedError."""
//| ...
@ -224,9 +224,9 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&os_urandom_obj) },
//| """.. data:: sep
//|
//| Separator used to delineate path components such as folder and file names."""
//| sep: str
//| """Separator used to delineate path components such as folder and file names."""
//|
{ MP_ROM_QSTR(MP_QSTR_sep), MP_ROM_QSTR(MP_QSTR__slash_) },
};

View File

@ -41,7 +41,7 @@
//| pulsed signal consists of timed on and off periods. Unlike PWM, there is no set duration
//| for on and off pairs."""
//|
//| def __init__(self, carrier: pulseio.PWMOut) -> None:
//| def __init__(self, carrier: PWMOut) -> None:
//| """Create a PulseOut object associated with the given PWMout object.
//|
//| :param ~pulseio.PWMOut carrier: PWMOut that is set to output on the desired pin.

View File

@ -46,6 +46,9 @@
//| .. warning:: Numbers from this module are not cryptographically strong! Use
//| bytes from `os.urandom` directly for true randomness."""
//|
//| from typing import TypeVar
//| _T = TypeVar('_T')
//|
//| def seed(seed: int) -> None:
//| """Sets the starting seed of the random number generation. Further calls to
@ -129,7 +132,7 @@ STATIC mp_obj_t random_randint(mp_obj_t a_in, mp_obj_t b_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(random_randint_obj, random_randint);
//| def choice(seq: list) -> Any:
//| def choice(seq: Sequence[_T]) -> _T:
//| """Returns a randomly selected element from the given sequence. Raises
//| IndexError when the sequence is empty."""
//| ...

View File

@ -128,7 +128,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_
}
}
//| def __init__(self, *, width: int, bit_depth: List[digitalio.DigitalInOut], rgb_pins: List[digitalio.DigitalInOut], addr_pins: List[digitalio.DigitalInOut], clock_pin: digitalio.DigitalInOut, latch_pin: digitalio.DigitalInOut, output_enable_pin: digitalio.DigitalInOut, doublebuffer: bool = True, framebuffer: Optional[WriteableBuffer] = None, height: int = 0) -> None:
//| def __init__(self, *, width: int, bit_depth: int, rgb_pins: Sequence[digitalio.DigitalInOut], addr_pins: List[digitalio.DigitalInOut], clock_pin: digitalio.DigitalInOut, latch_pin: digitalio.DigitalInOut, output_enable_pin: digitalio.DigitalInOut, doublebuffer: bool = True, framebuffer: Optional[WriteableBuffer] = None, height: int = 0) -> None:
//| """Create a RGBMatrix object with the given attributes. The height of
//| the display is determined by the number of rgb and address pins:
//| len(rgb_pins) // 3 * 2 ** len(address_pins). With 6 RGB pins and 4

View File

@ -44,7 +44,7 @@
//| `busio.SPI`, not `bitbangio.SPI`. Usually an SDCard object is used
//| with ``storage.VfsFat`` to allow file I/O to an SD card."""
//|
//| def __init__(bus:busio.SPI, cs: digitalio.DigitalInOut=digitalio.DigitalInOut, baudrate: int=8000000) -> None:
//| def __init__(self, bus: busio.SPI, cs: microcontroller.Pin, baudrate: int = 8000000) -> None:
//| """Construct an SPI SD Card object with the given properties
//|
//| :param busio.SPI spi: The SPI bus
@ -94,7 +94,7 @@ STATIC mp_obj_t sdcardio_sdcard_make_new(const mp_obj_type_t *type, size_t n_arg
}
//| def count() -> int:
//| def count(self) -> int:
//| """Returns the total number of sectors
//|
//| Due to technical limitations, this is a function and not a property.
@ -107,7 +107,7 @@ mp_obj_t sdcardio_sdcard_count(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_count_obj, sdcardio_sdcard_count);
//| def deinit() -> None:
//| def deinit(self) -> None:
//| """Disable permanently.
//|
//| :return: None"""
@ -120,7 +120,7 @@ mp_obj_t sdcardio_sdcard_deinit(mp_obj_t self_in) {
MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_deinit_obj, sdcardio_sdcard_deinit);
//| def readblocks(start_block: int, buf: bytearray) -> None:
//| def readblocks(self, start_block: int, buf: bytearray) -> None:
//|
//| """Read one or more blocks from the card
//|
@ -144,7 +144,7 @@ mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, m
MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_readblocks_obj, sdcardio_sdcard_readblocks);
//| def writeblocks(start_block: int, buf: bytearray) -> None:
//| def writeblocks(self, start_block: int, buf: bytearray) -> None:
//|
//| """Write one or more blocks to the card
//|

View File

@ -49,7 +49,7 @@
//| 25MHz. Usually an SDCard object is used with ``storage.VfsFat``
//| to allow file I/O to an SD card."""
//|
//| def __init__(*, clock: digitalio.DigitalInOut, command: digitalio.DigitalInOut, data: List[digitalio.DigitalInOut], frequency: int) -> None:
//| def __init__(self, clock: microcontroller.Pin, command: microcontroller.Pin, data: Sequence[microcontroller.Pin], frequency: int) -> None:
//| """Construct an SDIO SD Card object with the given properties
//|
//| :param ~microcontroller.Pin clock: the pin to use for the clock.
@ -109,7 +109,7 @@ STATIC void check_for_deinit(sdioio_sdcard_obj_t *self) {
}
}
//| def configure(*, frequency: int=0, width: int=0) -> None:
//| def configure(self, frequency: int = 0, width: int = 0) -> None:
//| """Configures the SDIO bus.
//|
//| :param int frequency: the desired clock rate in Hertz. The actual clock rate may be higher or lower due to the granularity of available clock settings. Check the `frequency` attribute for the actual clock rate.
@ -146,7 +146,7 @@ STATIC mp_obj_t sdioio_sdcard_configure(size_t n_args, const mp_obj_t *pos_args,
}
MP_DEFINE_CONST_FUN_OBJ_KW(sdioio_sdcard_configure_obj, 1, sdioio_sdcard_configure);
//| def count() -> int:
//| def count(self) -> int:
//| """Returns the total number of sectors
//|
//| Due to technical limitations, this is a function and not a property.
@ -160,7 +160,7 @@ STATIC mp_obj_t sdioio_sdcard_count(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_count_obj, sdioio_sdcard_count);
//| def readblocks(start_block: int, buf: bytearray) -> None:
//| def readblocks(self, start_block: int, buf: bytearray) -> None:
//|
//| """Read one or more blocks from the card
//|
@ -182,7 +182,7 @@ mp_obj_t sdioio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_
MP_DEFINE_CONST_FUN_OBJ_3(sdioio_sdcard_readblocks_obj, sdioio_sdcard_readblocks);
//| def writeblocks(start_block: int, buf: bytearray) -> None:
//| def writeblocks(self, start_block: int, buf: bytearray) -> None:
//|
//| """Write one or more blocks to the card
//|
@ -244,7 +244,7 @@ const mp_obj_property_t sdioio_sdcard_width_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| def deinit() -> None:
//| def deinit(self) -> None:
//| """Disable permanently.
//|
//| :return: None"""

View File

@ -512,7 +512,7 @@ STATIC const mp_obj_type_t socket_type = {
.locals_dict = (mp_obj_dict_t*)&socket_locals_dict,
};
//| def getaddrinfo(host: string, port: string) -> tuple:
//| def getaddrinfo(host: str, port: int) -> tuple:
//| """Gets the address information for a hostname and port
//|
//| Returns the appropriate family, socket type, socket protocol and

View File

@ -43,7 +43,7 @@
//| directly."""
//|
//| def mount(filesystem: VfsFat, mount_path: string, *, readonly: bool = False) -> None:
//| def mount(filesystem: VfsFat, mount_path: str, *, readonly: bool = False) -> None:
//| """Mounts the given filesystem object at the given path.
//|
//| This is the CircuitPython analog to the UNIX ``mount`` command.
@ -80,7 +80,7 @@ mp_obj_t storage_mount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_arg
}
MP_DEFINE_CONST_FUN_OBJ_KW(storage_mount_obj, 2, storage_mount);
//| def umount(mount: Union[string, VfsFat]) -> None:
//| def umount(mount: Union[str, VfsFat]) -> None:
//| """Unmounts the given filesystem object or if *mount* is a path, then unmount
//| the filesystem mounted at that location.
//|
@ -98,7 +98,7 @@ mp_obj_t storage_umount(mp_obj_t mnt_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(storage_umount_obj, storage_umount);
//| def remount(mount_path: string, readonly: bool = False, *, disable_concurrent_write_protection: bool = False) -> None:
//| def remount(mount_path: str, readonly: bool = False, *, disable_concurrent_write_protection: bool = False) -> None:
//| """Remounts the given path with new parameters.
//|
//| :param bool readonly: True when the filesystem should be readonly to CircuitPython.
@ -128,7 +128,7 @@ mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount);
//| def getmount(mount_path: string) -> VfsFat:
//| def getmount(mount_path: str) -> VfsFat:
//| """Retrieves the mount object associated with the mount path"""
//| ...
//|
@ -168,43 +168,43 @@ STATIC const mp_rom_map_elem_t storage_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) },
//| class VfsFat:
//| def __init__(self, block_device: string) -> None:
//| def __init__(self, block_device: str) -> None:
//| """Create a new VfsFat filesystem around the given block device.
//|
//| :param block_device: Block device the the filesystem lives on"""
//|
//| label: string = ...
//| """The filesystem label, up to 11 case-insensitive bytes. Note that
//| this property can only be set when the device is writable by the
//| microcontroller."""
//| ...
//| label: str
//| """The filesystem label, up to 11 case-insensitive bytes. Note that
//| this property can only be set when the device is writable by the
//| microcontroller."""
//| ...
//|
//| def mkfs(self) -> None:
//| """Format the block device, deleting any data that may have been there"""
//| ...
//|
//| def open(self, path: string, mode: string) -> None:
//| def open(self, path: str, mode: str) -> None:
//| """Like builtin ``open()``"""
//| ...
//|
//| def ilistdir(self, path: string) -> iterator:
//| def ilistdir(self, path: str) -> Iterator[Tuple[AnyStr, int, int, int]]:
//| """Return an iterator whose values describe files and folders within
//| ``path``"""
//| ...
//|
//| def mkdir(self, path: string) -> None:
//| def mkdir(self, path: str) -> None:
//| """Like `os.mkdir`"""
//| ...
//|
//| def rmdir(self, path: string) -> None:
//| def rmdir(self, path: str) -> None:
//| """Like `os.rmdir`"""
//| ...
//|
//| def stat(self, path: string) -> string:
//| def stat(self, path: str) -> str:
//| """Like `os.stat`"""
//| ...
//|
//| def statvfs(self, path: string) -> Tuple[string, string, string, string, string, string, string, string, string, string]:
//| def statvfs(self, path: str) -> Tuple[str, str, str, str, str, str, str, str, str, str]:
//| """Like `os.statvfs`"""
//| ...
//|

View File

@ -62,7 +62,7 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(struct_calcsize_obj, struct_calcsize);
//| def pack(fmt: string, *values: ReadableBuffer) -> bytes:
//| def pack(fmt: str, *values: ReadableBuffer) -> bytes:
//| """Pack the values according to the format string fmt.
//| The return value is a bytes object encoding the values."""
//| ...
@ -80,7 +80,7 @@ STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack);
//| def pack_into(fmt: string, buffer: WriteableBuffer, offset: int, *values: readableBuffer) -> None:
//| def pack_into(fmt: str, buffer: WriteableBuffer, offset: int, *values: ReadableBuffer) -> None:
//| """Pack the values according to the format string fmt into a buffer
//| starting at offset. offset may be negative to count from the end of buffer."""
//| ...
@ -106,7 +106,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_into_obj, 3, MP_OBJ_FUN_ARGS_MAX, struct_pack_into);
//| def unpack(fmt: string, data: ReadableBuffer) -> tuple:
//| def unpack(fmt: str, data: ReadableBuffer) -> tuple:
//| """Unpack from the data according to the format string fmt. The return value
//| is a tuple of the unpacked values. The buffer size must match the size
//| required by the format."""
@ -124,7 +124,7 @@ STATIC mp_obj_t struct_unpack(size_t n_args, const mp_obj_t *args) {
}
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_obj, 2, 3, struct_unpack);
//| def unpack_from(fmt: string, data: ReadableBuffer, offset: int = 0) -> tuple:
//| def unpack_from(fmt: str, data: ReadableBuffer, offset: int = 0) -> tuple:
//| """Unpack from the data starting at offset according to the format string fmt.
//| offset may be negative to count from the end of buffer. The return value is
//| a tuple of the unpacked values. The buffer size must be at least as big

View File

@ -34,7 +34,7 @@
//| """Heap size analysis"""
//|
//| def info(object: Any) -> int:
//| def info(object: object) -> int:
//| """Prints memory debugging info for the given object and returns the
//| estimated size."""
//| ...

View File

@ -36,7 +36,7 @@
//| The `usb_hid` module allows you to output data as a HID device."""
//|
//| usb_hid.devices: Any = ...
//| devices: Tuple[Device, ...]
//| """Tuple of all active HID device interfaces."""
//|
STATIC const mp_rom_map_elem_t usb_hid_module_globals_table[] = {

View File

@ -15,10 +15,8 @@
// #define VECTORIO_POLYGON_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__)
//| from typing import List, Tuple
//|
//| class Polygon:
//| def __init__(self, points: List[ Tuple[ x, y ], ... ] ) -> None:
//| def __init__(self, points: List[Tuple[int, int]]) -> None:
//| """Represents a closed shape by ordered vertices
//|
//| :param points: Vertices for the polygon"""
@ -44,7 +42,7 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar
}
//| points: List[ Tuple[ x, y ], ... ] = ...
//| points: List[Tuple[int, int]] = ...
//| """Set a new look and shape for this polygon"""
//|
STATIC mp_obj_t vectorio_polygon_obj_get_points(mp_obj_t self_in) {

View File

@ -20,7 +20,7 @@
//| class VectorShape:
//| def __init__(self, shape: vectorio.Polygon, pixel_shader: displayio.Palette, x: int=0, y: int=0) -> None:
//| def __init__(self, shape: Polygon, pixel_shader: displayio.Palette, x: int=0, y: int=0) -> None:
//| """Binds a vector shape to a location and pixel color
//|
//| :param shape: The shape to draw.

View File

@ -32,15 +32,15 @@
//| def __init__(self) -> None:
//| """Enum-like class to define the run mode of the watchdog timer."""
//|
//| RAISE: watchdog.WatchDogMode = ...
//| RAISE: WatchDogMode = ...
//| """Raise an exception when the WatchDogTimer expires.
//|
//| :type watchdog.WatchDogMode:"""
//| :type WatchDogMode:"""
//|
//| RESET: watchdog.WatchDogMode = ...
//| RESET: WatchDogMode = ...
//| """Reset the system if the WatchDogTimer expires.
//|
//| :type watchdog.WatchDogMode:"""
//| :type WatchDogMode:"""
//|
const mp_obj_type_t watchdog_watchdogmode_type;

View File

@ -54,7 +54,7 @@
//| ...
//|
//| def feed(self):
//| def feed(self) -> None:
//| """Feed the watchdog timer. This must be called regularly, otherwise
//| the timer will expire."""
//| ...
@ -71,7 +71,7 @@ STATIC mp_obj_t watchdog_watchdogtimer_feed(mp_obj_t self_in) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(watchdog_watchdogtimer_feed_obj, watchdog_watchdogtimer_feed);
//| def deinit(self):
//| def deinit(self) -> None:
//| """Stop the watchdog timer. This may raise an error if the watchdog
//| timer cannot be disabled on this platform."""
//| ...
@ -119,7 +119,7 @@ const mp_obj_property_t watchdog_watchdogtimer_timeout_obj = {
(mp_obj_t)&mp_const_none_obj},
};
//| mode: watchdog.WatchDogMode = ...
//| mode: WatchDogMode = ...
//| """The current operating mode of the WatchDogTimer `watchdog.WatchDogMode`.
//|
//| Setting a WatchDogMode activates the WatchDog::

View File

@ -13,11 +13,12 @@ import sys
import traceback
import isort
import black
IMPORTS_IGNORE = frozenset({'int', 'float', 'bool', 'str', 'bytes', 'tuple', 'list', 'set', 'dict', 'bytearray', 'file', 'buffer'})
IMPORTS_TYPING = frozenset({'Any', 'Optional', 'Union', 'Tuple', 'List', 'Sequence'})
IMPORTS_TYPESHED = frozenset({'ReadableBuffer', 'WritableBuffer'})
IMPORTS_IGNORE = frozenset({'int', 'float', 'bool', 'str', 'bytes', 'tuple', 'list', 'set', 'dict', 'bytearray', 'slice', 'file', 'buffer', 'range', 'array', 'struct_time'})
IMPORTS_TYPING = frozenset({'Any', 'Optional', 'Union', 'Tuple', 'List', 'Sequence', 'Iterable', 'Iterator', 'overload'})
IMPORTS_TYPESHED = frozenset({'ReadableBuffer', 'WriteableBuffer'})
def is_any(node):
@ -63,8 +64,9 @@ def extract_imports(tree):
typing.add(node.id)
elif node.id in IMPORTS_TYPESHED:
typeshed.add(node.id)
elif not node.id[0].isupper():
modules.add(node.id)
if node_type == ast.Attribute:
if type(node.value) == ast.Name:
modules.add(node.value.id)
for node in ast.walk(tree):
node_type = type(node)
@ -72,6 +74,9 @@ def extract_imports(tree):
collect_annotations(node.annotation)
elif node_type == ast.FunctionDef:
collect_annotations(node.returns)
for deco in node.decorator_list:
if deco.id in IMPORTS_TYPING:
typing.add(deco.id)
return {
"modules": sorted(modules),
@ -134,22 +139,21 @@ def convert_folder(top_level, stub_directory):
# Add import statements
import_lines = ["from __future__ import annotations"]
if imports["typing"]:
import_lines.append("from typing import " + ", ".join(imports["typing"]))
if imports["typeshed"]:
import_lines.append("from _typeshed import " + ", ".join(imports["typeshed"]))
import_lines.extend(f"import {m}" for m in imports["modules"])
import_lines.append("from typing import " + ", ".join(imports["typing"]))
import_lines.append("from _typeshed import " + ", ".join(imports["typeshed"]))
import_body = "\n".join(import_lines)
m = re.match(r'(\s*""".*?""")', stub_contents, flags=re.DOTALL)
if m:
stub_contents = m.group(1) + "\n\n" + import_body + "\n\n" + stub_contents[m.end():]
else:
stub_contents = import_body + "\n\n" + stub_contents
stub_contents = isort.code(stub_contents)
# Adjust blank lines
stub_contents = re.sub(r"\n+class", "\n\n\nclass", stub_contents)
stub_contents = re.sub(r"\n+def", "\n\n\ndef", stub_contents)
stub_contents = re.sub(r"\n+^(\s+)def", lambda m: f"\n\n{m.group(1)}def", stub_contents, flags=re.M)
stub_contents = stub_contents.strip() + "\n"
# Code formatting
stub_contents = isort.code(stub_contents)
stub_contents = black.format_str(stub_contents, mode=black.FileMode(is_pyi=True))
os.makedirs(stub_directory, exist_ok=True)
with open(stub_filename, "w") as f: