From 532639b820d375db8c80aaadea82d05809aab28b Mon Sep 17 00:00:00 2001 From: David Lechner Date: Tue, 6 Jul 2021 16:15:23 -0500 Subject: [PATCH] uio: add stubs and docs for uio module Issue: https://github.com/pybricks/support/issues/236 --- doc/api/index.rst | 1 + doc/api/uio.rst | 6 +++++ pyproject.toml | 1 + src/uio/__init__.py | 65 +++++++++++++++++++++++++++++++++++++++++++++ src/uio/py.typed | 0 5 files changed, 73 insertions(+) create mode 100644 doc/api/uio.rst create mode 100644 src/uio/__init__.py create mode 100644 src/uio/py.typed diff --git a/doc/api/index.rst b/doc/api/index.rst index f7d60c9..9c1aec8 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -79,6 +79,7 @@ findings on our `support page`_ so we can make Pybricks even better. micropython uerrno + uio .. toctree:: :maxdepth: 1 diff --git a/doc/api/uio.rst b/doc/api/uio.rst new file mode 100644 index 0000000..7356faa --- /dev/null +++ b/doc/api/uio.rst @@ -0,0 +1,6 @@ +:mod:`uio` -- Input/output streams +================================== + +.. note:: This module is not available on the BOOST Move Hub. + +.. automodule:: uio diff --git a/pyproject.toml b/pyproject.toml index 3f7c5df..d53ed4c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ packages = [ { include = "pybricks", from = "src" }, { include = "micropython", from = "src" }, { include = "uerrno", from = "src" }, + { include = "uio", from = "src" }, ] [tool.poetry.dependencies] diff --git a/src/uio/__init__.py b/src/uio/__init__.py new file mode 100644 index 0000000..c738cda --- /dev/null +++ b/src/uio/__init__.py @@ -0,0 +1,65 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2021 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. +""" + +# TODO: open() is not implemented on Powered Up hubs + +from typing import overload + +# TODO: MicroPython streams implement '__enter__', '__exit__', 'close', 'read', +# 'readinto', 'readline', 'write', 'flush', 'getvalue', 'seek', 'tell' +# and are iterable + + +class BytesIO: + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, initial_bytes: bytes) -> None: + ... + + @overload + def __init__(self, alloc_size: int) -> None: + ... + + def __init__(self, *args) -> None: + """ + 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. + """ + + +class StringIO: + @overload + def __init__(self) -> None: + ... + + @overload + def __init__(self, initial_value: str) -> None: + ... + + @overload + def __init__(self, alloc_size: int) -> None: + ... + + def __init__(self, *args) -> None: + """ + A binary stream using an in-memory string buffer. + + Args: + initial_value: Optional string object that contains initial data. + alloc_size: Optional number of preallocated bytes. + """ diff --git a/src/uio/py.typed b/src/uio/py.typed new file mode 100644 index 0000000..e69de29