From c656eae2f35658bc585c3a90b400350292a791e6 Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Wed, 14 Jul 2021 14:13:18 +0200 Subject: [PATCH] micropython: Drop TConst type. TConst does not exist, so adding it makes it a bit harder to read than needed. The const() "function" will take int or float, and the return value can be used as such, even if it is optimized out. This is described in the docstring, so we can leave out the additional type. Also adds autofunctions in place of one auto module so we can move things around as needed. Also fix cross links with usys to get the build to pass before we update that module. --- doc/main/micropython/micropython.rst | 16 ++++++++++++++++ src/micropython/__init__.py | 9 ++------- src/usys/__init__.py | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/doc/main/micropython/micropython.rst b/doc/main/micropython/micropython.rst index 99c2482..0dcc304 100644 --- a/doc/main/micropython/micropython.rst +++ b/doc/main/micropython/micropython.rst @@ -2,3 +2,19 @@ =========================================== .. automodule:: micropython + :no-members: + +.. autofunction:: micropython.const + +.. autofunction:: micropython.opt_level + +.. autofunction:: micropython.mem_info + +.. autofunction:: micropython.qstr_info + +.. autofunction:: micropython.stack_use + +.. autofunction:: micropython.kbd_intr + + + diff --git a/src/micropython/__init__.py b/src/micropython/__init__.py index b8e1b1e..3b45de9 100644 --- a/src/micropython/__init__.py +++ b/src/micropython/__init__.py @@ -9,15 +9,10 @@ Access and control MicroPython internals. """ -from typing import Any, Literal, TypeVar, overload - -TConst = TypeVar("TConst", int, float) -""" -Allowable types for :meth:`const`. -""" +from typing import Any, Literal, Union, overload -def const(expr: TConst) -> TConst: +def const(expression: Union[int, float]) -> Union[int, float]: """ Used to declare that the expression is a constant so that the compile can optimise it. The use of this function should be as follows:: diff --git a/src/usys/__init__.py b/src/usys/__init__.py index 2d9e5a6..f400afc 100644 --- a/src/usys/__init__.py +++ b/src/usys/__init__.py @@ -22,7 +22,7 @@ Stream object that receives input from a connected terminal, if any. Writing may modify newline characters. Use ``usys.stdin.buffer`` instead if this is undesirable. -Also see :meth:`micropython.kbd_intr` to disable ``KeyboardInterrupt`` if you +Also see :func:`micropython.kbd_intr` to disable ``KeyboardInterrupt`` if you are passing binary data via ``stdin``. """