From 71ce165a46e79acde8613b06aaa4a2650c93b69e Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Tue, 29 Nov 2022 20:21:11 +0100 Subject: [PATCH] uio: Update style. Also fix compatibility information. --- doc/main/micropython/uio.rst | 4 ++-- src/uio/__init__.py | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/doc/main/micropython/uio.rst b/doc/main/micropython/uio.rst index 7356faa..890c573 100644 --- a/doc/main/micropython/uio.rst +++ b/doc/main/micropython/uio.rst @@ -1,6 +1,6 @@ +.. pybricks-requirements:: stm32-extra + :mod:`uio` -- Input/output streams ================================== -.. note:: This module is not available on the BOOST Move Hub. - .. automodule:: uio diff --git a/src/uio/__init__.py b/src/uio/__init__.py index 3b29582..8e9c0cb 100644 --- a/src/uio/__init__.py +++ b/src/uio/__init__.py @@ -1,18 +1,17 @@ # SPDX-License-Identifier: MIT -# Copyright (c) 2021 The Pybricks Authors +# Copyright (c) 2022 The Pybricks Authors # # Portions of documentation copied from: # https://raw.githubusercontent.com/micropython/micropython/1e6d18c915ccea0b6a19ffec9710d33dd7e5f866/docs/library/uio.rst # Copyright (c) 2014-2021, Damien P. George, Paul Sokolovsky, and contributors """ -This module contains additional types of ``stream`` (file-like) objects -and helper functions. +This module contains ``stream`` objects that behave like files. """ # TODO: open() is not implemented on Powered Up hubs -from typing import overload +from typing import overload, Union # TODO: MicroPython streams implement '__enter__', '__exit__', 'close', 'read', # 'readinto', 'readline', 'write', 'flush', 'getvalue', 'seek', 'tell' @@ -25,7 +24,7 @@ class BytesIO: ... @overload - def __init__(self, initial_bytes: bytes) -> None: + def __init__(self, data: Union[bytes, bytearray]) -> None: ... @overload @@ -34,11 +33,16 @@ class BytesIO: def __init__(self, *args) -> None: """ + BytesIO(​) + BytesIO(data) + BytesIO(alloc_size) + A binary stream using an in-memory bytes buffer. - Args: - initial_bytes: Optional bytes-like object that contains initial data. - alloc_size: Optional number of preallocated bytes. + Arguments: + data (bytes or bytearray): Optional bytes-like object + that contains initial data. + alloc_size (int): Optional number of preallocated bytes. """ @@ -48,7 +52,7 @@ class StringIO: ... @overload - def __init__(self, initial_value: str) -> None: + def __init__(self, string: str) -> None: ... @overload @@ -57,16 +61,20 @@ class StringIO: def __init__(self, *args) -> None: """ - A binary stream using an in-memory string buffer. + StringIO(​) + StringIO(string) + StringIO(alloc_size) - Args: - initial_value: Optional string object that contains initial data. - alloc_size: Optional number of preallocated bytes. + A stream using an in-memory string buffer. + + Arguments: + string (str): Optional string with initial data. + alloc_size (int): Optional number of preallocated bytes. """ class FileIO: """ - This is type of a file open in binary mode, e.g. using ``open(name, 'rb')``. + This type represents a file opened in binary mode with ``open(name, 'rb')``. You should not instantiate this class directly. """