├── .gitignore ├── LICENSE ├── README.md ├── dist ├── micropython-typesheds-7.5.3.tar.gz └── micropython_typesheds-7.5.3-py3-none-any.whl ├── media ├── code.png ├── download.png ├── enable_pt1.png ├── enable_pt2.png ├── files.png ├── help.png ├── type.png ├── typesheds.png └── typo.png ├── micropython_typesheds.egg-info ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt └── top_level.txt ├── micropython_typesheds.py ├── micropython_typesheds ├── _thread.pyi ├── array.pyi ├── binascii.pyi ├── bluetooth.pyi ├── btree.pyi ├── cmath.pyi ├── collections.pyi ├── cryptolib.pyi ├── errno.pyi ├── esp.pyi ├── esp32.pyi ├── framebuf.pyi ├── gc.pyi ├── hashlib.pyi ├── heapq.pyi ├── io.pyi ├── json.pyi ├── lcd160cr.pyi ├── machine.ADCWiPy.pyi ├── machine.TimerWiPy.pyi ├── machine.pyi ├── math.pyi ├── micropython.pyi ├── neopixel.pyi ├── network.pyi ├── os.pyi ├── pyb.pyi ├── random.pyi ├── re.pyi ├── select.pyi ├── socket.pyi ├── ssl.pyi ├── stm.pyi ├── struct.pyi ├── sys.pyi ├── time.pyi ├── uarray.pyi ├── uasyncio.pyi ├── ubinascii.pyi ├── ubluetooth.pyi ├── ucollections.pyi ├── ucryptolib.pyi ├── uctypes.pyi ├── uerrno.pyi ├── uhashlib.pyi ├── uheapq.pyi ├── uio.pyi ├── ujson.pyi ├── uos.pyi ├── ure.pyi ├── uselect.pyi ├── usocket.pyi ├── ussl.pyi ├── ustruct.pyi ├── usys.pyi ├── utime.pyi ├── uzlib.pyi ├── wipy.pyi └── zlib.pyi └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Howard Lovatt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Micropython Typesheds (formerly known as Pyboard Typesheds) 2 | 3 | Rich typeshed (a.k.a.: type hints, interface stubs, and `.pyi` files) 4 | for [MicroPython](http://micropython.org). 5 | They are *rich* typesheds because they give help document for 6 | functions/methods, function/method arguments, function/method return types, 7 | method overloads, classes, modules, protocols, 8 | and constants/fields/properties. 9 | These typesheds are useful for IDEs that understand type hints, 10 | like PyCharm and VSCode, and for IDE plugins like the PyCharm's MicroPython plugin. 11 | 12 | ## What the typesheds do 13 | 14 | Once installed, see next section, the typesheds offer: 15 | 16 | 1. Code completion (in this case prompting completion for `pyb`):\ 17 | ![Code completion example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/code.png?raw=true "Possible code completions") 18 | 19 | 2. Rich help text (in this case constructor for `LCD160CR` 20 | showing argument types, argument defaults, return types and 21 | overloads as well as a description):\ 22 | ![Rich help example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/help.png?raw=true "Rich help for overloaded constructor") 23 | 24 | 3. Type errors (in this case a `float` instead of an `int`):\ 25 | ![Type error example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/type.png?raw=true "Detects type error") 26 | 27 | 4. Typos (in this case `colour` instead of `color`; error can be avoided by 28 | using code completion, see point 1 above):\ 29 | ![Type error example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/typo.png?raw=true "Detects missing attribute due to typo") 30 | 31 | ## Using the typesheds 32 | 33 | There are four ways of installing the Typesheds: 34 | via an IDE plugin, manually install into the IDE, 35 | use PyPI, copy the `.pyi` files into a project, 36 | and manually copy the `.pyi` files into a project. 37 | 38 | ### Via an IDE plugin 39 | 40 | #### For PyCharm 41 | 42 | Currently, December 2021, JetBrains have added many of these typesheds to their 43 | MicroPython plugin (many thanks to JetBrains and in particular Andrey Vlasovskikh). 44 | Therefore, installing the JetBrains Micropython plugin 45 | will be the easiest solution and also 46 | the typesheds will get updated everytime the plugin is updated: 47 | 48 | 1. Install the 49 | [MicroPython plugin](https://plugins.jetbrains.com/plugin/9777-micropython). 50 | 51 | 2. Enable the plugin for the project 52 | (two stages in project preferences/options: 53 | add the plugin to the project and then select options in the plugin):\ 54 | ![Enable MicroPython plugin for project part 1](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/enable_pt1.png?raw=true "Select MicroPython Language") 55 | ![Enable MicroPython plugin for project part 2](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/enable_pt2.png?raw=true "Enable MicroPython support, select Pyboard, and select device path)") 56 | 57 | The other options, below, unfortunately require manual updating and are more 58 | involved (though not difficult). 59 | 60 | ### Manually install in an IDE 61 | 62 | #### For PyCharm 63 | 64 | If the very latest typesheds are required then they can be installed from 65 | this repository directly. 66 | 67 | **Note:** The following procedure, below, only needs to be done for one project; 68 | after which all projects using the 69 | MicroPython plugin will pick up the typesheds. 70 | 71 | 1. Install and enable the plugin, see previous section above. 72 | 73 | 2. Download the ZIPed `.pyi` files from GitHub:\ 74 | ![Download ZIPed files from GitHub](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/download.png?raw=true "Select 'Download Zip' from 'Code' dropdown") 75 | 76 | 3. Unpack the ZIP file. 77 | 78 | 4. Drag (or copy and past) the `.pyi` (only) files into the Micropython Plugin 79 | (see image for which directory to put each file in):\ 80 | ![Drag `.pyi` files into Plugin](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/typesheds.png?raw=true "`.pyi` files in Micropython plugin") 81 | 82 | 5. Disable and re-enable plugin by going to preferences/options un-tick 83 | Micropython support and Apply then re-tick 84 | MicroPython support and OK 85 | (so that it picks up the changes):\ 86 | ![Re-enable MicroPython plugin](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/enable_pt2.png?raw=true "Un-tick and OK back into preferences re-tick MicroPython support and OK") 87 | 88 | ### Use PyPI to copy the `.pyi` files into a project or IDE 89 | 90 | 1. Install the typesheds' installer 91 | 92 | ```bash 93 | pip install --upgrade micropython-typesheds 94 | ``` 95 | 96 | 2. Copy the typesheds to where they are required. 97 | EG typeshed location for IDE or plugin or top 98 | level of project. 99 | **Note:** The following command, below, needs 100 | to be done for *all* required locations: 101 | 102 | ```bash 103 | python -m micropython_typesheds 104 | ``` 105 | 106 | ### Copy `.pyi` files into a project 107 | 108 | **Note:** The following procedure, below, needs to be done for *all* projects: 109 | 110 | 1. Download the ZIPed `.pyi` files from GitHub:\ 111 | ![Download ZIPed files from GitHub](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/download.png?raw=true "Select 'Download Zip' from 'Code' dropdown") 112 | 113 | 2. Unpack the ZIP file. 114 | 115 | 3. Drag the `.pyi` (only) files from directory `micropython_typesheds` into the top level of a project:\ 116 | ![Drag `.pyi` files in top level of project](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/files.png?raw=true "`.pyi` files in top level of project") 117 | 118 | ## Philosophy 119 | 120 | The typesheds are generated by 121 | [https://github.com/hlovatt/PyBoardTypeshedGenerator]() 122 | from the MicroPython `.rst` doc files. 123 | 124 | The philosophy of generating the typesheds is to take a superset of what is 125 | in the docs and what is listed by the `dir` 126 | command on a MicroPython board 127 | (the docs and `dir` don't agree!). 128 | An example of the `dir` command having more information than the docs is the docs 129 | for `pyb.Pin` mentions `board` and `cpu` classes and implies they contain 130 | declarations of available `Pin`s; 131 | `dir(pyb.Pin.cpu)` on the other hand lists the `Pin`s, 132 | therefore the generated typeshed contains `board` and `cpu` 133 | *with* `Pin` definitions. 134 | -------------------------------------------------------------------------------- /dist/micropython-typesheds-7.5.3.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/dist/micropython-typesheds-7.5.3.tar.gz -------------------------------------------------------------------------------- /dist/micropython_typesheds-7.5.3-py3-none-any.whl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/dist/micropython_typesheds-7.5.3-py3-none-any.whl -------------------------------------------------------------------------------- /media/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/code.png -------------------------------------------------------------------------------- /media/download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/download.png -------------------------------------------------------------------------------- /media/enable_pt1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/enable_pt1.png -------------------------------------------------------------------------------- /media/enable_pt2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/enable_pt2.png -------------------------------------------------------------------------------- /media/files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/files.png -------------------------------------------------------------------------------- /media/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/help.png -------------------------------------------------------------------------------- /media/type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/type.png -------------------------------------------------------------------------------- /media/typesheds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/typesheds.png -------------------------------------------------------------------------------- /media/typo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hlovatt/PyBoardTypeshed/db986058be995bbcde6227c4d84f654329424d9c/media/typo.png -------------------------------------------------------------------------------- /micropython_typesheds.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: micropython-typesheds 3 | Version: 7.5.3 4 | Summary: Typesheds (a.k.a.: interface stubs, `pyi` files, and type hints) for MicroPython. 5 | Home-page: https://github.com/hlovatt/PyBoardTypeshed 6 | Author: Howard C Lovatt 7 | Author-email: howard.lovatt@gmail.com 8 | License: MIT License 9 | Platform: any 10 | Classifier: Intended Audience :: Developers 11 | Classifier: Programming Language :: Python :: Implementation :: MicroPython 12 | Classifier: License :: OSI Approved :: MIT License 13 | Classifier: Operating System :: OS Independent 14 | Requires-Python: >=3.8 15 | Description-Content-Type: text/markdown 16 | License-File: LICENSE 17 | 18 | # Micropython Typesheds (formerly known as Pyboard Typesheds) 19 | 20 | Rich typeshed (a.k.a.: type hints, interface stubs, and `.pyi` files) 21 | for [MicroPython](http://micropython.org). 22 | They are *rich* typesheds because they give help document for 23 | functions/methods, function/method arguments, function/method return types, 24 | method overloads, classes, modules, protocols, 25 | and constants/fields/properties. 26 | These typesheds are useful for IDEs that understand type hints, 27 | like PyCharm and VSCode, and for IDE plugins like the PyCharm's MicroPython plugin. 28 | 29 | ## What the typesheds do 30 | 31 | Once installed, see next section, the typesheds offer: 32 | 33 | 1. Code completion (in this case prompting completion for `pyb`):\ 34 | ![Code completion example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/code.png?raw=true "Possible code completions") 35 | 36 | 2. Rich help text (in this case constructor for `LCD160CR` 37 | showing argument types, argument defaults, return types and 38 | overloads as well as a description):\ 39 | ![Rich help example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/help.png?raw=true "Rich help for overloaded constructor") 40 | 41 | 3. Type errors (in this case a `float` instead of an `int`):\ 42 | ![Type error example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/type.png?raw=true "Detects type error") 43 | 44 | 4. Typos (in this case `colour` instead of `color`; error can be avoided by 45 | using code completion, see point 1 above):\ 46 | ![Type error example](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/typo.png?raw=true "Detects missing attribute due to typo") 47 | 48 | ## Using the typesheds 49 | 50 | There are four ways of installing the Typesheds: 51 | via an IDE plugin, manually install into the IDE, 52 | use PyPI, copy the `.pyi` files into a project, 53 | and manually copy the `.pyi` files into a project. 54 | 55 | ### Via an IDE plugin 56 | 57 | #### For PyCharm 58 | 59 | Currently, December 2021, JetBrains have added many of these typesheds to their 60 | MicroPython plugin (many thanks to JetBrains and in particular Andrey Vlasovskikh). 61 | Therefore, installing the JetBrains Micropython plugin 62 | will be the easiest solution and also 63 | the typesheds will get updated everytime the plugin is updated: 64 | 65 | 1. Install the 66 | [MicroPython plugin](https://plugins.jetbrains.com/plugin/9777-micropython). 67 | 68 | 2. Enable the plugin for the project 69 | (two stages in project preferences/options: 70 | add the plugin to the project and then select options in the plugin):\ 71 | ![Enable MicroPython plugin for project part 1](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/enable_pt1.png?raw=true "Select MicroPython Language") 72 | ![Enable MicroPython plugin for project part 2](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/enable_pt2.png?raw=true "Enable MicroPython support, select Pyboard, and select device path)") 73 | 74 | The other options, below, unfortunately require manual updating and are more 75 | involved (though not difficult). 76 | 77 | ### Manually install in an IDE 78 | 79 | #### For PyCharm 80 | 81 | If the very latest typesheds are required then they can be installed from 82 | this repository directly. 83 | 84 | **Note:** The following procedure, below, only needs to be done for one project; 85 | after which all projects using the 86 | MicroPython plugin will pick up the typesheds. 87 | 88 | 1. Install and enable the plugin, see previous section above. 89 | 90 | 2. Download the ZIPed `.pyi` files from GitHub:\ 91 | ![Download ZIPed files from GitHub](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/download.png?raw=true "Select 'Download Zip' from 'Code' dropdown") 92 | 93 | 3. Unpack the ZIP file. 94 | 95 | 4. Drag (or copy and past) the `.pyi` (only) files into the Micropython Plugin 96 | (see image for which directory to put each file in):\ 97 | ![Drag `.pyi` files into Plugin](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/typesheds.png?raw=true "`.pyi` files in Micropython plugin") 98 | 99 | 5. Disable and re-enable plugin by going to preferences/options un-tick 100 | Micropython support and Apply then re-tick 101 | MicroPython support and OK 102 | (so that it picks up the changes):\ 103 | ![Re-enable MicroPython plugin](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/enable_pt2.png?raw=true "Un-tick and OK back into preferences re-tick MicroPython support and OK") 104 | 105 | ### Use PyPI to copy the `.pyi` files into a project or IDE 106 | 107 | 1. Install the typesheds' installer 108 | 109 | ```bash 110 | pip install --upgrade micropython-typesheds 111 | ``` 112 | 113 | 2. Copy the typesheds to where they are required. 114 | EG typeshed location for IDE or plugin or top 115 | level of project. 116 | **Note:** The following command, below, needs 117 | to be done for *all* required locations: 118 | 119 | ```bash 120 | python -m micropython_typesheds 121 | ``` 122 | 123 | ### Copy `.pyi` files into a project 124 | 125 | **Note:** The following procedure, below, needs to be done for *all* projects: 126 | 127 | 1. Download the ZIPed `.pyi` files from GitHub:\ 128 | ![Download ZIPed files from GitHub](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/download.png?raw=true "Select 'Download Zip' from 'Code' dropdown") 129 | 130 | 2. Unpack the ZIP file. 131 | 132 | 3. Drag the `.pyi` (only) files from directory `micropython_typesheds` into the top level of a project:\ 133 | ![Drag `.pyi` files in top level of project](https://github.com/hlovatt/PyBoardTypeshed/blob/master/media/files.png?raw=true "`.pyi` files in top level of project") 134 | 135 | ## Philosophy 136 | 137 | The typesheds are generated by 138 | [https://github.com/hlovatt/PyBoardTypeshedGenerator]() 139 | from the MicroPython `.rst` doc files. 140 | 141 | The philosophy of generating the typesheds is to take a superset of what is 142 | in the docs and what is listed by the `dir` 143 | command on a MicroPython board 144 | (the docs and `dir` don't agree!). 145 | An example of the `dir` command having more information than the docs is the docs 146 | for `pyb.Pin` mentions `board` and `cpu` classes and implies they contain 147 | declarations of available `Pin`s; 148 | `dir(pyb.Pin.cpu)` on the other hand lists the `Pin`s, 149 | therefore the generated typeshed contains `board` and `cpu` 150 | *with* `Pin` definitions. 151 | 152 | 153 | -------------------------------------------------------------------------------- /micropython_typesheds.egg-info/SOURCES.txt: -------------------------------------------------------------------------------- 1 | LICENSE 2 | README.md 3 | micropython_typesheds.py 4 | setup.py 5 | micropython_typesheds.egg-info/PKG-INFO 6 | micropython_typesheds.egg-info/SOURCES.txt 7 | micropython_typesheds.egg-info/dependency_links.txt 8 | micropython_typesheds.egg-info/top_level.txt -------------------------------------------------------------------------------- /micropython_typesheds.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /micropython_typesheds.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | micropython_typesheds 2 | -------------------------------------------------------------------------------- /micropython_typesheds.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copies the Micropython typesheds into the given directory (directory must exist). 3 | """ 4 | 5 | __author__ = "Howard C Lovatt" 6 | __copyright__ = "Howard C Lovatt, 2020 onwards." 7 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 8 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 9 | 10 | from argparse import ArgumentParser 11 | from io import BytesIO 12 | 13 | # noinspection PyUnresolvedReferences 14 | from os import scandir # Not in Micropython `os`, hence suppression for CPython use. 15 | from pathlib import Path 16 | from shutil import copy2 17 | from tempfile import TemporaryDirectory 18 | from typing import Final 19 | from urllib.request import urlopen 20 | from zipfile import ZipFile 21 | 22 | 23 | def main(): 24 | parse_args: Final = ArgumentParser( 25 | description="Copy Micropython typesheds (a.k.a.: interface stubs, `pyi` files, and type hints) into given directory (directory must exist)" 26 | ) 27 | parse_args.add_argument( 28 | "-V", 29 | "--version", 30 | help="show program's version number and exit", 31 | action="version", 32 | version="%(prog)s " + __version__, 33 | ) 34 | parse_args.add_argument( 35 | "directory", 36 | help="directory (which must exist) into which typesheds are copied into", 37 | ) 38 | args: Final = parse_args.parse_args() 39 | destination_dir: Final = Path(args.directory) 40 | if not destination_dir.is_dir(): 41 | raise NotADirectoryError( 42 | f"Given destination directory, `{destination_dir}`, is not an existing directory!" 43 | ) 44 | 45 | with urlopen( 46 | "https://github.com/hlovatt/PyBoardTypeshed/archive/master.zip" 47 | ) as http_response: 48 | with ZipFile(BytesIO(http_response.read())) as zipfile: 49 | typesheds: Final = [f for f in zipfile.namelist() if f.endswith(".pyi")] 50 | with TemporaryDirectory() as temp_top_level: 51 | zipfile.extractall(path=temp_top_level, members=typesheds) 52 | temp_typeshed_level = ( 53 | Path(temp_top_level) 54 | / "PyBoardTypeshed-master" 55 | / "micropython_typesheds" 56 | ) 57 | for file in scandir(temp_typeshed_level): 58 | copy2(file, destination_dir) 59 | 60 | 61 | if __name__ == "__main__": 62 | main() 63 | -------------------------------------------------------------------------------- /micropython_typesheds/_thread.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | multithreading support. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/_thread.rst. 6 | ======================================== 7 | 8 | .. module:: _thread 9 | :synopsis: multithreading support 10 | 11 | |see_cpython_module| :mod:`python:_thread`. 12 | 13 | This module implements multithreading support. 14 | 15 | This module is highly experimental and its API is not yet fully settled 16 | and not yet described in this documentation. 17 | """ 18 | 19 | __author__ = "Howard C Lovatt" 20 | __copyright__ = "Howard C Lovatt, 2020 onwards." 21 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 22 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 23 | -------------------------------------------------------------------------------- /micropython_typesheds/array.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | efficient arrays of numeric data. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/array.rst. 6 | """ 7 | 8 | __author__ = "Howard C Lovatt" 9 | __copyright__ = "Howard C Lovatt, 2020 onwards." 10 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 11 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 12 | 13 | from typing import ( 14 | overload, 15 | Sequence, 16 | Any, 17 | MutableSequence, 18 | Generic, 19 | Text, 20 | TypeVar, 21 | Final, 22 | ) 23 | 24 | _T: Final = TypeVar("_T", int, float, Text) 25 | 26 | # noinspection PyPep8Naming 27 | class array(MutableSequence[_T], Generic[_T]): 28 | """ 29 | |see_cpython_module| :mod:`python:array`. 30 | 31 | Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``, 32 | ``L``, ``q``, ``Q``, ``f``, ``d`` (the latter 2 depending on the 33 | floating-point support). 34 | 35 | +-----------+--------------------+-------------------+-----------------------+ 36 | | Type code | C Type | Python Type | Minimum size in bytes | 37 | +===========+====================+===================+=======================+ 38 | | ``'b'`` | signed char | int | 1 | 39 | +-----------+--------------------+-------------------+-----------------------+ 40 | | ``'B'`` | unsigned char | int | 1 | 41 | +-----------+--------------------+-------------------+-----------------------+ 42 | | ``'h'`` | signed short | int | 2 | 43 | +-----------+--------------------+-------------------+-----------------------+ 44 | | ``'H'`` | unsigned short | int | 2 | 45 | +-----------+--------------------+-------------------+-----------------------+ 46 | | ``'i'`` | signed int | int | 2 | 47 | +-----------+--------------------+-------------------+-----------------------+ 48 | | ``'I'`` | unsigned int | int | 2 | 49 | +-----------+--------------------+-------------------+-----------------------+ 50 | | ``'l'`` | signed long | int | 4 | 51 | +-----------+--------------------+-------------------+-----------------------+ 52 | | ``'L'`` | unsigned long | int | 4 | 53 | +-----------+--------------------+-------------------+-----------------------+ 54 | | ``'q'`` | signed long long | int | 8 | 55 | +-----------+--------------------+-------------------+-----------------------+ 56 | | ``'Q'`` | unsigned long long | int | 8 | 57 | +-----------+--------------------+-------------------+-----------------------+ 58 | | ``'f'`` | float | float | 4 | 59 | +-----------+--------------------+-------------------+-----------------------+ 60 | | ``'d'`` | double | float | 8 | 61 | +-----------+--------------------+-------------------+-----------------------+ 62 | """ 63 | 64 | def __init__(self, typecode: str, iterable: Sequence[Any] = ..., /): 65 | """ 66 | Create array with elements of given type. Initial contents of the 67 | array are given by *iterable*. If it is not provided, an empty 68 | array is created. 69 | """ 70 | def append(self, val: Any, /) -> None: 71 | """ 72 | Append new element *val* to the end of array, growing it. 73 | """ 74 | def extend(self, iterable: Sequence[Any], /) -> None: 75 | """ 76 | Append new elements as contained in *iterable* to the end of 77 | array, growing it. 78 | """ 79 | def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: 80 | """ 81 | Deprecated *do not use*, likely to be removed in future! 82 | 83 | Note: ``decode`` is only meant to be present for ``bytearray``, 84 | but for efficiency of code-size reasons ``bytearray`` is implemented with the same code as the 85 | other array type-codes and hence ``decode`` is on all ``array``s at present. 86 | """ 87 | @overload 88 | def __delitem__(self, i: int) -> None: 89 | """``array`` object does **not** support item deletion.""" 90 | @overload 91 | def __delitem__(self, sl: slice) -> None: 92 | """``array`` object does **not** support item deletion.""" 93 | def insert(self, index: int, value: _T) -> None: 94 | """``array`` object does **not** support item insertion.""" 95 | @overload 96 | def __getitem__(self, index: int) -> _T: 97 | """ 98 | Indexed read of ``self``; called as ``a[index]``, where ``a`` is an ``array``. 99 | Returns the value at the given ``index``. 100 | Negative indices count from end and ``IndexError``is thrown if the index out of range. 101 | 102 | **Note:** ``__getitem__`` cannot be called directly (``a.__getitem__(index)`` fails) and 103 | is not present in ``__dict__``, however ``a[index]`` does work. 104 | """ 105 | @overload 106 | def __getitem__(self, sl: slice) -> array[_T]: 107 | """ 108 | Slice read of ``self``; called as ``a[sl]``, where ``a`` is an ``array``. 109 | Returns an ``array`` of values for the given slice. 110 | Negative slice indices count from end and ``IndexError``is thrown if any of the slice indices are out of range. 111 | **Note:** ``__getitem__`` cannot be called directly (``a.__getitem__(sl)`` fails) and 112 | is not present in ``__dict__``, however ``a[sl]`` does work. 113 | """ 114 | @overload 115 | def __setitem__(self, index: int, value: _T) -> None: 116 | """ 117 | Indexed write into ``self``; called as ``a[index] = value`` where ``a`` is an ``array``, 118 | ``index`` is an ``int``, and ``value`` is the same type as ``a``'s content. 119 | Negative indices count from end and ``IndexError``is thrown if the index out of range. 120 | 121 | **Note:** ``__setitem__`` cannot be called directly (``a.__setitem__(index, value)`` fails) and 122 | is not present in ``__dict__``, however ``a[index] = value`` does work. 123 | """ 124 | @overload 125 | def __setitem__(self, sl: slice, values: array[_T]) -> None: 126 | """ 127 | Indexed write into ``self``; called as ``a[sl] = values``, where ``a`` is an ``array``, 128 | ``sl`` is an ``slice``, and ``values`` is the same type as ``a``. 129 | Negative indices count from end and ``IndexError``is thrown if any of the slice indices are out of range. 130 | **Note:** ``__setitem__`` cannot be called directly (``a.__setitem__(index, value)`` fails) and 131 | is not present in ``__dict__``, however ``a[index] = value`` does work. 132 | """ 133 | def __len__(self) -> int: 134 | """ 135 | Returns the number of items in ``self``; called as ``len(a)``, where ``a`` is an ``array``. 136 | **Note:** ``__len__`` cannot be called directly (``a.__len__()`` fails) and the 137 | method is not present in ``__dict__``, however ``len(a)`` does work. 138 | """ 139 | def __add__(self, other: array[_T]) -> array[_T]: 140 | """ 141 | Return a new ``array`` that is the concatenation of ``self`` with ``other``; 142 | called as ``a + other`` (where ``a`` and ``other`` are both ``array``s). 143 | **Note:** ``__add__`` cannot be called directly (``a.__add__(other)`` fails) and 144 | is not present in ``__dict__``, however ``a + other`` does work. 145 | """ 146 | def __iadd__(self, other: array[_T]) -> None: 147 | """ 148 | Concatenates ``self`` with ``other`` in-place; 149 | called as ``a += other``, where ``a`` and ``other`` are both ``array``s. 150 | Equivalent to ``extend(other)``. 151 | **Note:** ``__iadd__`` cannot be called directly (``a.__iadd__(other)`` fails) and 152 | is not present in ``__dict__``, however ``a += other`` does work. 153 | """ 154 | def __repr__(self) -> str: 155 | """ 156 | Returns the string representation of ``self``; called as ``str(a)`` or ``repr(a)```, 157 | where ``a`` is an ``array``. 158 | Returns the string 'array(, [])', 159 | where ```` is the type code letter for ``self`` and ```` is a 160 | comma separated list of the elements of ``self``. 161 | **Note:** ``__repr__`` cannot be called directly (``a.__repr__()`` fails) and 162 | is not present in ``__dict__``, however ``str(a)`` and ``repr(a)`` both work. 163 | """ 164 | -------------------------------------------------------------------------------- /micropython_typesheds/binascii.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | binary/ASCII conversions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/binascii.rst. 6 | =========================================== 7 | 8 | .. module:: binascii 9 | :synopsis: binary/ASCII conversions 10 | 11 | |see_cpython_module| :mod:`python:binascii`. 12 | 13 | This module implements conversions between binary data and various 14 | encodings of it in ASCII form (in both directions). 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | def hexlify(data: bytes, sep: str | bytes = ..., /) -> bytes: 23 | """ 24 | Convert the bytes in the *data* object to a hexadecimal representation. 25 | Returns a bytes object. 26 | 27 | If the additional argument *sep* is supplied it is used as a separator 28 | between hexadecimal values. 29 | """ 30 | 31 | def unhexlify(data: str | bytes, /) -> bytes: 32 | """ 33 | Convert hexadecimal data to binary representation. Returns bytes string. 34 | (i.e. inverse of hexlify) 35 | """ 36 | 37 | def a2b_base64(data: str | bytes, /) -> bytes: 38 | """ 39 | Decode base64-encoded data, ignoring invalid characters in the input. 40 | Conforms to `RFC 2045 s.6.8 `_. 41 | Returns a bytes object. 42 | """ 43 | 44 | def b2a_base64(data: bytes, /) -> bytes: 45 | """ 46 | Encode binary data in base64 format, as in `RFC 3548 47 | `_. Returns the encoded data 48 | followed by a newline character, as a bytes object. 49 | """ 50 | -------------------------------------------------------------------------------- /micropython_typesheds/btree.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | simple BTree database. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/btree.rst. 6 | ===================================== 7 | 8 | .. module:: btree 9 | :synopsis: simple BTree database 10 | 11 | The ``btree`` module implements a simple key-value database using external 12 | storage (disk files, or in general case, a random-access `stream`). Keys are 13 | stored sorted in the database, and besides efficient retrieval by a key 14 | value, a database also supports efficient ordered range scans (retrieval 15 | of values with the keys in a given range). On the application interface 16 | side, BTree database work as close a possible to a way standard `dict` 17 | type works, one notable difference is that both keys and values must 18 | be `bytes` objects (so, if you want to store objects of other types, you 19 | need to serialize them to `bytes` first). 20 | 21 | The module is based on the well-known BerkelyDB library, version 1.xx. 22 | 23 | Example:: 24 | 25 | import btree 26 | 27 | # First, we need to open a stream which holds a database 28 | # This is usually a file, but can be in-memory database 29 | # using io.BytesIO, a raw flash partition, etc. 30 | # Oftentimes, you want to create a database file if it doesn't 31 | # exist and open if it exists. Idiom below takes care of this. 32 | # DO NOT open database with "a+b" access mode. 33 | try: 34 | f = open("mydb", "r+b") 35 | except OSError: 36 | f = open("mydb", "w+b") 37 | 38 | # Now open a database itself 39 | db = btree.open(f) 40 | 41 | # The keys you add will be sorted internally in the database 42 | db[b"3"] = b"three" 43 | db[b"1"] = b"one" 44 | db[b"2"] = b"two" 45 | 46 | # Assume that any changes are cached in memory unless 47 | # explicitly flushed (or database closed). Flush database 48 | # at the end of each "transaction". 49 | db.flush() 50 | 51 | # Prints b'two' 52 | print(db[b"2"]) 53 | 54 | # Iterate over sorted keys in the database, starting from b"2" 55 | # until the end of the database, returning only values. 56 | # Mind that arguments passed to values() method are *key* values. 57 | # Prints: 58 | # b'two' 59 | # b'three' 60 | for word in db.values(b"2"): 61 | print(word) 62 | 63 | del db[b"2"] 64 | 65 | # No longer true, prints False 66 | print(b"2" in db) 67 | 68 | # Prints: 69 | # b"1" 70 | # b"3" 71 | for key in db: 72 | print(key) 73 | 74 | db.close() 75 | 76 | # Don't forget to close the underlying stream! 77 | f.close() 78 | """ 79 | 80 | __author__ = "Howard C Lovatt" 81 | __copyright__ = "Howard C Lovatt, 2020 onwards." 82 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 83 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 84 | 85 | from typing import Any, Final, Iterable 86 | 87 | from uio import IOBase 88 | 89 | def open( 90 | stream: IOBase[bytes, Any], 91 | /, 92 | *, 93 | flags: int = 0, 94 | pagesize: int = 0, 95 | cachesize: int = 0, 96 | minkeypage: int = 0, 97 | ) -> _BTree: 98 | """ 99 | Open a database from a random-access `stream` (like an open file). All 100 | other parameters are optional and keyword-only, and allow to tweak advanced 101 | parameters of the database operation (most users will not need them): 102 | 103 | * *flags* - Currently unused. 104 | * *pagesize* - Page size used for the nodes in BTree. Acceptable range 105 | is 512-65536. If 0, a port-specific default will be used, optimized for 106 | port's memory usage and/or performance. 107 | * *cachesize* - Suggested memory cache size in bytes. For a 108 | board with enough memory using larger values may improve performance. 109 | Cache policy is as follows: entire cache is not allocated at once; 110 | instead, accessing a new page in database will allocate a memory buffer 111 | for it, until value specified by *cachesize* is reached. Then, these 112 | buffers will be managed using LRU (least recently used) policy. More 113 | buffers may still be allocated if needed (e.g., if a database contains 114 | big keys and/or values). Allocated cache buffers aren't reclaimed. 115 | * *minkeypage* - Minimum number of keys to store per page. Default value 116 | of 0 equivalent to 2. 117 | 118 | Returns a BTree object, which implements a dictionary protocol (set 119 | of methods), and some additional methods described below. 120 | """ 121 | 122 | INCL: Final[int] = ... 123 | """ 124 | A flag for `keys()`, `values()`, `items()` methods to specify that 125 | scanning should be inclusive of the end key. 126 | """ 127 | 128 | DESC: Final[int] = ... 129 | """ 130 | A flag for `keys()`, `values()`, `items()` methods to specify that 131 | scanning should be in descending direction of keys. 132 | """ 133 | 134 | class _BTree: 135 | """ 136 | 137 | """ 138 | 139 | def close(self) -> None: 140 | """ 141 | Close the database. It's mandatory to close the database at the end of 142 | processing, as some unwritten data may be still in the cache. Note that 143 | this does not close underlying stream with which the database was opened, 144 | it should be closed separately (which is also mandatory to make sure that 145 | data flushed from buffer to the underlying storage). 146 | """ 147 | def flush(self) -> None: 148 | """ 149 | Flush any data in cache to the underlying stream. 150 | """ 151 | def __getitem__(self, key: bytes, /) -> bytes: 152 | """ 153 | Standard dictionary methods. 154 | """ 155 | def get(self, key: bytes, default: bytes | None = None, /) -> bytes | None: 156 | """ 157 | Standard dictionary methods. 158 | """ 159 | def __setitem__(self, key: bytes, val: bytes, /) -> None: 160 | """ 161 | Standard dictionary methods. 162 | """ 163 | def __delitem__(self, key: bytes, /) -> None: 164 | """ 165 | Standard dictionary methods. 166 | """ 167 | def __contains__(self, key: bytes, /) -> bool: 168 | """ 169 | Standard dictionary methods. 170 | """ 171 | def __iter__(self) -> Iterable[bytes]: 172 | """ 173 | A BTree object can be iterated over directly (similar to a dictionary) 174 | to get access to all keys in order. 175 | """ 176 | def keys( 177 | self, 178 | start_key: bytes | None = None, 179 | end_key: bytes | None = None, 180 | flags: int = 0, 181 | /, 182 | ) -> Iterable[bytes]: 183 | """ 184 | These methods are similar to standard dictionary methods, but also can 185 | take optional parameters to iterate over a key sub-range, instead of 186 | the entire database. Note that for all 3 methods, *start_key* and 187 | *end_key* arguments represent key values. For example, `values()` 188 | method will iterate over values corresponding to they key range 189 | given. None values for *start_key* means "from the first key", no 190 | *end_key* or its value of None means "until the end of database". 191 | By default, range is inclusive of *start_key* and exclusive of 192 | *end_key*, you can include *end_key* in iteration by passing *flags* 193 | of `btree.INCL`. You can iterate in descending key direction 194 | by passing *flags* of `btree.DESC`. The flags values can be ORed 195 | together. 196 | """ 197 | def values( 198 | self, 199 | start_key: bytes | None = None, 200 | end_key: bytes | None = None, 201 | flags: int = 0, 202 | /, 203 | ) -> Iterable[bytes]: 204 | """ 205 | These methods are similar to standard dictionary methods, but also can 206 | take optional parameters to iterate over a key sub-range, instead of 207 | the entire database. Note that for all 3 methods, *start_key* and 208 | *end_key* arguments represent key values. For example, `values()` 209 | method will iterate over values corresponding to they key range 210 | given. None values for *start_key* means "from the first key", no 211 | *end_key* or its value of None means "until the end of database". 212 | By default, range is inclusive of *start_key* and exclusive of 213 | *end_key*, you can include *end_key* in iteration by passing *flags* 214 | of `btree.INCL`. You can iterate in descending key direction 215 | by passing *flags* of `btree.DESC`. The flags values can be ORed 216 | together. 217 | """ 218 | def items( 219 | self, 220 | start_key: bytes | None = None, 221 | end_key: bytes | None = None, 222 | flags: int = 0, 223 | /, 224 | ) -> Iterable[tuple[bytes, bytes]]: 225 | """ 226 | These methods are similar to standard dictionary methods, but also can 227 | take optional parameters to iterate over a key sub-range, instead of 228 | the entire database. Note that for all 3 methods, *start_key* and 229 | *end_key* arguments represent key values. For example, `values()` 230 | method will iterate over values corresponding to they key range 231 | given. None values for *start_key* means "from the first key", no 232 | *end_key* or its value of None means "until the end of database". 233 | By default, range is inclusive of *start_key* and exclusive of 234 | *end_key*, you can include *end_key* in iteration by passing *flags* 235 | of `btree.INCL`. You can iterate in descending key direction 236 | by passing *flags* of `btree.DESC`. The flags values can be ORed 237 | together. 238 | """ 239 | -------------------------------------------------------------------------------- /micropython_typesheds/cmath.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | mathematical functions for complex numbers. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/cmath.rst. 6 | ========================================================== 7 | 8 | .. module:: cmath 9 | :synopsis: mathematical functions for complex numbers 10 | 11 | |see_cpython_module| :mod:`python:cmath`. 12 | 13 | The ``cmath`` module provides some basic mathematical functions for 14 | working with complex numbers. 15 | 16 | Availability: not available on WiPy and ESP8266. Floating point support 17 | required for this module. 18 | """ 19 | 20 | __author__ = "Howard C Lovatt" 21 | __copyright__ = "Howard C Lovatt, 2020 onwards." 22 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 23 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 24 | 25 | from typing import SupportsComplex, SupportsFloat, Final 26 | 27 | _C: Final = SupportsFloat | SupportsComplex 28 | 29 | def cos(z: _C, /) -> complex: 30 | """ 31 | Return the cosine of ``z``. 32 | """ 33 | 34 | def exp(z: _C, /) -> complex: 35 | """ 36 | Return the exponential of ``z``. 37 | """ 38 | 39 | def log(z: _C, /) -> complex: 40 | """ 41 | Return the natural logarithm of ``z``. The branch cut is along the negative real axis. 42 | """ 43 | 44 | def log10(z: _C, /) -> complex: 45 | """ 46 | Return the base-10 logarithm of ``z``. The branch cut is along the negative real axis. 47 | """ 48 | 49 | def phase(z: _C, /) -> float: 50 | """ 51 | Returns the phase of the number ``z``, in the range (-pi, +pi]. 52 | """ 53 | 54 | def polar(z: _C, /) -> tuple[float, float]: 55 | """ 56 | Returns, as a tuple, the polar form of ``z``. 57 | """ 58 | 59 | def rect(r: float, phi: float, /) -> complex: 60 | """ 61 | Returns the complex number with modulus ``r`` and phase ``phi``. 62 | """ 63 | 64 | def sin(z: _C, /) -> complex: 65 | """ 66 | Return the sine of ``z``. 67 | """ 68 | 69 | def sqrt(z: _C, /) -> complex: 70 | """ 71 | Return the square-root of ``z``. 72 | """ 73 | 74 | e: Final[float] = ... 75 | """ 76 | base of the natural logarithm 77 | """ 78 | 79 | pi: Final[float] = ... 80 | """ 81 | the ratio of a circle's circumference to its diameter 82 | """ 83 | -------------------------------------------------------------------------------- /micropython_typesheds/collections.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | collection and container types. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/collections.rst. 6 | ==================================================== 7 | 8 | .. module:: collections 9 | :synopsis: collection and container types 10 | 11 | |see_cpython_module| :mod:`python:collections`. 12 | 13 | This module implements advanced collection and container types to 14 | hold/accumulate various objects. 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import overload, Any, Type, Iterable, TypeVar, Generic, Mapping, Dict, Final 23 | 24 | _KT: Final = TypeVar("_KT") 25 | _VT: Final = TypeVar("_VT") 26 | 27 | def namedtuple(name: str, fields: str | Iterable[str]) -> Type[tuple[Any, ...]]: 28 | """ 29 | This is factory function to create a new namedtuple type with a specific 30 | name and set of fields. A namedtuple is a subclass of tuple which allows 31 | to access its fields not just by numeric index, but also with an attribute 32 | access syntax using symbolic field names. Fields is a sequence of strings 33 | specifying field names. For compatibility with CPython it can also be a 34 | a string with space-separated field named (but this is less efficient). 35 | Example of use:: 36 | 37 | from collections import namedtuple 38 | 39 | MyTuple = namedtuple("MyTuple", ("id", "name")) 40 | t1 = MyTuple(1, "foo") 41 | t2 = MyTuple(2, "bar") 42 | print(t1.name) 43 | assert t2.name == t2[1] 44 | """ 45 | 46 | # noinspection PyPep8Naming 47 | class deque: 48 | """ 49 | Minimal implementation of a deque that implements a FIFO buffer. 50 | """ 51 | 52 | def __init__(self, iterable: tuple[Any], maxlen: int, flags: int = 0, /): 53 | """ 54 | Deques (double-ended queues) are a list-like container that support O(1) 55 | appends and pops from either side of the deque. New deques are created 56 | using the following arguments: 57 | 58 | - *iterable* must be the empty tuple, and the new deque is created empty. 59 | 60 | - *maxlen* must be specified and the deque will be bounded to this 61 | maximum length. Once the deque is full, any new items added will 62 | discard items from the opposite end. 63 | 64 | - The optional *flags* can be 1 to check for overflow when adding items. 65 | """ 66 | def __bool__(self) -> bool: 67 | """ 68 | Returns true if the `deque` isn't empty. 69 | 70 | **Note:** The method isn't listed by ``dir(deque)`` and can't be called directly, 71 | however ``bool(deque)`` and automatic conversion work! 72 | """ 73 | def __len__(self) -> int: 74 | """ 75 | Returns the number of items in the `deque`. 76 | 77 | **Note:** The method isn't listed by ``dir(deque)`` and can't be called directly, 78 | however ``len(deque)`` works! 79 | """ 80 | def append(self, x: Any, /) -> None: 81 | """ 82 | Add *x* to the right side of the deque. 83 | Raises IndexError if overflow checking is enabled and there is no more room left. 84 | """ 85 | def popleft(self) -> Any: 86 | """ 87 | Remove and return an item from the left side of the deque. 88 | Raises IndexError if no items are present. 89 | """ 90 | 91 | class OrderedDict(Dict[_KT, _VT], Generic[_KT, _VT]): 92 | """ 93 | W 94 | h 95 | e 96 | n 97 | 98 | o 99 | r 100 | d 101 | e 102 | r 103 | e 104 | d 105 | 106 | d 107 | i 108 | c 109 | t 110 | 111 | i 112 | s 113 | 114 | i 115 | t 116 | e 117 | r 118 | a 119 | t 120 | e 121 | d 122 | 123 | o 124 | v 125 | e 126 | r 127 | , 128 | 129 | k 130 | e 131 | y 132 | s 133 | / 134 | i 135 | t 136 | e 137 | m 138 | s 139 | 140 | a 141 | r 142 | e 143 | 144 | r 145 | e 146 | t 147 | u 148 | r 149 | n 150 | e 151 | d 152 | 153 | i 154 | n 155 | 156 | t 157 | h 158 | e 159 | 160 | o 161 | r 162 | d 163 | e 164 | r 165 | 166 | t 167 | h 168 | e 169 | y 170 | 171 | w 172 | e 173 | r 174 | e 175 | 176 | a 177 | d 178 | d 179 | e 180 | d 181 | . 182 | """ 183 | 184 | @overload 185 | def __init__(self): 186 | """ 187 | ``dict`` type subclass which remembers and preserves the order of keys 188 | added. When ordered dict is iterated over, keys/items are returned in 189 | the order they were added:: 190 | 191 | from collections import OrderedDict 192 | 193 | # To make benefit of ordered keys, OrderedDict should be initialized 194 | # from sequence of (key, value) pairs. 195 | d = OrderedDict([("z", 1), ("a", 2)]) 196 | # More items can be added as usual 197 | d["w"] = 5 198 | d["b"] = 3 199 | for k, v in d.items(): 200 | print(k, v) 201 | 202 | Output:: 203 | 204 | z 1 205 | a 2 206 | w 5 207 | b 3 208 | """ 209 | @overload 210 | def __init__(self, **kwargs: _VT): 211 | """ 212 | ``dict`` type subclass which remembers and preserves the order of keys 213 | added. When ordered dict is iterated over, keys/items are returned in 214 | the order they were added:: 215 | 216 | from collections import OrderedDict 217 | 218 | # To make benefit of ordered keys, OrderedDict should be initialized 219 | # from sequence of (key, value) pairs. 220 | d = OrderedDict([("z", 1), ("a", 2)]) 221 | # More items can be added as usual 222 | d["w"] = 5 223 | d["b"] = 3 224 | for k, v in d.items(): 225 | print(k, v) 226 | 227 | Output:: 228 | 229 | z 1 230 | a 2 231 | w 5 232 | b 3 233 | """ 234 | @overload 235 | def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT): 236 | """ 237 | ``dict`` type subclass which remembers and preserves the order of keys 238 | added. When ordered dict is iterated over, keys/items are returned in 239 | the order they were added:: 240 | 241 | from collections import OrderedDict 242 | 243 | # To make benefit of ordered keys, OrderedDict should be initialized 244 | # from sequence of (key, value) pairs. 245 | d = OrderedDict([("z", 1), ("a", 2)]) 246 | # More items can be added as usual 247 | d["w"] = 5 248 | d["b"] = 3 249 | for k, v in d.items(): 250 | print(k, v) 251 | 252 | Output:: 253 | 254 | z 1 255 | a 2 256 | w 5 257 | b 3 258 | """ 259 | -------------------------------------------------------------------------------- /micropython_typesheds/cryptolib.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | cryptographic ciphers. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/cryptolib.rst. 6 | ========================================= 7 | 8 | .. module:: cryptolib 9 | :synopsis: cryptographic ciphers 10 | """ 11 | 12 | __author__ = "Howard C Lovatt" 13 | __copyright__ = "Howard C Lovatt, 2020 onwards." 14 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 15 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 16 | 17 | from typing import overload 18 | 19 | from uio import AnyReadableBuf, AnyWritableBuf 20 | 21 | # noinspection PyPep8Naming 22 | class aes: 23 | """ 24 | .. class:: aes 25 | """ 26 | 27 | @overload 28 | def __init__(self, key: AnyReadableBuf, mode: int, /): 29 | """ 30 | Initialize cipher object, suitable for encryption/decryption. Note: 31 | after initialization, cipher object can be use only either for 32 | encryption or decryption. Running decrypt() operation after encrypt() 33 | or vice versa is not supported. 34 | 35 | Parameters are: 36 | 37 | * *key* is an encryption/decryption key (bytes-like). 38 | * *mode* is: 39 | 40 | * ``1`` (or ``cryptolib.MODE_ECB`` if it exists) for Electronic Code Book (ECB). 41 | * ``2`` (or ``cryptolib.MODE_CBC`` if it exists) for Cipher Block Chaining (CBC). 42 | * ``6`` (or ``cryptolib.MODE_CTR`` if it exists) for Counter mode (CTR). 43 | 44 | * *IV* is an initialization vector for CBC mode. 45 | * For Counter mode, *IV* is the initial value for the counter. 46 | """ 47 | @overload 48 | def __init__(self, key: AnyReadableBuf, mode: int, IV: AnyReadableBuf, /): 49 | """ 50 | Initialize cipher object, suitable for encryption/decryption. Note: 51 | after initialization, cipher object can be use only either for 52 | encryption or decryption. Running decrypt() operation after encrypt() 53 | or vice versa is not supported. 54 | 55 | Parameters are: 56 | 57 | * *key* is an encryption/decryption key (bytes-like). 58 | * *mode* is: 59 | 60 | * ``1`` (or ``cryptolib.MODE_ECB`` if it exists) for Electronic Code Book (ECB). 61 | * ``2`` (or ``cryptolib.MODE_CBC`` if it exists) for Cipher Block Chaining (CBC). 62 | * ``6`` (or ``cryptolib.MODE_CTR`` if it exists) for Counter mode (CTR). 63 | 64 | * *IV* is an initialization vector for CBC mode. 65 | * For Counter mode, *IV* is the initial value for the counter. 66 | """ 67 | @overload 68 | def encrypt(self, in_buf: AnyReadableBuf, /) -> bytes: 69 | """ 70 | Encrypt *in_buf*. If no *out_buf* is given result is returned as a 71 | newly allocated `bytes` object. Otherwise, result is written into 72 | mutable buffer *out_buf*. *in_buf* and *out_buf* can also refer 73 | to the same mutable buffer, in which case data is encrypted in-place. 74 | """ 75 | @overload 76 | def encrypt(self, in_buf: AnyReadableBuf, out_buf: AnyWritableBuf, /) -> None: 77 | """ 78 | Encrypt *in_buf*. If no *out_buf* is given result is returned as a 79 | newly allocated `bytes` object. Otherwise, result is written into 80 | mutable buffer *out_buf*. *in_buf* and *out_buf* can also refer 81 | to the same mutable buffer, in which case data is encrypted in-place. 82 | """ 83 | @overload 84 | def decrypt(self, in_buf: AnyReadableBuf, /) -> bytes: 85 | """ 86 | Like `encrypt()`, but for decryption. 87 | """ 88 | @overload 89 | def decrypt(self, in_buf: AnyReadableBuf, out_buf: AnyWritableBuf, /) -> None: 90 | """ 91 | Like `encrypt()`, but for decryption. 92 | """ 93 | -------------------------------------------------------------------------------- /micropython_typesheds/errno.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | system error codes. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/errno.rst. 6 | ================================== 7 | 8 | .. module:: errno 9 | :synopsis: system error codes 10 | 11 | |see_cpython_module| :mod:`python:errno`. 12 | 13 | This module provides access to symbolic error codes for `OSError` exception. 14 | A particular inventory of codes depends on :term:`MicroPython port`. 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import Final, Dict 23 | 24 | EEXIST: Final[int] = ... 25 | """ 26 | Error codes, based on ANSI C/POSIX standard. All error codes start with 27 | "E". As mentioned above, inventory of the codes depends on 28 | :term:`MicroPython port`. Errors are usually accessible as ``exc.errno`` 29 | where ``exc`` is an instance of `OSError`. Usage example:: 30 | 31 | try: 32 | os.mkdir("my_dir") 33 | except OSError as exc: 34 | if exc.errno == errno.EEXIST: 35 | print("Directory already exists") 36 | """ 37 | 38 | EAGAIN: Final[int] = ... 39 | """ 40 | Error codes, based on ANSI C/POSIX standard. All error codes start with 41 | "E". As mentioned above, inventory of the codes depends on 42 | :term:`MicroPython port`. Errors are usually accessible as ``exc.errno`` 43 | where ``exc`` is an instance of `OSError`. Usage example:: 44 | 45 | try: 46 | os.mkdir("my_dir") 47 | except OSError as exc: 48 | if exc.errno == errno.EEXIST: 49 | print("Directory already exists") 50 | """ 51 | 52 | errorcode: Final[Dict[int, str]] = ... 53 | """ 54 | Dictionary mapping numeric error codes to strings with symbolic error 55 | code (see above):: 56 | 57 | >>> print(errno.errorcode[errno.EEXIST]) 58 | EEXIST 59 | """ 60 | -------------------------------------------------------------------------------- /micropython_typesheds/esp.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | functions related to the ESP8266 and ESP32. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/esp.rst. 6 | ========================================================= 7 | 8 | .. module:: esp 9 | :synopsis: functions related to the ESP8266 and ESP32 10 | 11 | The ``esp`` module contains specific functions related to both the ESP8266 and 12 | ESP32 modules. Some functions are only available on one or the other of these 13 | ports. 14 | """ 15 | 16 | __author__ = "Howard C Lovatt" 17 | __copyright__ = "Howard C Lovatt, 2020 onwards." 18 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 19 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 20 | 21 | from typing import Final, overload 22 | 23 | from uio import AnyWritableBuf, AnyReadableBuf 24 | 25 | SLEEP_NONE: Final[int] = ... 26 | """All functions enabled.""" 27 | 28 | SLEEP_MODEM: Final[int] = ... 29 | """Modem sleep, shuts down the WiFi Modem circuit.""" 30 | 31 | SLEEP_LIGHT: Final[int] = ... 32 | """Light sleep, shuts down the WiFi Modem circuit.""" 33 | 34 | # noinspection PyShadowingNames 35 | @overload 36 | def sleep_type(sleep_type: int, /) -> None: 37 | """ 38 | **Note**: ESP8266 only 39 | 40 | Get or set the sleep type. 41 | 42 | If the *sleep_type* parameter is provided, sets the sleep type to its 43 | value. If the function is called without parameters, returns the current 44 | sleep type. 45 | 46 | The possible sleep types are defined as constants: 47 | 48 | * ``SLEEP_NONE`` -- all functions enabled, 49 | * ``SLEEP_MODEM`` -- modem sleep, shuts down the WiFi Modem circuit. 50 | * ``SLEEP_LIGHT`` -- light sleep, shuts down the WiFi Modem circuit 51 | and suspends the processor periodically. 52 | 53 | The system enters the set sleep mode automatically when possible. 54 | """ 55 | 56 | # noinspection PyShadowingNames 57 | @overload 58 | def sleep_type() -> int: 59 | """ 60 | **Note**: ESP8266 only 61 | 62 | Get or set the sleep type. 63 | 64 | If the *sleep_type* parameter is provided, sets the sleep type to its 65 | value. If the function is called without parameters, returns the current 66 | sleep type. 67 | 68 | The possible sleep types are defined as constants: 69 | 70 | * ``SLEEP_NONE`` -- all functions enabled, 71 | * ``SLEEP_MODEM`` -- modem sleep, shuts down the WiFi Modem circuit. 72 | * ``SLEEP_LIGHT`` -- light sleep, shuts down the WiFi Modem circuit 73 | and suspends the processor periodically. 74 | 75 | The system enters the set sleep mode automatically when possible. 76 | """ 77 | 78 | def deepsleep(time_us: int = 0, /) -> None: 79 | """ 80 | **Note**: ESP8266 only - use `machine.deepsleep()` on ESP32 81 | 82 | Enter deep sleep. 83 | 84 | The whole module powers down, except for the RTC clock circuit, which can 85 | be used to restart the module after the specified time if the pin 16 is 86 | connected to the reset pin. Otherwise the module will sleep until manually 87 | reset. 88 | """ 89 | 90 | def flash_id() -> int: 91 | """ 92 | **Note**: ESP8266 only 93 | 94 | Read the device ID of the flash memory. 95 | """ 96 | 97 | def flash_size() -> int: 98 | """ 99 | Read the total size of the flash memory. 100 | """ 101 | 102 | def flash_user_start() -> int: 103 | """ 104 | Read the memory offset at which the user flash space begins. 105 | """ 106 | 107 | @overload 108 | def flash_read(byte_offset: int, length_or_buffer: int, /) -> bytes: 109 | """ 110 | Reads bytes from the flash memory starting at the given byte offset. 111 | If length is specified: reads the given length of bytes and returns them as ``bytes``. 112 | If a buffer is given: reads the buf length of bytes and writes them into the buffer. 113 | Note: esp32 doesn't support passing a length, just a buffer. 114 | """ 115 | 116 | @overload 117 | def flash_read(byte_offset: int, length_or_buffer: AnyWritableBuf, /) -> None: 118 | """ 119 | Reads bytes from the flash memory starting at the given byte offset. 120 | If length is specified: reads the given length of bytes and returns them as ``bytes``. 121 | If a buffer is given: reads the buf length of bytes and writes them into the buffer. 122 | Note: esp32 doesn't support passing a length, just a buffer. 123 | """ 124 | 125 | def flash_write(byte_offset: int, bytes: AnyReadableBuf, /) -> None: 126 | """ 127 | Writes given bytes buffer to the flash memory starting at the given byte offset. 128 | """ 129 | 130 | def flash_erase(sector_no: int, /) -> None: 131 | """ 132 | Erases the given *sector* of flash memory. 133 | """ 134 | 135 | @overload 136 | def set_native_code_location(start: None, length: None, /) -> None: 137 | """ 138 | **Note**: ESP8266 only 139 | 140 | Set the location that native code will be placed for execution after it is 141 | compiled. Native code is emitted when the ``@micropython.native``, 142 | ``@micropython.viper`` and ``@micropython.asm_xtensa`` decorators are applied 143 | to a function. The ESP8266 must execute code from either iRAM or the lower 144 | 1MByte of flash (which is memory mapped), and this function controls the 145 | location. 146 | 147 | If *start* and *length* are both ``None`` then the native code location is 148 | set to the unused portion of memory at the end of the iRAM1 region. The 149 | size of this unused portion depends on the firmware and is typically quite 150 | small (around 500 bytes), and is enough to store a few very small 151 | functions. The advantage of using this iRAM1 region is that it does not 152 | get worn out by writing to it. 153 | 154 | If neither *start* nor *length* are ``None`` then they should be integers. 155 | *start* should specify the byte offset from the beginning of the flash at 156 | which native code should be stored. *length* specifies how many bytes of 157 | flash from *start* can be used to store native code. *start* and *length* 158 | should be multiples of the sector size (being 4096 bytes). The flash will 159 | be automatically erased before writing to it so be sure to use a region of 160 | flash that is not otherwise used, for example by the firmware or the 161 | filesystem. 162 | 163 | When using the flash to store native code *start+length* must be less 164 | than or equal to 1MByte. Note that the flash can be worn out if repeated 165 | erasures (and writes) are made so use this feature sparingly. 166 | In particular, native code needs to be recompiled and rewritten to flash 167 | on each boot (including wake from deepsleep). 168 | 169 | In both cases above, using iRAM1 or flash, if there is no more room left 170 | in the specified region then the use of a native decorator on a function 171 | will lead to `MemoryError` exception being raised during compilation of 172 | that function. 173 | """ 174 | 175 | @overload 176 | def set_native_code_location(start: int, length: int, /) -> None: 177 | """ 178 | **Note**: ESP8266 only 179 | 180 | Set the location that native code will be placed for execution after it is 181 | compiled. Native code is emitted when the ``@micropython.native``, 182 | ``@micropython.viper`` and ``@micropython.asm_xtensa`` decorators are applied 183 | to a function. The ESP8266 must execute code from either iRAM or the lower 184 | 1MByte of flash (which is memory mapped), and this function controls the 185 | location. 186 | 187 | If *start* and *length* are both ``None`` then the native code location is 188 | set to the unused portion of memory at the end of the iRAM1 region. The 189 | size of this unused portion depends on the firmware and is typically quite 190 | small (around 500 bytes), and is enough to store a few very small 191 | functions. The advantage of using this iRAM1 region is that it does not 192 | get worn out by writing to it. 193 | 194 | If neither *start* nor *length* are ``None`` then they should be integers. 195 | *start* should specify the byte offset from the beginning of the flash at 196 | which native code should be stored. *length* specifies how many bytes of 197 | flash from *start* can be used to store native code. *start* and *length* 198 | should be multiples of the sector size (being 4096 bytes). The flash will 199 | be automatically erased before writing to it so be sure to use a region of 200 | flash that is not otherwise used, for example by the firmware or the 201 | filesystem. 202 | 203 | When using the flash to store native code *start+length* must be less 204 | than or equal to 1MByte. Note that the flash can be worn out if repeated 205 | erasures (and writes) are made so use this feature sparingly. 206 | In particular, native code needs to be recompiled and rewritten to flash 207 | on each boot (including wake from deepsleep). 208 | 209 | In both cases above, using iRAM1 or flash, if there is no more room left 210 | in the specified region then the use of a native decorator on a function 211 | will lead to `MemoryError` exception being raised during compilation of 212 | that function. 213 | """ 214 | -------------------------------------------------------------------------------- /micropython_typesheds/framebuf.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | Frame buffer manipulation. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/framebuf.rst. 6 | 7 | This module provides a general frame buffer which can be used to create 8 | bitmap images, which can then be sent to a display. 9 | """ 10 | 11 | __author__ = "Howard C Lovatt" 12 | __copyright__ = "Howard C Lovatt, 2020 onwards." 13 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 14 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 15 | 16 | from typing import overload, Final 17 | 18 | from uio import AnyWritableBuf 19 | 20 | MONO_VLSB: Final[int] = ... 21 | """ 22 | Monochrome (1-bit) color format 23 | This defines a mapping where the bits in a byte are vertically mapped with 24 | bit 0 being nearest the top of the screen. Consequently each byte occupies 25 | 8 vertical pixels. Subsequent bytes appear at successive horizontal 26 | locations until the rightmost edge is reached. Further bytes are rendered 27 | at locations starting at the leftmost edge, 8 pixels lower. 28 | """ 29 | 30 | MONO_HLSB: Final[int] = ... 31 | """ 32 | Monochrome (1-bit) color format 33 | This defines a mapping where the bits in a byte are horizontally mapped. 34 | Each byte occupies 8 horizontal pixels with bit 7 being the leftmost. 35 | Subsequent bytes appear at successive horizontal locations until the 36 | rightmost edge is reached. Further bytes are rendered on the next row, one 37 | pixel lower. 38 | """ 39 | 40 | MONO_HMSB: Final[int] = ... 41 | """ 42 | Monochrome (1-bit) color format 43 | This defines a mapping where the bits in a byte are horizontally mapped. 44 | Each byte occupies 8 horizontal pixels with bit 0 being the leftmost. 45 | Subsequent bytes appear at successive horizontal locations until the 46 | rightmost edge is reached. Further bytes are rendered on the next row, one 47 | pixel lower. 48 | """ 49 | 50 | RGB565: Final[int] = ... 51 | """ 52 | Red Green Blue (16-bit, 5+6+5) color format 53 | """ 54 | 55 | GS2_HMSB: Final[int] = ... 56 | """ 57 | Grayscale (2-bit) color format 58 | """ 59 | 60 | GS4_HMSB: Final[int] = ... 61 | """ 62 | Grayscale (4-bit) color format 63 | """ 64 | 65 | GS8: Final[int] = ... 66 | """ 67 | Grayscale (8-bit) color format 68 | """ 69 | 70 | class FrameBuffer: 71 | """ 72 | The FrameBuffer class provides a pixel buffer which can be drawn upon with 73 | pixels, lines, rectangles, text and even other FrameBuffer's. It is useful 74 | when generating output for displays. 75 | 76 | For example:: 77 | 78 | import framebuf 79 | 80 | # FrameBuffer needs 2 bytes for every RGB565 pixel 81 | fbuf = framebuf.FrameBuffer(bytearray(100 * 10 * 2), 100, 10, framebuf.RGB565) 82 | 83 | fbuf.fill(0) 84 | fbuf.text('MicroPython!', 0, 0, 0xffff) 85 | fbuf.hline(0, 9, 96, 0xffff) 86 | """ 87 | 88 | def __init__( 89 | self, 90 | buffer: AnyWritableBuf, 91 | width: int, 92 | height: int, 93 | format: int, 94 | stride: int = ..., 95 | /, 96 | ): 97 | """ 98 | Construct a FrameBuffer object. The parameters are: 99 | 100 | - *buffer* is an object with a buffer protocol which must be large 101 | enough to contain every pixel defined by the width, height and 102 | format of the FrameBuffer. 103 | - *width* is the width of the FrameBuffer in pixels 104 | - *height* is the height of the FrameBuffer in pixels 105 | - *format* specifies the type of pixel used in the FrameBuffer; 106 | permissible values are listed under Constants below. These set the 107 | number of bits used to encode a color value and the layout of these 108 | bits in *buffer*. 109 | Where a color value c is passed to a method, c is a small integer 110 | with an encoding that is dependent on the format of the FrameBuffer. 111 | - *stride* is the number of pixels between each horizontal line 112 | of pixels in the FrameBuffer. This defaults to *width* but may 113 | need adjustments when implementing a FrameBuffer within another 114 | larger FrameBuffer or screen. The *buffer* size must accommodate 115 | an increased step size. 116 | 117 | One must specify valid *buffer*, *width*, *height*, *format* and 118 | optionally *stride*. Invalid *buffer* size or dimensions may lead to 119 | unexpected errors. 120 | """ 121 | def fill(self, c: int, /) -> None: 122 | """ 123 | Fill the entire FrameBuffer with the specified color. 124 | """ 125 | @overload 126 | def pixel(self, x: int, y: int, /) -> int: 127 | """ 128 | If *c* is not given, get the color value of the specified pixel. 129 | If *c* is given, set the specified pixel to the given color. 130 | """ 131 | @overload 132 | def pixel(self, x: int, y: int, c: int, /) -> None: 133 | """ 134 | If *c* is not given, get the color value of the specified pixel. 135 | If *c* is given, set the specified pixel to the given color. 136 | """ 137 | def hline(self, x: int, y: int, w: int, c: int, /) -> None: 138 | """ 139 | Draw a line from a set of coordinates using the given color and 140 | a thickness of 1 pixel. The `line` method draws the line up to 141 | a second set of coordinates whereas the `hline` and `vline` 142 | methods draw horizontal and vertical lines respectively up to 143 | a given length. 144 | """ 145 | def vline(self, x: int, y: int, h: int, c: int, /) -> None: 146 | """ 147 | Draw a line from a set of coordinates using the given color and 148 | a thickness of 1 pixel. The `line` method draws the line up to 149 | a second set of coordinates whereas the `hline` and `vline` 150 | methods draw horizontal and vertical lines respectively up to 151 | a given length. 152 | """ 153 | def line(self, x1: int, y1: int, x2: int, y2: int, c: int, /) -> None: 154 | """ 155 | Draw a line from a set of coordinates using the given color and 156 | a thickness of 1 pixel. The `line` method draws the line up to 157 | a second set of coordinates whereas the `hline` and `vline` 158 | methods draw horizontal and vertical lines respectively up to 159 | a given length. 160 | """ 161 | def rect(self, x: int, y: int, w: int, h: int, c: int, /) -> None: 162 | """ 163 | Draw a rectangle at the given location, size and color. The `rect` 164 | method draws only a 1 pixel outline whereas the `fill_rect` method 165 | draws both the outline and interior. 166 | """ 167 | def fill_rect(self, x: int, y: int, w: int, h: int, c: int, /) -> None: 168 | """ 169 | Draw a rectangle at the given location, size and color. The `rect` 170 | method draws only a 1 pixel outline whereas the `fill_rect` method 171 | draws both the outline and interior. 172 | """ 173 | def text(self, s: str, x: int, y: int, c: int = 1, /) -> None: 174 | """ 175 | Write text to the FrameBuffer using the the coordinates as the upper-left 176 | corner of the text. The color of the text can be defined by the optional 177 | argument but is otherwise a default value of 1. All characters have 178 | dimensions of 8x8 pixels and there is currently no way to change the font. 179 | """ 180 | def scroll(self, xstep: int, ystep: int, /) -> None: 181 | """ 182 | Shift the contents of the FrameBuffer by the given vector. This may 183 | leave a footprint of the previous colors in the FrameBuffer. 184 | """ 185 | def blit( 186 | self, 187 | fbuf: FrameBuffer, 188 | x: int, 189 | y: int, 190 | key: int = -1, 191 | pallet: FrameBuffer | None = None, 192 | /, 193 | ) -> None: 194 | """ 195 | Draw another FrameBuffer on top of the current one at the given coordinates. 196 | If *key* is specified then it should be a color integer and the 197 | corresponding color will be considered transparent: all pixels with that 198 | color value will not be drawn. 199 | 200 | The *palette* argument enables blitting between FrameBuffers with differing 201 | formats. Typical usage is to render a monochrome or grayscale glyph/icon to 202 | a color display. The *palette* is a FrameBuffer instance whose format is 203 | that of the current FrameBuffer. The *palette* height is one pixel and its 204 | pixel width is the number of colors in the source FrameBuffer. The *palette* 205 | for an N-bit source needs 2**N pixels; the *palette* for a monochrome source 206 | would have 2 pixels representing background and foreground colors. The 207 | application assigns a color to each pixel in the *palette*. The color of the 208 | current pixel will be that of that *palette* pixel whose x position is the 209 | color of the corresponding source pixel. 210 | """ 211 | -------------------------------------------------------------------------------- /micropython_typesheds/gc.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | control the garbage collector. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/gc.rst. 6 | ========================================== 7 | 8 | .. module:: gc 9 | :synopsis: control the garbage collector 10 | 11 | |see_cpython_module| :mod:`python:gc`. 12 | """ 13 | 14 | __author__ = "Howard C Lovatt" 15 | __copyright__ = "Howard C Lovatt, 2020 onwards." 16 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 17 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 18 | 19 | from typing import overload 20 | 21 | def enable() -> None: 22 | """ 23 | Enable automatic garbage collection. 24 | """ 25 | 26 | def disable() -> None: 27 | """ 28 | Disable automatic garbage collection. Heap memory can still be allocated, 29 | and garbage collection can still be initiated manually using :meth:`gc.collect`. 30 | """ 31 | 32 | def collect() -> None: 33 | """ 34 | Run a garbage collection. 35 | """ 36 | 37 | def mem_alloc() -> int: 38 | """ 39 | Return the number of bytes of heap RAM that are allocated. 40 | 41 | .. admonition:: Difference to CPython 42 | :class: attention 43 | 44 | This function is MicroPython extension. 45 | """ 46 | 47 | def mem_free() -> int: 48 | """ 49 | Return the number of bytes of available heap RAM, or -1 if this amount 50 | is not known. 51 | 52 | .. admonition:: Difference to CPython 53 | :class: attention 54 | 55 | This function is MicroPython extension. 56 | """ 57 | 58 | @overload 59 | def threshold() -> int: 60 | """ 61 | Set or query the additional GC allocation threshold. Normally, a collection 62 | is triggered only when a new allocation cannot be satisfied, i.e. on an 63 | out-of-memory (OOM) condition. If this function is called, in addition to 64 | OOM, a collection will be triggered each time after *amount* bytes have been 65 | allocated (in total, since the previous time such an amount of bytes 66 | have been allocated). *amount* is usually specified as less than the 67 | full heap size, with the intention to trigger a collection earlier than when the 68 | heap becomes exhausted, and in the hope that an early collection will prevent 69 | excessive memory fragmentation. This is a heuristic measure, the effect 70 | of which will vary from application to application, as well as 71 | the optimal value of the *amount* parameter. 72 | 73 | Calling the function without argument will return the current value of 74 | the threshold. A value of -1 means a disabled allocation threshold. 75 | 76 | .. admonition:: Difference to CPython 77 | :class: attention 78 | 79 | This function is a MicroPython extension. CPython has a similar 80 | function - ``set_threshold()``, but due to different GC 81 | implementations, its signature and semantics are different. 82 | """ 83 | 84 | @overload 85 | def threshold(amount: int) -> None: 86 | """ 87 | Set or query the additional GC allocation threshold. Normally, a collection 88 | is triggered only when a new allocation cannot be satisfied, i.e. on an 89 | out-of-memory (OOM) condition. If this function is called, in addition to 90 | OOM, a collection will be triggered each time after *amount* bytes have been 91 | allocated (in total, since the previous time such an amount of bytes 92 | have been allocated). *amount* is usually specified as less than the 93 | full heap size, with the intention to trigger a collection earlier than when the 94 | heap becomes exhausted, and in the hope that an early collection will prevent 95 | excessive memory fragmentation. This is a heuristic measure, the effect 96 | of which will vary from application to application, as well as 97 | the optimal value of the *amount* parameter. 98 | 99 | Calling the function without argument will return the current value of 100 | the threshold. A value of -1 means a disabled allocation threshold. 101 | 102 | .. admonition:: Difference to CPython 103 | :class: attention 104 | 105 | This function is a MicroPython extension. CPython has a similar 106 | function - ``set_threshold()``, but due to different GC 107 | implementations, its signature and semantics are different. 108 | """ 109 | -------------------------------------------------------------------------------- /micropython_typesheds/hashlib.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | hashing algorithms. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/hashlib.rst. 6 | ==================================== 7 | 8 | .. module:: hashlib 9 | :synopsis: hashing algorithms 10 | 11 | |see_cpython_module| :mod:`python:hashlib`. 12 | 13 | This module implements binary data hashing algorithms. The exact inventory 14 | of available algorithms depends on a board. Among the algorithms which may 15 | be implemented: 16 | 17 | * SHA256 - The current generation, modern hashing algorithm (of SHA2 series). 18 | It is suitable for cryptographically-secure purposes. Included in the 19 | MicroPython core and any board is recommended to provide this, unless 20 | it has particular code size constraints. 21 | 22 | * SHA1 - A previous generation algorithm. Not recommended for new usages, 23 | but SHA1 is a part of number of Internet standards and existing 24 | applications, so boards targeting network connectivity and 25 | interoperability will try to provide this. 26 | 27 | * MD5 - A legacy algorithm, not considered cryptographically secure. Only 28 | selected boards, targeting interoperability with legacy applications, 29 | will offer this. 30 | """ 31 | 32 | __author__ = "Howard C Lovatt" 33 | __copyright__ = "Howard C Lovatt, 2020 onwards." 34 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 35 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 36 | 37 | from abc import ABC 38 | from typing import overload 39 | 40 | from uio import AnyReadableBuf 41 | 42 | # noinspection PyPep8Naming 43 | class sha256("_Hash"): 44 | """ 45 | The current generation, modern hashing algorithm (of SHA2 series). 46 | It is suitable for cryptographically-secure purposes. Included in the 47 | MicroPython core and any board is recommended to provide this, unless 48 | it has particular code size constraints. 49 | """ 50 | 51 | @overload 52 | def __init__(self): 53 | """ 54 | Create an SHA256 hasher object and optionally feed ``data`` into it. 55 | """ 56 | @overload 57 | def __init__(self, data: AnyReadableBuf): 58 | """ 59 | Create an SHA256 hasher object and optionally feed ``data`` into it. 60 | """ 61 | 62 | # noinspection PyPep8Naming 63 | class sha1("_Hash"): 64 | """ 65 | A previous generation algorithm. Not recommended for new usages, 66 | but SHA1 is a part of number of Internet standards and existing 67 | applications, so boards targeting network connectivity and 68 | interoperability will try to provide this. 69 | """ 70 | 71 | @overload 72 | def __init__(self): 73 | """ 74 | Create an SHA1 hasher object and optionally feed ``data`` into it. 75 | """ 76 | @overload 77 | def __init__(self, data: AnyReadableBuf): 78 | """ 79 | Create an SHA1 hasher object and optionally feed ``data`` into it. 80 | """ 81 | 82 | # noinspection PyPep8Naming 83 | class md5("_Hash"): 84 | """ 85 | A legacy algorithm, not considered cryptographically secure. Only 86 | selected boards, targeting interoperability with legacy applications, 87 | will offer this. 88 | """ 89 | 90 | def __init__(self, data: AnyReadableBuf = ..., /): 91 | """ 92 | Create an MD5 hasher object and optionally feed ``data`` into it. 93 | """ 94 | 95 | class _Hash(ABC): 96 | """ 97 | Abstract base class for hashing algorithms that defines methods available in all algorithms. 98 | """ 99 | 100 | def update(self, data: AnyReadableBuf, /) -> None: 101 | """ 102 | Feed more binary data into hash. 103 | """ 104 | def digest(self) -> bytes: 105 | """ 106 | Return hash for all data passed through hash, as a bytes object. After this 107 | method is called, more data cannot be fed into the hash any longer. 108 | """ 109 | def hexdigest(self) -> str: 110 | """ 111 | This method is NOT implemented. Use ``binascii.hexlify(hash.digest())`` 112 | to achieve a similar effect. 113 | """ 114 | -------------------------------------------------------------------------------- /micropython_typesheds/heapq.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | heap queue algorithm. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/heapq.rst. 6 | ==================================== 7 | 8 | .. module:: heapq 9 | :synopsis: heap queue algorithm 10 | 11 | |see_cpython_module| :mod:`python:heapq`. 12 | 13 | This module implements the 14 | `min heap queue algorithm `_. 15 | 16 | A heap queue is essentially a list that has its elements stored in such a way 17 | that the first item of the list is always the smallest. 18 | """ 19 | 20 | __author__ = "Howard C Lovatt" 21 | __copyright__ = "Howard C Lovatt, 2020 onwards." 22 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 23 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 24 | 25 | from typing import TypeVar, Any, Final 26 | 27 | _T: Final = TypeVar("_T") 28 | 29 | def heappush(heap: list[_T], item: _T, /) -> None: 30 | """ 31 | Push the ``item`` onto the ``heap``. 32 | """ 33 | 34 | def heappop(heap: list[_T], /) -> _T: 35 | """ 36 | Pop the first item from the ``heap``, and return it. Raise ``IndexError`` if 37 | ``heap`` is empty. 38 | 39 | The returned item will be the smallest item in the ``heap``. 40 | """ 41 | 42 | def heapify(x: list[Any], /) -> None: 43 | """ 44 | Convert the list ``x`` into a heap. This is an in-place operation. 45 | """ 46 | -------------------------------------------------------------------------------- /micropython_typesheds/json.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | JSON encoding and decoding. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/json.rst. 6 | ========================================= 7 | 8 | .. module:: json 9 | :synopsis: JSON encoding and decoding 10 | 11 | |see_cpython_module| :mod:`python:json`. 12 | 13 | This modules allows to convert between Python objects and the JSON 14 | data format. 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import Any, AnyStr 23 | 24 | from uio import IOBase 25 | 26 | def dump( 27 | obj: Any, stream: IOBase[str, Any], separators: tuple[str, str] | None = None, / 28 | ) -> None: 29 | """ 30 | Serialise *obj* to a JSON string, writing it to the given *stream*. 31 | 32 | If specified, separators should be an ``(item_separator, key_separator)`` 33 | tuple. The default is ``(', ', ': ')``. To get the most compact JSON 34 | representation, you should specify ``(',', ':')`` to eliminate whitespace. 35 | """ 36 | 37 | def dumps(obj: Any, separators: tuple[str, str] | None = None) -> str: 38 | """ 39 | Return *obj* represented as a JSON string. 40 | 41 | The arguments have the same meaning as in `dump`. 42 | """ 43 | 44 | def load(stream: IOBase[str, Any]) -> Any: 45 | """ 46 | Parse the given *stream*, interpreting it as a JSON string and 47 | deserialising the data to a Python object. The resulting object is 48 | returned. 49 | 50 | Parsing continues until end-of-file is encountered. 51 | A :exc:`ValueError` is raised if the data in *stream* is not correctly formed. 52 | """ 53 | 54 | def loads(str: AnyStr) -> Any: 55 | """ 56 | Parse the JSON *str* and return an object. Raises :exc:`ValueError` if the 57 | string is not correctly formed. 58 | """ 59 | -------------------------------------------------------------------------------- /micropython_typesheds/machine.ADCWiPy.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | class ADCWiPy -- analog to digital conversion. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/machine.ADCWiPy.rst. 6 | ============================================= 7 | 8 | .. note:: 9 | 10 | This class is a non-standard ADC implementation for the WiPy. 11 | It is available simply as ``machine.ADC`` on the WiPy but is named in the 12 | documentation below as ``machine.ADCWiPy`` to distinguish it from the 13 | more general :ref:`machine.ADC ` class. 14 | """ 15 | 16 | __author__ = "Howard C Lovatt" 17 | __copyright__ = "Howard C Lovatt, 2020 onwards." 18 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 19 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 20 | 21 | from typing import overload 22 | 23 | class ADC: 24 | """ 25 | Usage:: 26 | 27 | import machine 28 | 29 | adc = machine.ADC() # create an ADC object 30 | apin = adc.channel(pin='GP3') # create an analog pin on GP3 31 | val = apin() # read an analog value 32 | """ 33 | 34 | def __init__(self, id: int = 0, /, *, bits: int = 12): 35 | """ 36 | Create an ADC object associated with the given pin. 37 | This allows you to then read analog values on that pin. 38 | For more info check the `pinout and alternate functions 39 | table. `_ 40 | 41 | .. warning:: 42 | 43 | ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it 44 | can withstand). When GP2, GP3, GP4 or GP5 are remapped to the 45 | ADC block, 1.8 V is the maximum. If these pins are used in digital mode, 46 | then the maximum allowed input is 3.6V. 47 | """ 48 | @overload 49 | def channel(self, id: int, /) -> ADCChannel: 50 | """ 51 | Create an analog pin. If only channel ID is given, the correct pin will 52 | be selected. Alternatively, only the pin can be passed and the correct 53 | channel will be selected. Examples:: 54 | 55 | # all of these are equivalent and enable ADC channel 1 on GP3 56 | apin = adc.channel(1) 57 | apin = adc.channel(pin='GP3') 58 | apin = adc.channel(id=1, pin='GP3') 59 | """ 60 | @overload 61 | def channel(self, /, *, pin: str) -> ADCChannel: 62 | """ 63 | Create an analog pin. If only channel ID is given, the correct pin will 64 | be selected. Alternatively, only the pin can be passed and the correct 65 | channel will be selected. Examples:: 66 | 67 | # all of these are equivalent and enable ADC channel 1 on GP3 68 | apin = adc.channel(1) 69 | apin = adc.channel(pin='GP3') 70 | apin = adc.channel(id=1, pin='GP3') 71 | """ 72 | @overload 73 | def channel(self, id: int, /, *, pin: str) -> ADCChannel: 74 | """ 75 | Create an analog pin. If only channel ID is given, the correct pin will 76 | be selected. Alternatively, only the pin can be passed and the correct 77 | channel will be selected. Examples:: 78 | 79 | # all of these are equivalent and enable ADC channel 1 on GP3 80 | apin = adc.channel(1) 81 | apin = adc.channel(pin='GP3') 82 | apin = adc.channel(id=1, pin='GP3') 83 | """ 84 | def init(self) -> None: 85 | """ 86 | Enable the ADC block. 87 | """ 88 | def deinit(self) -> None: 89 | """ 90 | Disable the ADC block. 91 | """ 92 | 93 | class ADCChannel: 94 | """ 95 | class ADCChannel --- read analog values from internal or external sources 96 | ========================================================================= 97 | 98 | ADC channels can be connected to internal points of the MCU or to GPIO pins. 99 | ADC channels are created using the ADC.channel method. 100 | """ 101 | 102 | def __call__(self) -> int: 103 | """ 104 | Fast method to read the channel value. 105 | """ 106 | def value(self) -> int: 107 | """ 108 | Read the channel value. 109 | """ 110 | def init(self) -> None: 111 | """ 112 | Re-init (and effectively enable) the ADC channel. 113 | """ 114 | def deinit(self) -> None: 115 | """ 116 | Disable the ADC channel. 117 | """ 118 | -------------------------------------------------------------------------------- /micropython_typesheds/math.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | mathematical functions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/math.rst. 6 | ===================================== 7 | 8 | .. module:: math 9 | :synopsis: mathematical functions 10 | 11 | |see_cpython_module| :mod:`python:math`. 12 | 13 | The ``math`` module provides some basic mathematical functions for 14 | working with floating-point numbers. 15 | 16 | *Note:* On the pyboard, floating-point numbers have 32-bit precision. 17 | 18 | Availability: not available on WiPy. Floating point support required 19 | for this module. 20 | """ 21 | 22 | __author__ = "Howard C Lovatt" 23 | __copyright__ = "Howard C Lovatt, 2020 onwards." 24 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 25 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 26 | 27 | from typing import SupportsFloat, Final 28 | 29 | def acos(x: SupportsFloat, /) -> float: 30 | """ 31 | Return the inverse cosine of ``x``. 32 | """ 33 | 34 | def acosh(x: SupportsFloat, /) -> float: 35 | """ 36 | Return the inverse hyperbolic cosine of ``x``. 37 | """ 38 | 39 | def asin(x: SupportsFloat, /) -> float: 40 | """ 41 | Return the inverse sine of ``x``. 42 | """ 43 | 44 | def asinh(x: SupportsFloat, /) -> float: 45 | """ 46 | Return the inverse hyperbolic sine of ``x``. 47 | """ 48 | 49 | def atan(x: SupportsFloat, /) -> float: 50 | """ 51 | Return the inverse tangent of ``x``. 52 | """ 53 | 54 | def atan2(y: SupportsFloat, x: SupportsFloat, /) -> float: 55 | """ 56 | Return the principal value of the inverse tangent of ``y/x``. 57 | """ 58 | 59 | def atanh(x: SupportsFloat, /) -> float: 60 | """ 61 | Return the inverse hyperbolic tangent of ``x``. 62 | """ 63 | 64 | def ceil(x: SupportsFloat, /) -> int: 65 | """ 66 | Return an integer, being ``x`` rounded towards positive infinity. 67 | """ 68 | 69 | def copysign(x: SupportsFloat, y: SupportsFloat, /) -> float: 70 | """ 71 | Return ``x`` with the sign of ``y``. 72 | """ 73 | 74 | def cos(x: SupportsFloat, /) -> float: 75 | """ 76 | Return the cosine of ``x``. 77 | """ 78 | 79 | def cosh(x: SupportsFloat, /) -> float: 80 | """ 81 | Return the hyperbolic cosine of ``x``. 82 | """ 83 | 84 | def degrees(x: SupportsFloat, /) -> float: 85 | """ 86 | Return radians ``x`` converted to degrees. 87 | """ 88 | 89 | def erf(x: SupportsFloat, /) -> float: 90 | """ 91 | Return the error function of ``x``. 92 | """ 93 | 94 | def erfc(x: SupportsFloat, /) -> float: 95 | """ 96 | Return the complementary error function of ``x``. 97 | """ 98 | 99 | def exp(x: SupportsFloat, /) -> float: 100 | """ 101 | Return the exponential of ``x``. 102 | """ 103 | 104 | def expm1(x: SupportsFloat, /) -> float: 105 | """ 106 | Return ``exp(x) - 1``. 107 | """ 108 | 109 | def fabs(x: SupportsFloat, /) -> float: 110 | """ 111 | Return the absolute value of ``x``. 112 | """ 113 | 114 | def floor(x: SupportsFloat, /) -> int: 115 | """ 116 | Return an integer, being ``x`` rounded towards negative infinity. 117 | """ 118 | 119 | def fmod(x: SupportsFloat, y: SupportsFloat, /) -> float: 120 | """ 121 | Return the remainder of ``x/y``. 122 | """ 123 | 124 | def frexp(x: SupportsFloat, /) -> tuple[float, int]: 125 | """ 126 | Decomposes a floating-point number into its mantissa and exponent. 127 | The returned value is the tuple ``(m, e)`` such that ``x == m * 2**e`` 128 | exactly. If ``x == 0`` then the function returns ``(0.0, 0)``, otherwise 129 | the relation ``0.5 <= abs(m) < 1`` holds. 130 | """ 131 | 132 | def gamma(x: SupportsFloat, /) -> float: 133 | """ 134 | Return the gamma function of ``x``. 135 | """ 136 | 137 | def isfinite(x: SupportsFloat, /) -> bool: 138 | """ 139 | Return ``True`` if ``x`` is finite. 140 | """ 141 | 142 | def isinf(x: SupportsFloat, /) -> bool: 143 | """ 144 | Return ``True`` if ``x`` is infinite. 145 | """ 146 | 147 | def isnan(x: SupportsFloat, /) -> bool: 148 | """ 149 | Return ``True`` if ``x`` is not-a-number 150 | """ 151 | 152 | # noinspection PyShadowingNames 153 | def ldexp(x: SupportsFloat, exp: int, /) -> float: 154 | """ 155 | Return ``x * (2**exp)``. 156 | """ 157 | 158 | def lgamma(x: SupportsFloat, /) -> float: 159 | """ 160 | Return the natural logarithm of the gamma function of ``x``. 161 | """ 162 | 163 | def log(x: SupportsFloat, /) -> float: 164 | """ 165 | Return the natural logarithm of ``x``. 166 | """ 167 | 168 | def log10(x: SupportsFloat, /) -> float: 169 | """ 170 | Return the base-10 logarithm of ``x``. 171 | """ 172 | 173 | def log2(x: SupportsFloat, /) -> float: 174 | """ 175 | Return the base-2 logarithm of ``x``. 176 | """ 177 | 178 | def modf(x: SupportsFloat, /) -> tuple[float, float]: 179 | """ 180 | Return a tuple of two floats, being the fractional and integral parts of 181 | ``x``. Both return values have the same sign as ``x``. 182 | """ 183 | 184 | def pow(x: SupportsFloat, y: SupportsFloat, /) -> float: 185 | """ 186 | Returns ``x`` to the power of ``y``. 187 | """ 188 | 189 | def radians(x: SupportsFloat, /) -> float: 190 | """ 191 | Return degrees ``x`` converted to radians. 192 | """ 193 | 194 | def sin(x: SupportsFloat, /) -> float: 195 | """ 196 | Return the sine of ``x``. 197 | """ 198 | 199 | def sinh(x: SupportsFloat, /) -> float: 200 | """ 201 | Return the hyperbolic sine of ``x``. 202 | """ 203 | 204 | def sqrt(x: SupportsFloat, /) -> float: 205 | """ 206 | Return the square root of ``x``. 207 | """ 208 | 209 | def tan(x: SupportsFloat, /) -> float: 210 | """ 211 | Return the tangent of ``x``. 212 | """ 213 | 214 | def tanh(x: SupportsFloat, /) -> float: 215 | """ 216 | Return the hyperbolic tangent of ``x``. 217 | """ 218 | 219 | def trunc(x: SupportsFloat, /) -> float: 220 | """ 221 | Return an integer, being ``x`` rounded towards 0. 222 | """ 223 | 224 | e: Final[float] = ... 225 | """ 226 | base of the natural logarithm 227 | """ 228 | 229 | pi: Final[float] = ... 230 | """ 231 | the ratio of a circle's circumference to its diameter 232 | """ 233 | -------------------------------------------------------------------------------- /micropython_typesheds/micropython.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | access and control MicroPython internals. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/micropython.rst. 6 | ============================================================== 7 | 8 | .. module:: micropython 9 | :synopsis: access and control MicroPython internals 10 | """ 11 | 12 | __author__ = "Howard C Lovatt" 13 | __copyright__ = "Howard C Lovatt, 2020 onwards." 14 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 15 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 16 | 17 | from typing import TypeVar, overload, Callable, Any, Final 18 | 19 | _T: Final = TypeVar("_T") 20 | _F: Final = TypeVar("_F", bound=Callable[..., Any]) 21 | 22 | def native(func: _F) -> _F: 23 | """ 24 | This causes the MicroPython compiler to emit unoptimised native CPU opcodes 25 | rather than bytecode (normal) or optimised opcodes (viper) and is an optimisation, 26 | for more information see 27 | https://docs.micropython.org/en/latest/reference/speed_python.html#the-native-code-emitter. 28 | """ 29 | 30 | def viper(func: _F) -> _F: 31 | """ 32 | This causes the MicroPython compiler to emit optimised native CPU opcodes based on special typehints 33 | rather than bytecode (normal) or unoptimised opcodes (native) and is an optimisation, 34 | for more information see 35 | https://docs.micropython.org/en/latest/reference/speed_python.html#the-viper-code-emitter. 36 | """ 37 | 38 | def const(expr: _T, /) -> _T: 39 | """ 40 | Used to declare that the expression is a constant so that the compile can 41 | optimise it. The use of this function should be as follows:: 42 | 43 | from micropython import const 44 | 45 | CONST_X = const(123) 46 | CONST_Y = const(2 * CONST_X + 1) 47 | 48 | Constants declared this way are still accessible as global variables from 49 | outside the module they are declared in. On the other hand, if a constant 50 | begins with an underscore then it is hidden, it is not available as a global 51 | variable, and does not take up any memory during execution. 52 | 53 | This `const` function is recognised directly by the MicroPython parser and is 54 | provided as part of the :mod:`micropython` module mainly so that scripts can be 55 | written which run under both CPython and MicroPython, by following the above 56 | pattern. 57 | """ 58 | 59 | @overload 60 | def opt_level() -> int: 61 | """ 62 | If *level* is given then this function sets the optimisation level for subsequent 63 | compilation of scripts, and returns ``None``. Otherwise it returns the current 64 | optimisation level. 65 | 66 | The optimisation level controls the following compilation features: 67 | 68 | - Assertions: at level 0 assertion statements are enabled and compiled into the 69 | bytecode; at levels 1 and higher assertions are not compiled. 70 | - Built-in ``__debug__`` variable: at level 0 this variable expands to ``True``; 71 | at levels 1 and higher it expands to ``False``. 72 | - Source-code line numbers: at levels 0, 1 and 2 source-code line number are 73 | stored along with the bytecode so that exceptions can report the line number 74 | they occurred at; at levels 3 and higher line numbers are not stored. 75 | 76 | The default optimisation level is usually level 0. 77 | """ 78 | 79 | @overload 80 | def opt_level(level: int, /) -> None: 81 | """ 82 | If *level* is given then this function sets the optimisation level for subsequent 83 | compilation of scripts, and returns ``None``. Otherwise it returns the current 84 | optimisation level. 85 | 86 | The optimisation level controls the following compilation features: 87 | 88 | - Assertions: at level 0 assertion statements are enabled and compiled into the 89 | bytecode; at levels 1 and higher assertions are not compiled. 90 | - Built-in ``__debug__`` variable: at level 0 this variable expands to ``True``; 91 | at levels 1 and higher it expands to ``False``. 92 | - Source-code line numbers: at levels 0, 1 and 2 source-code line number are 93 | stored along with the bytecode so that exceptions can report the line number 94 | they occurred at; at levels 3 and higher line numbers are not stored. 95 | 96 | The default optimisation level is usually level 0. 97 | """ 98 | 99 | def alloc_emergency_exception_buf(size: int, /) -> None: 100 | """ 101 | Allocate *size* bytes of RAM for the emergency exception buffer (a good 102 | size is around 100 bytes). The buffer is used to create exceptions in cases 103 | when normal RAM allocation would fail (eg within an interrupt handler) and 104 | therefore give useful traceback information in these situations. 105 | 106 | A good way to use this function is to put it at the start of your main script 107 | (eg ``boot.py`` or ``main.py``) and then the emergency exception buffer will be active 108 | for all the code following it. 109 | """ 110 | 111 | @overload 112 | def mem_info() -> None: 113 | """ 114 | Print information about currently used memory. If the *verbose* argument 115 | is given then extra information is printed. 116 | 117 | The information that is printed is implementation dependent, but currently 118 | includes the amount of stack and heap used. In verbose mode it prints out 119 | the entire heap indicating which blocks are used and which are free. 120 | """ 121 | 122 | @overload 123 | def mem_info(verbose: Any, /) -> None: 124 | """ 125 | Print information about currently used memory. If the *verbose* argument 126 | is given then extra information is printed. 127 | 128 | The information that is printed is implementation dependent, but currently 129 | includes the amount of stack and heap used. In verbose mode it prints out 130 | the entire heap indicating which blocks are used and which are free. 131 | """ 132 | 133 | @overload 134 | def qstr_info() -> None: 135 | """ 136 | Print information about currently interned strings. If the *verbose* 137 | argument is given then extra information is printed. 138 | 139 | The information that is printed is implementation dependent, but currently 140 | includes the number of interned strings and the amount of RAM they use. In 141 | verbose mode it prints out the names of all RAM-interned strings. 142 | """ 143 | 144 | @overload 145 | def qstr_info(verbose: bool, /) -> None: 146 | """ 147 | Print information about currently interned strings. If the *verbose* 148 | argument is given then extra information is printed. 149 | 150 | The information that is printed is implementation dependent, but currently 151 | includes the number of interned strings and the amount of RAM they use. In 152 | verbose mode it prints out the names of all RAM-interned strings. 153 | """ 154 | 155 | def stack_use() -> int: 156 | """ 157 | Return an integer representing the current amount of stack that is being 158 | used. The absolute value of this is not particularly useful, rather it 159 | should be used to compute differences in stack usage at different points. 160 | """ 161 | 162 | def heap_lock() -> None: 163 | """ 164 | Lock or unlock the heap. When locked no memory allocation can occur and a 165 | `MemoryError` will be raised if any heap allocation is attempted. 166 | `heap_locked()` returns a true value if the heap is currently locked. 167 | 168 | These functions can be nested, ie `heap_lock()` can be called multiple times 169 | in a row and the lock-depth will increase, and then `heap_unlock()` must be 170 | called the same number of times to make the heap available again. 171 | 172 | Both `heap_unlock()` and `heap_locked()` return the current lock depth 173 | (after unlocking for the former) as a non-negative integer, with 0 meaning 174 | the heap is not locked. 175 | 176 | If the REPL becomes active with the heap locked then it will be forcefully 177 | unlocked. 178 | 179 | Note: `heap_locked()` is not enabled on most ports by default, 180 | requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``. 181 | """ 182 | 183 | def heap_unlock() -> None: 184 | """ 185 | Lock or unlock the heap. When locked no memory allocation can occur and a 186 | `MemoryError` will be raised if any heap allocation is attempted. 187 | `heap_locked()` returns a true value if the heap is currently locked. 188 | 189 | These functions can be nested, ie `heap_lock()` can be called multiple times 190 | in a row and the lock-depth will increase, and then `heap_unlock()` must be 191 | called the same number of times to make the heap available again. 192 | 193 | Both `heap_unlock()` and `heap_locked()` return the current lock depth 194 | (after unlocking for the former) as a non-negative integer, with 0 meaning 195 | the heap is not locked. 196 | 197 | If the REPL becomes active with the heap locked then it will be forcefully 198 | unlocked. 199 | 200 | Note: `heap_locked()` is not enabled on most ports by default, 201 | requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``. 202 | """ 203 | 204 | def heap_locked() -> bool: 205 | """ 206 | Lock or unlock the heap. When locked no memory allocation can occur and a 207 | `MemoryError` will be raised if any heap allocation is attempted. 208 | `heap_locked()` returns a true value if the heap is currently locked. 209 | 210 | These functions can be nested, ie `heap_lock()` can be called multiple times 211 | in a row and the lock-depth will increase, and then `heap_unlock()` must be 212 | called the same number of times to make the heap available again. 213 | 214 | Both `heap_unlock()` and `heap_locked()` return the current lock depth 215 | (after unlocking for the former) as a non-negative integer, with 0 meaning 216 | the heap is not locked. 217 | 218 | If the REPL becomes active with the heap locked then it will be forcefully 219 | unlocked. 220 | 221 | Note: `heap_locked()` is not enabled on most ports by default, 222 | requires ``MICROPY_PY_MICROPYTHON_HEAP_LOCKED``. 223 | """ 224 | 225 | def kbd_intr(chr: int) -> None: 226 | """ 227 | Set the character that will raise a `KeyboardInterrupt` exception. By 228 | default this is set to 3 during script execution, corresponding to Ctrl-C. 229 | Passing -1 to this function will disable capture of Ctrl-C, and passing 3 230 | will restore it. 231 | 232 | This function can be used to prevent the capturing of Ctrl-C on the 233 | incoming stream of characters that is usually used for the REPL, in case 234 | that stream is used for other purposes. 235 | """ 236 | 237 | def schedule(func: Callable[[_T], None], arg: _T, /) -> None: 238 | """ 239 | Schedule the function *func* to be executed "very soon". The function 240 | is passed the value *arg* as its single argument. "Very soon" means that 241 | the MicroPython runtime will do its best to execute the function at the 242 | earliest possible time, given that it is also trying to be efficient, and 243 | that the following conditions hold: 244 | 245 | - A scheduled function will never preempt another scheduled function. 246 | - Scheduled functions are always executed "between opcodes" which means 247 | that all fundamental Python operations (such as appending to a list) 248 | are guaranteed to be atomic. 249 | - A given port may define "critical regions" within which scheduled 250 | functions will never be executed. Functions may be scheduled within 251 | a critical region but they will not be executed until that region 252 | is exited. An example of a critical region is a preempting interrupt 253 | handler (an IRQ). 254 | 255 | A use for this function is to schedule a callback from a preempting IRQ. 256 | Such an IRQ puts restrictions on the code that runs in the IRQ (for example 257 | the heap may be locked) and scheduling a function to call later will lift 258 | those restrictions. 259 | 260 | Note: If `schedule()` is called from a preempting IRQ, when memory 261 | allocation is not allowed and the callback to be passed to `schedule()` is 262 | a bound method, passing this directly will fail. This is because creating a 263 | reference to a bound method causes memory allocation. A solution is to 264 | create a reference to the method in the class constructor and to pass that 265 | reference to `schedule()`. This is discussed in detail here 266 | :ref:`reference documentation ` under "Creation of Python 267 | objects". 268 | 269 | There is a finite queue to hold the scheduled functions and `schedule()` 270 | will raise a `RuntimeError` if the queue is full. 271 | """ 272 | -------------------------------------------------------------------------------- /micropython_typesheds/neopixel.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | control of WS2812 / NeoPixel LEDs. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/neopixel.rst. 6 | ===================================================== 7 | 8 | .. module:: neopixel 9 | :synopsis: control of WS2812 / NeoPixel LEDs 10 | 11 | This module provides a driver for WS2818 / NeoPixel LEDs. 12 | 13 | .. note:: This module is only included by default on the ESP8266 and ESP32 14 | ports. On STM32 / Pyboard, you can `download the module 15 | `_ 16 | and copy it to the filesystem. 17 | """ 18 | 19 | __author__ = "Howard C Lovatt" 20 | __copyright__ = "Howard C Lovatt, 2020 onwards." 21 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 22 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 23 | 24 | from typing import Final 25 | 26 | from machine import Pin 27 | 28 | _Color: Final = tuple[int, int, int] | tuple[int, int, int, int] 29 | 30 | class NeoPixel: 31 | """ 32 | This class stores pixel data for a WS2812 LED strip connected to a pin. The 33 | application should set pixel data and then call :meth:`NeoPixel.write` 34 | when it is ready to update the strip. 35 | 36 | For example:: 37 | 38 | import neopixel 39 | 40 | # 32 LED strip connected to X8. 41 | p = machine.Pin.board.X8 42 | n = neopixel.NeoPixel(p, 32) 43 | 44 | # Draw a red gradient. 45 | for i in range(32): 46 | n[i] = (i * 8, 0, 0) 47 | 48 | # Update the strip. 49 | n.write() 50 | """ 51 | 52 | def __init__(self, pin: Pin, n: int, /, *, bpp: int = 3, timing: int = 1): 53 | """ 54 | Construct an NeoPixel object. The parameters are: 55 | 56 | - *pin* is a machine.Pin instance. 57 | - *n* is the number of LEDs in the strip. 58 | - *bpp* is 3 for RGB LEDs, and 4 for RGBW LEDs. 59 | - *timing* is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz). 60 | """ 61 | def fill(self, pixel: _Color, /) -> None: 62 | """ 63 | Sets the value of all pixels to the specified *pixel* value (i.e. an 64 | RGB/RGBW tuple). 65 | """ 66 | def __len__(self) -> int: 67 | """ 68 | Returns the number of LEDs in the strip. 69 | """ 70 | def __setitem__(self, index: int, val: _Color, /) -> None: 71 | """ 72 | Set the pixel at *index* to the value, which is an RGB/RGBW tuple. 73 | """ 74 | def __getitem__(self, index: int, /) -> _Color: 75 | """ 76 | Returns the pixel at *index* as an RGB/RGBW tuple. 77 | """ 78 | def write(self) -> None: 79 | """ 80 | Writes the current pixel data to the strip. 81 | """ 82 | -------------------------------------------------------------------------------- /micropython_typesheds/random.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | random numbers. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/random.rst. 6 | ======================================== 7 | 8 | .. module:: random 9 | :synopsis: random numbers 10 | 11 | This module implements a pseudo-random number generator (PRNG). 12 | 13 | |see_cpython_module| :mod:`python:random` . 14 | 15 | .. note:: 16 | 17 | The following notation is used for intervals: 18 | 19 | - () are open interval brackets and do not include their endpoints. 20 | For example, (0, 1) means greater than 0 and less than 1. 21 | In set notation: (0, 1) = {x | 0 < x < 1}. 22 | 23 | - [] are closed interval brackets which include all their limit points. 24 | For example, [0, 1] means greater than or equal to 0 and less than 25 | or equal to 1. 26 | In set notation: [0, 1] = {x | 0 <= x <= 1}. 27 | 28 | .. note:: 29 | 30 | The :func:`randrange`, :func:`randint` and :func:`choice` functions are only 31 | available if the ``MICROPY_PY_URANDOM_EXTRA_FUNCS`` configuration option is 32 | enabled. 33 | """ 34 | 35 | __author__ = "Howard C Lovatt" 36 | __copyright__ = "Howard C Lovatt, 2020 onwards." 37 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 38 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 39 | 40 | from typing import TypeVar, runtime_checkable, Protocol, overload 41 | 42 | _T = TypeVar("_T") 43 | @runtime_checkable 44 | class Subscriptable(Protocol[_T]): 45 | """A `Protocol` (structurally typed) for an object that is subscriptable and of finite length.""" 46 | 47 | __slots__ = () 48 | def __len__(self) -> int: 49 | """Number of elements, normally called via `len(x)` where `x` is an object that implements this protocol.""" 50 | def __getitem__(self, index: int) -> _T: 51 | """ 52 | Element at the given index, 53 | normally called via `x[index]` where `x` is an object that implements this protocol. 54 | """ 55 | 56 | def getrandbits(n: int, /) -> int: 57 | """ 58 | Return an integer with *n* random bits (0 <= n <= 32). 59 | """ 60 | 61 | def randint(a: int, b: int, /) -> int: 62 | """ 63 | Return a random integer in the range [*a*, *b*]. 64 | """ 65 | 66 | @overload 67 | def randrange(stop: int, /) -> int: 68 | """ 69 | The first form returns a random integer from the range [0, *stop*). 70 | The second form returns a random integer from the range [*start*, *stop*). 71 | The third form returns a random integer from the range [*start*, *stop*) in 72 | steps of *step*. For instance, calling ``randrange(1, 10, 2)`` will 73 | return odd numbers between 1 and 9 inclusive. 74 | """ 75 | 76 | @overload 77 | def randrange(start: int, stop: int, /) -> int: 78 | """ 79 | The first form returns a random integer from the range [0, *stop*). 80 | The second form returns a random integer from the range [*start*, *stop*). 81 | The third form returns a random integer from the range [*start*, *stop*) in 82 | steps of *step*. For instance, calling ``randrange(1, 10, 2)`` will 83 | return odd numbers between 1 and 9 inclusive. 84 | """ 85 | 86 | @overload 87 | def randrange(start: int, stop: int, step: int, /) -> int: 88 | """ 89 | The first form returns a random integer from the range [0, *stop*). 90 | The second form returns a random integer from the range [*start*, *stop*). 91 | The third form returns a random integer from the range [*start*, *stop*) in 92 | steps of *step*. For instance, calling ``randrange(1, 10, 2)`` will 93 | return odd numbers between 1 and 9 inclusive. 94 | """ 95 | 96 | def random() -> float: 97 | """ 98 | Return a random floating point number in the range [0.0, 1.0). 99 | """ 100 | 101 | def uniform(a: float, b: float) -> float: 102 | """ 103 | Return a random floating point number N such that *a* <= N <= *b* for *a* <= *b*, 104 | and *b* <= N <= *a* for *b* < *a*. 105 | """ 106 | 107 | def seed(n: int | None = None, /) -> None: 108 | """ 109 | Initialise the random number generator module with the seed *n* which should 110 | be an integer. When no argument (or ``None``) is passed in it will (if 111 | supported by the port) initialise the PRNG with a true random number 112 | (usually a hardware generated random number). 113 | 114 | The ``None`` case only works if ``MICROPY_PY_URANDOM_SEED_INIT_FUNC`` is 115 | enabled by the port, otherwise it raises ``ValueError``. 116 | """ 117 | 118 | def choice(sequence: Subscriptable, /) -> None: 119 | """ 120 | Chooses and returns one item at random from *sequence* (tuple, list or 121 | any object that supports the subscript operation). 122 | """ 123 | -------------------------------------------------------------------------------- /micropython_typesheds/re.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | regular expressions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/re.rst. 6 | ======================================= 7 | 8 | .. module:: re 9 | :synopsis: regular expressions 10 | 11 | |see_cpython_module| :mod:`python:re`. 12 | 13 | This module implements regular expression operations. Regular expression 14 | syntax supported is a subset of CPython ``re`` module (and actually is 15 | a subset of POSIX extended regular expressions). 16 | 17 | Supported operators and special sequences are: 18 | 19 | ``.`` 20 | Match any character. 21 | 22 | ``[...]`` 23 | Match set of characters. Individual characters and ranges are supported, 24 | including negated sets (e.g. ``[^a-c]``). 25 | 26 | ``^`` 27 | Match the start of the string. 28 | 29 | ``$`` 30 | Match the end of the string. 31 | 32 | ``?`` 33 | Match zero or one of the previous sub-pattern. 34 | 35 | ``*`` 36 | Match zero or more of the previous sub-pattern. 37 | 38 | ``+`` 39 | Match one or more of the previous sub-pattern. 40 | 41 | ``??`` 42 | Non-greedy version of ``?``, match zero or one, with the preference 43 | for zero. 44 | 45 | ``*?`` 46 | Non-greedy version of ``*``, match zero or more, with the preference 47 | for the shortest match. 48 | 49 | ``+?`` 50 | Non-greedy version of ``+``, match one or more, with the preference 51 | for the shortest match. 52 | 53 | ``|`` 54 | Match either the left-hand side or the right-hand side sub-patterns of 55 | this operator. 56 | 57 | ``(...)`` 58 | Grouping. Each group is capturing (a substring it captures can be accessed 59 | with `match.group()` method). 60 | 61 | ``\d`` 62 | Matches digit. Equivalent to ``[0-9]``. 63 | 64 | ``\D`` 65 | Matches non-digit. Equivalent to ``[^0-9]``. 66 | 67 | ``\s`` 68 | Matches whitespace. Equivalent to ``[ \t-\r]``. 69 | 70 | ``\S`` 71 | Matches non-whitespace. Equivalent to ``[^ \t-\r]``. 72 | 73 | ``\w`` 74 | Matches "word characters" (ASCII only). Equivalent to ``[A-Za-z0-9_]``. 75 | 76 | ``\W`` 77 | Matches non "word characters" (ASCII only). Equivalent to ``[^A-Za-z0-9_]``. 78 | 79 | ``\`` 80 | Escape character. Any other character following the backslash, except 81 | for those listed above, is taken literally. For example, ``\*`` is 82 | equivalent to literal ``*`` (not treated as the ``*`` operator). 83 | Note that ``\r``, ``\n``, etc. are not handled specially, and will be 84 | equivalent to literal letters ``r``, ``n``, etc. Due to this, it's 85 | not recommended to use raw Python strings (``r""``) for regular 86 | expressions. For example, ``r"\r\n"`` when used as the regular 87 | expression is equivalent to ``"rn"``. To match CR character followed 88 | by LF, use ``"\r\n"``. 89 | 90 | **NOT SUPPORTED**: 91 | 92 | * counted repetitions (``{m,n}``) 93 | * named groups (``(?P...)``) 94 | * non-capturing groups (``(?:...)``) 95 | * more advanced assertions (``\b``, ``\B``) 96 | * special character escapes like ``\r``, ``\n`` - use Python's own escaping 97 | instead 98 | * etc. 99 | 100 | Example:: 101 | 102 | import re 103 | 104 | # As re doesn't support escapes itself, use of r"" strings is not 105 | # recommended. 106 | regex = re.compile("[\r\n]") 107 | 108 | regex.split("line1\rline2\nline3\r\n") 109 | 110 | # Result: 111 | # ['line1', 'line2', 'line3', '', ''] 112 | """ 113 | 114 | __author__ = "Howard C Lovatt" 115 | __copyright__ = "Howard C Lovatt, 2020 onwards." 116 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 117 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 118 | 119 | from typing import AnyStr, Callable, Generic, Final, Any 120 | 121 | _StrLike: Final = str | bytes 122 | 123 | def compile(regex_str: _StrLike, flags: int = ..., /) -> "ure": 124 | """ 125 | Compile regular expression, return `regex ` object. 126 | """ 127 | 128 | def match(regex_str: _StrLike, string: AnyStr, /) -> "Match[AnyStr]": 129 | """ 130 | Compile *regex_str* and match against *string*. Match always happens 131 | from starting position in a string. 132 | """ 133 | 134 | def search(regex_str: _StrLike, string: AnyStr, /) -> "Match[AnyStr]": 135 | """ 136 | Compile *regex_str* and search it in a *string*. Unlike `match`, this will search 137 | string for first position which matches regex (which still may be 138 | 0 if regex is anchored). 139 | """ 140 | 141 | def sub( 142 | regex_str: _StrLike, 143 | replace: AnyStr | Callable[["Match[AnyStr]"], AnyStr], 144 | string: AnyStr, 145 | count: int = 0, 146 | flags: int = 0, 147 | /, 148 | ) -> AnyStr: 149 | """ 150 | Compile *regex_str* and search for it in *string*, replacing all matches 151 | with *replace*, and returning the new string. 152 | 153 | *replace* can be a string or a function. If it is a string then escape 154 | sequences of the form ``\`` and ``\g`` can be used to 155 | expand to the corresponding group (or an empty string for unmatched groups). 156 | If *replace* is a function then it must take a single argument (the match) 157 | and should return a replacement string. 158 | 159 | If *count* is specified and non-zero then substitution will stop after 160 | this many substitutions are made. The *flags* argument is ignored. 161 | 162 | Note: availability of this function depends on :term:`MicroPython port`. 163 | """ 164 | 165 | DEBUG: Final[int] = ... 166 | """ 167 | Flag value, display debug information about compiled expression. 168 | (Availability depends on :term:`MicroPython port`.) 169 | """ 170 | 171 | # noinspection PyPep8Naming 172 | class ure: 173 | """ 174 | Compiled regular expression. Instances of this class are created using 175 | `re.compile()`. 176 | """ 177 | 178 | def match(self, string: AnyStr, /) -> "Match[AnyStr]": 179 | """ 180 | Similar to the module-level functions :meth:`match`, :meth:`search` 181 | and :meth:`sub`. 182 | Using methods is (much) more efficient if the same regex is applied to 183 | multiple strings. 184 | """ 185 | def search(self, string: AnyStr, /) -> "Match[AnyStr]": 186 | """ 187 | Similar to the module-level functions :meth:`match`, :meth:`search` 188 | and :meth:`sub`. 189 | Using methods is (much) more efficient if the same regex is applied to 190 | multiple strings. 191 | """ 192 | def sub( 193 | self, 194 | replace: AnyStr | Callable[["Match[AnyStr]"], AnyStr], 195 | string: AnyStr, 196 | count: int = 0, 197 | flags: int = 0, 198 | /, 199 | ) -> AnyStr: 200 | """ 201 | Similar to the module-level functions :meth:`match`, :meth:`search` 202 | and :meth:`sub`. 203 | Using methods is (much) more efficient if the same regex is applied to 204 | multiple strings. 205 | """ 206 | def split(self, string: AnyStr, max_split: int = -1, /) -> list[AnyStr]: 207 | """ 208 | Split a *string* using regex. If *max_split* is given, it specifies 209 | maximum number of splits to perform. Returns list of strings (there 210 | may be up to *max_split+1* elements if it's specified). 211 | """ 212 | 213 | class Match(Generic[AnyStr]): 214 | """ 215 | Match objects as returned by `match()` and `search()` methods, and passed 216 | to the replacement function in `sub()`. 217 | 218 | The name, `Match`, used for typing is not the same as the runtime name, `match` (note lowercase `m`). 219 | The reason for this difference is that the runtime uses `match` as both a class name and as a method name and 220 | this is not possible within code written entirely in Python and therefore not possible within typing code. 221 | """ 222 | 223 | def group(self, index: int, /) -> AnyStr: 224 | """ 225 | Return matching (sub)string. *index* is 0 for entire match, 226 | 1 and above for each capturing group. Only numeric groups are supported. 227 | """ 228 | def groups(self) -> tuple[AnyStr | Any, ...]: 229 | """ 230 | Return a tuple containing all the substrings of the groups of the match. 231 | 232 | Note: availability of this method depends on :term:`MicroPython port`. 233 | """ 234 | def start(self, index: int = ..., /) -> int: 235 | """ 236 | Return the index in the original string of the start or end of the 237 | substring group that was matched. *index* defaults to the entire 238 | group, otherwise it will select a group. 239 | 240 | Note: availability of these methods depends on :term:`MicroPython port`. 241 | """ 242 | def end(self, index: int = ..., /) -> int: 243 | """ 244 | Return the index in the original string of the start or end of the 245 | substring group that was matched. *index* defaults to the entire 246 | group, otherwise it will select a group. 247 | 248 | Note: availability of these methods depends on :term:`MicroPython port`. 249 | """ 250 | def span(self, index: int = ..., /) -> tuple[int, int]: 251 | """ 252 | Returns the 2-tuple ``(match.start(index), match.end(index))``. 253 | 254 | Note: availability of this method depends on :term:`MicroPython port`. 255 | """ 256 | -------------------------------------------------------------------------------- /micropython_typesheds/select.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | wait for events on a set of streams. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/select.rst. 6 | ==================================================== 7 | 8 | .. module:: select 9 | :synopsis: wait for events on a set of streams 10 | 11 | |see_cpython_module| :mod:`python:select`. 12 | 13 | This module provides functions to efficiently wait for events on multiple 14 | `streams ` (select streams which are ready for operations). 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import Iterable, Any, Final, Iterator 23 | 24 | from uio import IOBase 25 | 26 | POLLIN: Final[int] = ... 27 | """Data available for reading.""" 28 | 29 | POLLOUT: Final[int] = ... 30 | """More data can be written.""" 31 | 32 | POLLHUP: Final[int] = ... 33 | """Socket is no longer connected.""" 34 | 35 | POLLERR: Final[int] = ... 36 | """Socket got an asynchronous error.""" 37 | 38 | def poll() -> "Poll": 39 | """ 40 | Create an instance of the Poll class. 41 | """ 42 | 43 | def select( 44 | rlist: Iterable[Any], 45 | wlist: Iterable[Any], 46 | xlist: Iterable[Any], 47 | timeout: int = -1, 48 | /, 49 | ) -> list[tuple[Any, int, Any, ...]]: 50 | """ 51 | Wait for activity on a set of objects. 52 | 53 | This function is provided by some MicroPython ports for compatibility 54 | and is not efficient. Usage of :class:`Poll` is recommended instead. 55 | """ 56 | 57 | class Poll: 58 | """ 59 | The name, `Poll`, used for typing is not the same as the runtime name, `poll` (note lowercase `p`). 60 | The reason for this difference is that the runtime uses `poll` as both a class name and as a method name and 61 | this is not possible within code written entirely in Python and therefore not possible within typing code. 62 | """ 63 | 64 | def register(self, obj: IOBase, eventmask: int = POLLIN | POLLOUT, /) -> None: 65 | """ 66 | Register `stream` *obj* for polling. *eventmask* is logical OR of: 67 | 68 | * ``select.POLLIN`` - data available for reading 69 | * ``select.POLLOUT`` - more data can be written 70 | 71 | Note that flags like ``select.POLLHUP`` and ``select.POLLERR`` are 72 | *not* valid as input eventmask (these are unsolicited events which 73 | will be returned from `poll()` regardless of whether they are asked 74 | for). This semantics is per POSIX. 75 | 76 | *eventmask* defaults to ``select.POLLIN | select.POLLOUT``. 77 | 78 | It is OK to call this function multiple times for the same *obj*. 79 | Successive calls will update *obj*'s eventmask to the value of 80 | *eventmask* (i.e. will behave as `modify()`). 81 | """ 82 | def unregister(self, obj: IOBase, /) -> None: 83 | """ 84 | Unregister *obj* from polling. 85 | """ 86 | def modify(self, obj: IOBase, eventmask: int, /) -> None: 87 | """ 88 | Modify the *eventmask* for *obj*. If *obj* is not registered, `OSError` 89 | is raised with error of ENOENT. 90 | """ 91 | def poll(self, timeout: int = -1, /) -> list[tuple[Any, int, Any, ...]]: 92 | """ 93 | Wait for at least one of the registered objects to become ready or have an 94 | exceptional condition, with optional timeout in milliseconds (if *timeout* 95 | arg is not specified or -1, there is no timeout). 96 | 97 | Returns list of (``obj``, ``event``, ...) tuples. There may be other elements in 98 | tuple, depending on a platform and version, so don't assume that its size is 2. 99 | The ``event`` element specifies which events happened with a stream and 100 | is a combination of ``select.POLL*`` constants described above. Note that 101 | flags ``select.POLLHUP`` and ``select.POLLERR`` can be returned at any time 102 | (even if were not asked for), and must be acted on accordingly (the 103 | corresponding stream unregistered from poll and likely closed), because 104 | otherwise all further invocations of `poll()` may return immediately with 105 | these flags set for this stream again. 106 | 107 | In case of timeout, an empty list is returned. 108 | 109 | .. admonition:: Difference to CPython 110 | :class: attention 111 | 112 | Tuples returned may contain more than 2 elements as described above. 113 | """ 114 | def ipoll( 115 | self, timeout: int = -1, flags: int = 0, / 116 | ) -> Iterator[tuple[Any, int, Any, ...]]: 117 | """ 118 | Like :meth:`poll.poll`, but instead returns an iterator which yields a 119 | `callee-owned tuple`. This function provides an efficient, allocation-free 120 | way to poll on streams. 121 | 122 | If *flags* is 1, one-shot behaviour for events is employed: streams for 123 | which events happened will have their event masks automatically reset 124 | (equivalent to ``poll.modify(obj, 0)``), so new events for such a stream 125 | won't be processed until new mask is set with `poll.modify()`. This 126 | behaviour is useful for asynchronous I/O schedulers. 127 | 128 | .. admonition:: Difference to CPython 129 | :class: attention 130 | 131 | This function is a MicroPython extension. 132 | """ 133 | -------------------------------------------------------------------------------- /micropython_typesheds/ssl.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | TLS/SSL wrapper for socket objects. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/ssl.rst. 6 | 7 | |see_cpython_module| :mod:`python:ssl`. 8 | 9 | This module provides access to Transport Layer Security (previously and 10 | widely known as “Secure Sockets Layer”) encryption and peer authentication 11 | facilities for network sockets, both client-side and server-side. 12 | 13 | .. admonition:: Difference to CPython 14 | :class: attention 15 | The CPython version of ``ssl`` uses ``SSLError``. 16 | This exception does NOT exist. Instead its base class, OSError, is used. 17 | """ 18 | 19 | __author__ = "Howard C Lovatt" 20 | __copyright__ = "Howard C Lovatt, 2020 onwards." 21 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 22 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 23 | 24 | from typing import Final 25 | 26 | from uio import StrOrBytesPath 27 | from usocket import Socket 28 | 29 | def wrap_socket( 30 | sock: Socket, 31 | server_side: bool = False, 32 | keyfile: StrOrBytesPath | None = None, 33 | certfile: StrOrBytesPath | None = None, 34 | cert_reqs: int = "CERT_NONE", 35 | ca_certs: str | None = None, 36 | do_handshake: bool = True, 37 | /, 38 | ) -> Socket: 39 | """ 40 | Takes a `stream` *sock* (usually socket.socket instance of ``SOCK_STREAM`` type), 41 | and returns an instance of ssl.SSLSocket, which wraps the underlying stream in 42 | an SSL context. Returned object has the usual `stream` interface methods like 43 | ``read()``, ``write()``, etc. 44 | A server-side SSL socket should be created from a normal socket returned from 45 | :meth:`~socket.socket.accept()` on a non-SSL listening server socket. 46 | 47 | - *do_handshake* determines whether the handshake is done as part of the ``wrap_socket`` 48 | or whether it is deferred to be done as part of the initial reads or writes 49 | (there is no ``do_handshake`` method as in CPython). 50 | For blocking sockets doing the handshake immediately is standard. For non-blocking 51 | sockets (i.e. when the *sock* passed into ``wrap_socket`` is in non-blocking mode) 52 | the handshake should generally be deferred because otherwise ``wrap_socket`` blocks 53 | until it completes. Note that in AXTLS the handshake can be deferred until the first 54 | read or write but it then blocks until completion. 55 | 56 | Depending on the underlying module implementation in a particular 57 | :term:`MicroPython port`, some or all keyword arguments above may be not supported. 58 | """ 59 | 60 | CERT_NONE: Final[int] = ... 61 | """ 62 | Supported values for *cert_reqs* parameter. 63 | """ 64 | 65 | CERT_OPTIONAL: Final[int] = ... 66 | """ 67 | Supported values for *cert_reqs* parameter. 68 | """ 69 | 70 | CERT_REQUIRED: Final[int] = ... 71 | """ 72 | Supported values for *cert_reqs* parameter. 73 | """ 74 | -------------------------------------------------------------------------------- /micropython_typesheds/stm.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | functionality specific to STM32 MCUs. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/stm.rst. 6 | =================================================== 7 | 8 | .. module:: stm 9 | :synopsis: functionality specific to STM32 MCUs 10 | 11 | This module provides functionality specific to STM32 microcontrollers, including 12 | direct access to peripheral registers. 13 | """ 14 | 15 | __author__ = "Howard C Lovatt" 16 | __copyright__ = "Howard C Lovatt, 2020 onwards." 17 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 18 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 19 | 20 | from typing import Final 21 | 22 | # noinspection PyPep8Naming 23 | class mem: 24 | """ 25 | Memory objects that can be used in combination with the peripheral register 26 | constants to read and write registers of the MCU hardware peripherals, as well 27 | as all other areas of address space. 28 | 29 | Cannot make an instance of this class, 30 | but pre-made instances: `mem8`, `mem16`, and `mem32` are available for 8, 16, and 32 bit access respectively. 31 | """ 32 | 33 | def __getitem__(self, loc: int, /) -> int: 34 | """ 35 | Get the contents of the given memory location using subscript notation e.g., `mem8[0]`. 36 | Returns 8 bits for mem8`, 16 bits for `mem16`, and 32 bits for `mem32`, in all cases as a single `int`. 37 | Location doesn't overflow, it is truncated. 38 | 39 | Can be used in combination with the peripheral register 40 | constants to read registers of the MCU hardware peripherals, as well 41 | as all other areas of address space. 42 | """ 43 | def __setitem__(self, loc: int, value: int, /) -> None: 44 | """ 45 | Set the contents of the given memory location to the given value using subscript notation e.g., `mem8[0] = 195`. 46 | Sets 8 bits for `mem8`, 16 bits for `mem16`, and 32 bits for `mem32`, from the given `int` value. 47 | Location doesn't overflow, it is truncated. 48 | 49 | Can be used in combination with the peripheral register 50 | constants to write registers of the MCU hardware peripherals, as well 51 | as all other areas of address space. 52 | """ 53 | 54 | mem8: Final[mem] = ... 55 | """ 56 | Read/write 8 bits of memory. 57 | """ 58 | 59 | mem16: Final[mem] = ... 60 | """ 61 | Read/write 16 bits of memory. 62 | """ 63 | 64 | mem32: Final[mem] = ... 65 | """ 66 | Read/write 32 bits of memory. 67 | """ 68 | 69 | GPIOA: Final[int] = ... 70 | """ 71 | Base address of the GPIOA peripheral. 72 | 73 | The module defines constants for registers which are generated from CMSIS header 74 | files, and the constants available depend on the microcontroller series that is 75 | being compiled for. Examples of some constants include: 76 | address of that peripheral. Constants that have a prefix which is the name of a 77 | peripheral, like ``GPIO_BSRR``, are relative offsets of the register. Accessing 78 | peripheral registers requires adding the absolute base address of the peripheral 79 | and the relative register offset. For example ``GPIOA + GPIO_BSRR`` is the 80 | full, absolute address of the ``GPIOA->BSRR`` register. 81 | 82 | Example use: 83 | 84 | .. code-block:: python3 85 | 86 | # set PA2 high 87 | stm.mem32[stm.GPIOA + stm.GPIO_BSRR] = 1 << 2 88 | 89 | # read PA3 90 | value = (stm.mem32[stm.GPIOA + stm.GPIO_IDR] >> 3) & 1 91 | """ 92 | 93 | GPIOB: Final[int] = ... 94 | """ 95 | Base address of the GPIOB peripheral. 96 | 97 | The module defines constants for registers which are generated from CMSIS header 98 | files, and the constants available depend on the microcontroller series that is 99 | being compiled for. Examples of some constants include: 100 | address of that peripheral. Constants that have a prefix which is the name of a 101 | peripheral, like ``GPIO_BSRR``, are relative offsets of the register. Accessing 102 | peripheral registers requires adding the absolute base address of the peripheral 103 | and the relative register offset. For example ``GPIOA + GPIO_BSRR`` is the 104 | full, absolute address of the ``GPIOA->BSRR`` register. 105 | 106 | Example use: 107 | 108 | .. code-block:: python3 109 | 110 | # set PA2 high 111 | stm.mem32[stm.GPIOA + stm.GPIO_BSRR] = 1 << 2 112 | 113 | # read PA3 114 | value = (stm.mem32[stm.GPIOA + stm.GPIO_IDR] >> 3) & 1 115 | """ 116 | 117 | GPIO_BSRR: Final[int] = ... 118 | """ 119 | Offset of the GPIO bit set/reset register. 120 | 121 | The module defines constants for registers which are generated from CMSIS header 122 | files, and the constants available depend on the microcontroller series that is 123 | being compiled for. Examples of some constants include: 124 | address of that peripheral. Constants that have a prefix which is the name of a 125 | peripheral, like ``GPIO_BSRR``, are relative offsets of the register. Accessing 126 | peripheral registers requires adding the absolute base address of the peripheral 127 | and the relative register offset. For example ``GPIOA + GPIO_BSRR`` is the 128 | full, absolute address of the ``GPIOA->BSRR`` register. 129 | 130 | Example use: 131 | 132 | .. code-block:: python3 133 | 134 | # set PA2 high 135 | stm.mem32[stm.GPIOA + stm.GPIO_BSRR] = 1 << 2 136 | 137 | # read PA3 138 | value = (stm.mem32[stm.GPIOA + stm.GPIO_IDR] >> 3) & 1 139 | """ 140 | 141 | GPIO_IDR: Final[int] = ... 142 | """ 143 | Offset of the GPIO input data register. 144 | 145 | The module defines constants for registers which are generated from CMSIS header 146 | files, and the constants available depend on the microcontroller series that is 147 | being compiled for. Examples of some constants include: 148 | address of that peripheral. Constants that have a prefix which is the name of a 149 | peripheral, like ``GPIO_BSRR``, are relative offsets of the register. Accessing 150 | peripheral registers requires adding the absolute base address of the peripheral 151 | and the relative register offset. For example ``GPIOA + GPIO_BSRR`` is the 152 | full, absolute address of the ``GPIOA->BSRR`` register. 153 | 154 | Example use: 155 | 156 | .. code-block:: python3 157 | 158 | # set PA2 high 159 | stm.mem32[stm.GPIOA + stm.GPIO_BSRR] = 1 << 2 160 | 161 | # read PA3 162 | value = (stm.mem32[stm.GPIOA + stm.GPIO_IDR] >> 3) & 1 163 | """ 164 | 165 | GPIO_ODR: Final[int] = ... 166 | """ 167 | Offset of the GPIO output data register. 168 | 169 | Constants that are named after a peripheral, like ``GPIOA``, are the absolute 170 | The module defines constants for registers which are generated from CMSIS header 171 | files, and the constants available depend on the microcontroller series that is 172 | being compiled for. Examples of some constants include: 173 | address of that peripheral. Constants that have a prefix which is the name of a 174 | peripheral, like ``GPIO_BSRR``, are relative offsets of the register. Accessing 175 | peripheral registers requires adding the absolute base address of the peripheral 176 | and the relative register offset. For example ``GPIOA + GPIO_BSRR`` is the 177 | full, absolute address of the ``GPIOA->BSRR`` register. 178 | 179 | Example use: 180 | 181 | .. code-block:: python3 182 | 183 | # set PA2 high 184 | stm.mem32[stm.GPIOA + stm.GPIO_BSRR] = 1 << 2 185 | 186 | # read PA3 187 | value = (stm.mem32[stm.GPIOA + stm.GPIO_IDR] >> 3) & 1 188 | """ 189 | 190 | def rfcore_status() -> int: 191 | """ 192 | Returns the status of the second CPU as an integer (the first word of device 193 | info table). 194 | 195 | These functions are available on STM32WBxx microcontrollers, and interact with 196 | the second CPU, the RF core. 197 | """ 198 | 199 | def rfcore_fw_version(id: int, /) -> tuple[int, int, int, int, int]: 200 | """ 201 | Get the version of the firmware running on the second CPU. Pass in 0 for 202 | *id* to get the FUS version, and 1 to get the WS version. 203 | 204 | Returns a 5-tuple with the full version number. 205 | 206 | These functions are available on STM32WBxx microcontrollers, and interact with 207 | the second CPU, the RF core. 208 | """ 209 | 210 | def rfcore_sys_hci(ogf: int, ocf: int, data: int, timeout_ms: int = 0, /) -> bytes: 211 | """ 212 | Execute a HCI command on the SYS channel. The execution is synchronous. 213 | 214 | Returns a bytes object with the result of the SYS command. 215 | These functions are available on STM32WBxx microcontrollers, and interact with 216 | the second CPU, the RF core. 217 | """ 218 | -------------------------------------------------------------------------------- /micropython_typesheds/struct.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | pack and unpack primitive data types. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/struct.rst. 6 | ===================================================== 7 | 8 | .. module:: struct 9 | :synopsis: pack and unpack primitive data types 10 | 11 | |see_cpython_module| :mod:`python:struct`. 12 | 13 | Supported size/byte order prefixes: ``@``, ``<``, ``>``, ``!``. 14 | 15 | Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``, 16 | ``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending 17 | on the floating-point support). 18 | 19 | .. admonition:: Difference to CPython 20 | :class: attention 21 | 22 | Whitespace is not supported in format strings. 23 | """ 24 | 25 | __author__ = "Howard C Lovatt" 26 | __copyright__ = "Howard C Lovatt, 2020 onwards." 27 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 28 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 29 | 30 | from typing import Any 31 | 32 | from uio import AnyReadableBuf, AnyWritableBuf 33 | 34 | def calcsize(fmt: str | bytes, /,) -> int: 35 | """ 36 | Return the number of bytes needed to store the given *fmt*. 37 | """ 38 | 39 | def pack(fmt: str | bytes, /, *v: Any) -> bytes: 40 | """ 41 | Pack the values *v1*, *v2*, ... according to the format string *fmt*. 42 | The return value is a bytes object encoding the values. 43 | """ 44 | 45 | def pack_into( 46 | fmt: str | bytes, buffer: AnyWritableBuf, offset: int, /, *v: Any 47 | ) -> None: 48 | """ 49 | Pack the values *v1*, *v2*, ... according to the format string *fmt* 50 | into a *buffer* starting at *offset*. *offset* may be negative to count 51 | from the end of *buffer*. 52 | """ 53 | 54 | def unpack(fmt: str | bytes, data: AnyReadableBuf, /) -> tuple[Any, ...]: 55 | """ 56 | Unpack from the *data* according to the format string *fmt*. 57 | The return value is a tuple of the unpacked values. 58 | """ 59 | 60 | def unpack_from( 61 | fmt: str | bytes, data: AnyReadableBuf, offset: int = 0, / 62 | ) -> tuple[Any, ...]: 63 | """ 64 | Unpack from the *data* starting at *offset* according to the format string 65 | *fmt*. *offset* may be negative to count from the end of *buffer*. The return 66 | value is a tuple of the unpacked values. 67 | """ 68 | -------------------------------------------------------------------------------- /micropython_typesheds/sys.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | system specific functions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/sys.rst. 6 | ======================================= 7 | 8 | .. module:: sys 9 | :synopsis: system specific functions 10 | 11 | |see_cpython_module| :mod:`python:sys`. 12 | """ 13 | 14 | __author__ = "Howard C Lovatt" 15 | __copyright__ = "Howard C Lovatt, 2020 onwards." 16 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 17 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 18 | 19 | from typing import Callable, Final, Literal, NoReturn 20 | 21 | from uio import IOBase 22 | 23 | class Implementation(tuple[str, tuple[int, int, int], int]): 24 | name: str 25 | version: tuple[int, int, int] 26 | mpy: int 27 | 28 | class ModuleType: 29 | __class__: str 30 | __name__: str 31 | 32 | def exit(retval: object = 0, /) -> NoReturn: 33 | """ 34 | Terminate current program with a given exit code. Underlyingly, this 35 | function raise as `SystemExit` exception. If an argument is given, its 36 | value given as an argument to `SystemExit`. 37 | """ 38 | 39 | def atexit(func: Callable[[], None] | None, /) -> Callable[[], None] | None: 40 | """ 41 | Register *func* to be called upon termination. *func* must be a callable 42 | that takes no arguments, or ``None`` to disable the call. The ``atexit`` 43 | function will return the previous value set by this function, which is 44 | initially ``None``. 45 | 46 | .. admonition:: Difference to CPython 47 | :class: attention 48 | 49 | This function is a MicroPython extension intended to provide similar 50 | functionality to the :mod:`atexit` module in CPython. 51 | """ 52 | 53 | def print_exception(exc: BaseException, file: IOBase[str] = "stdout", /) -> None: 54 | """ 55 | Print exception with a traceback to a file-like object *file* (or 56 | `sys.stdout` by default). 57 | 58 | .. admonition:: Difference to CPython 59 | :class: attention 60 | 61 | This is simplified version of a function which appears in the 62 | ``traceback`` module in CPython. Unlike ``traceback.print_exception()``, 63 | this function takes just exception value instead of exception type, 64 | exception value, and traceback object; *file* argument should be 65 | positional; further arguments are not supported. CPython-compatible 66 | ``traceback`` module can be found in `micropython-lib`. 67 | 68 | .. function:: settrace(tracefunc) 69 | 70 | Enable tracing of bytecode execution. For details see the `CPython 71 | documentaion `_. 72 | 73 | This function requires a custom MicroPython build as it is typically not 74 | present in pre-built firmware (due to it affecting performance). The relevant 75 | configuration option is *MICROPY_PY_SYS_SETTRACE*. 76 | """ 77 | 78 | argv: Final[list[str]] = ... 79 | """ 80 | A mutable list of arguments the current program was started with. 81 | """ 82 | 83 | byteorder: Final[Literal["little", "big"]] = ... 84 | """ 85 | The byte order of the system (``"little"`` or ``"big"``). 86 | """ 87 | 88 | implementation: Final[Implementation] = ... 89 | """ 90 | Object with information about the current Python implementation. For 91 | MicroPython, it has following attributes: 92 | 93 | * *name* - string "micropython" 94 | * *version* - tuple (major, minor, micro), e.g. (1, 7, 0) 95 | 96 | This object is the recommended way to distinguish MicroPython from other 97 | Python implementations (note that it still may not exist in the very 98 | minimal ports). 99 | 100 | .. admonition:: Difference to CPython 101 | :class: attention 102 | 103 | CPython mandates more attributes for this object, but the actual useful 104 | bare minimum is implemented in MicroPython. 105 | """ 106 | 107 | maxsize: Final[int] = ... 108 | """ 109 | Maximum value which a native integer type can hold on the current platform, 110 | or maximum value representable by MicroPython integer type, if it's smaller 111 | than platform max value (that is the case for MicroPython ports without 112 | long int support). 113 | 114 | This attribute is useful for detecting "bitness" of a platform (32-bit vs 115 | 64-bit, etc.). It's recommended to not compare this attribute to some 116 | value directly, but instead count number of bits in it:: 117 | 118 | bits = 0 119 | v = sys.maxsize 120 | while v: 121 | bits += 1 122 | v >>= 1 123 | if bits > 32: 124 | # 64-bit (or more) platform 125 | ... 126 | else: 127 | # 32-bit (or less) platform 128 | # Note that on 32-bit platform, value of bits may be less than 32 129 | # (e.g. 31) due to peculiarities described above, so use "> 16", 130 | # "> 32", "> 64" style of comparisons. 131 | """ 132 | 133 | modules: Final[dict[str, ModuleType]] = ... 134 | """ 135 | Dictionary of loaded modules. On some ports, it may not include builtin 136 | modules. 137 | """ 138 | 139 | path: Final[list[str]] = ... 140 | """ 141 | A mutable list of directories to search for imported modules. 142 | 143 | .. admonition:: Difference to CPython 144 | :class: attention 145 | 146 | On MicroPython, an entry with the value ``".frozen"`` will indicate that import 147 | should search :term:`frozen modules ` at that point in the search. 148 | If no frozen module is found then search will *not* look for a directory called 149 | ``.frozen``, instead it will continue with the next entry in ``sys.path``. 150 | """ 151 | 152 | platform: Final[str] = ... 153 | """ 154 | The platform that MicroPython is running on. For OS/RTOS ports, this is 155 | usually an identifier of the OS, e.g. ``"linux"``. For baremetal ports it 156 | is an identifier of a board, e.g. ``"pyboard"`` for the original MicroPython 157 | reference board. It thus can be used to distinguish one board from another. 158 | If you need to check whether your program runs on MicroPython (vs other 159 | Python implementation), use `sys.implementation` instead. 160 | """ 161 | 162 | stderr: Final[IOBase[str]] = ... 163 | """ 164 | Standard error `stream`. 165 | """ 166 | 167 | stdin: Final[IOBase[str]] = ... 168 | """ 169 | Standard input `stream`. 170 | """ 171 | 172 | stdout: Final[IOBase[str]] = ... 173 | """ 174 | Standard output `stream`. 175 | """ 176 | 177 | version: Final[str] = ... 178 | """ 179 | Python language version that this implementation conforms to, as a string. 180 | """ 181 | 182 | version_info: Final[tuple[int, int, int]] = ... 183 | """ 184 | Python language version that this implementation conforms to, as a tuple of ints. 185 | 186 | .. admonition:: Difference to CPython 187 | :class: attention 188 | 189 | Only the first three version numbers (major, minor, micro) are supported and 190 | they can be referenced only by index, not by name. 191 | """ 192 | -------------------------------------------------------------------------------- /micropython_typesheds/uarray.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | efficient arrays of numeric data. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/array.rst. 6 | """ 7 | 8 | __author__ = "Howard C Lovatt" 9 | __copyright__ = "Howard C Lovatt, 2020 onwards." 10 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 11 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 12 | 13 | from typing import ( 14 | overload, 15 | Sequence, 16 | Any, 17 | MutableSequence, 18 | Generic, 19 | Text, 20 | TypeVar, 21 | Final, 22 | ) 23 | 24 | _T: Final = TypeVar("_T", int, float, Text) 25 | 26 | # noinspection PyPep8Naming 27 | class array(MutableSequence[_T], Generic[_T]): 28 | """ 29 | |see_cpython_module| :mod:`python:array`. 30 | 31 | Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``, 32 | ``L``, ``q``, ``Q``, ``f``, ``d`` (the latter 2 depending on the 33 | floating-point support). 34 | 35 | +-----------+--------------------+-------------------+-----------------------+ 36 | | Type code | C Type | Python Type | Minimum size in bytes | 37 | +===========+====================+===================+=======================+ 38 | | ``'b'`` | signed char | int | 1 | 39 | +-----------+--------------------+-------------------+-----------------------+ 40 | | ``'B'`` | unsigned char | int | 1 | 41 | +-----------+--------------------+-------------------+-----------------------+ 42 | | ``'h'`` | signed short | int | 2 | 43 | +-----------+--------------------+-------------------+-----------------------+ 44 | | ``'H'`` | unsigned short | int | 2 | 45 | +-----------+--------------------+-------------------+-----------------------+ 46 | | ``'i'`` | signed int | int | 2 | 47 | +-----------+--------------------+-------------------+-----------------------+ 48 | | ``'I'`` | unsigned int | int | 2 | 49 | +-----------+--------------------+-------------------+-----------------------+ 50 | | ``'l'`` | signed long | int | 4 | 51 | +-----------+--------------------+-------------------+-----------------------+ 52 | | ``'L'`` | unsigned long | int | 4 | 53 | +-----------+--------------------+-------------------+-----------------------+ 54 | | ``'q'`` | signed long long | int | 8 | 55 | +-----------+--------------------+-------------------+-----------------------+ 56 | | ``'Q'`` | unsigned long long | int | 8 | 57 | +-----------+--------------------+-------------------+-----------------------+ 58 | | ``'f'`` | float | float | 4 | 59 | +-----------+--------------------+-------------------+-----------------------+ 60 | | ``'d'`` | double | float | 8 | 61 | +-----------+--------------------+-------------------+-----------------------+ 62 | """ 63 | 64 | def __init__(self, typecode: str, iterable: Sequence[Any] = ..., /): 65 | """ 66 | Create array with elements of given type. Initial contents of the 67 | array are given by *iterable*. If it is not provided, an empty 68 | array is created. 69 | """ 70 | def append(self, val: Any, /) -> None: 71 | """ 72 | Append new element *val* to the end of array, growing it. 73 | """ 74 | def extend(self, iterable: Sequence[Any], /) -> None: 75 | """ 76 | Append new elements as contained in *iterable* to the end of 77 | array, growing it. 78 | """ 79 | def decode(self, encoding: str = "utf-8", errors: str = "strict") -> str: 80 | """ 81 | Deprecated *do not use*, likely to be removed in future! 82 | 83 | Note: ``decode`` is only meant to be present for ``bytearray``, 84 | but for efficiency of code-size reasons ``bytearray`` is implemented with the same code as the 85 | other array type-codes and hence ``decode`` is on all ``array``s at present. 86 | """ 87 | @overload 88 | def __delitem__(self, i: int) -> None: 89 | """``array`` object does **not** support item deletion.""" 90 | @overload 91 | def __delitem__(self, sl: slice) -> None: 92 | """``array`` object does **not** support item deletion.""" 93 | def insert(self, index: int, value: _T) -> None: 94 | """``array`` object does **not** support item insertion.""" 95 | @overload 96 | def __getitem__(self, index: int) -> _T: 97 | """ 98 | Indexed read of ``self``; called as ``a[index]``, where ``a`` is an ``array``. 99 | Returns the value at the given ``index``. 100 | Negative indices count from end and ``IndexError``is thrown if the index out of range. 101 | 102 | **Note:** ``__getitem__`` cannot be called directly (``a.__getitem__(index)`` fails) and 103 | is not present in ``__dict__``, however ``a[index]`` does work. 104 | """ 105 | @overload 106 | def __getitem__(self, sl: slice) -> array[_T]: 107 | """ 108 | Slice read of ``self``; called as ``a[sl]``, where ``a`` is an ``array``. 109 | Returns an ``array`` of values for the given slice. 110 | Negative slice indices count from end and ``IndexError``is thrown if any of the slice indices are out of range. 111 | **Note:** ``__getitem__`` cannot be called directly (``a.__getitem__(sl)`` fails) and 112 | is not present in ``__dict__``, however ``a[sl]`` does work. 113 | """ 114 | @overload 115 | def __setitem__(self, index: int, value: _T) -> None: 116 | """ 117 | Indexed write into ``self``; called as ``a[index] = value`` where ``a`` is an ``array``, 118 | ``index`` is an ``int``, and ``value`` is the same type as ``a``'s content. 119 | Negative indices count from end and ``IndexError``is thrown if the index out of range. 120 | 121 | **Note:** ``__setitem__`` cannot be called directly (``a.__setitem__(index, value)`` fails) and 122 | is not present in ``__dict__``, however ``a[index] = value`` does work. 123 | """ 124 | @overload 125 | def __setitem__(self, sl: slice, values: array[_T]) -> None: 126 | """ 127 | Indexed write into ``self``; called as ``a[sl] = values``, where ``a`` is an ``array``, 128 | ``sl`` is an ``slice``, and ``values`` is the same type as ``a``. 129 | Negative indices count from end and ``IndexError``is thrown if any of the slice indices are out of range. 130 | **Note:** ``__setitem__`` cannot be called directly (``a.__setitem__(index, value)`` fails) and 131 | is not present in ``__dict__``, however ``a[index] = value`` does work. 132 | """ 133 | def __len__(self) -> int: 134 | """ 135 | Returns the number of items in ``self``; called as ``len(a)``, where ``a`` is an ``array``. 136 | **Note:** ``__len__`` cannot be called directly (``a.__len__()`` fails) and the 137 | method is not present in ``__dict__``, however ``len(a)`` does work. 138 | """ 139 | def __add__(self, other: array[_T]) -> array[_T]: 140 | """ 141 | Return a new ``array`` that is the concatenation of ``self`` with ``other``; 142 | called as ``a + other`` (where ``a`` and ``other`` are both ``array``s). 143 | **Note:** ``__add__`` cannot be called directly (``a.__add__(other)`` fails) and 144 | is not present in ``__dict__``, however ``a + other`` does work. 145 | """ 146 | def __iadd__(self, other: array[_T]) -> None: 147 | """ 148 | Concatenates ``self`` with ``other`` in-place; 149 | called as ``a += other``, where ``a`` and ``other`` are both ``array``s. 150 | Equivalent to ``extend(other)``. 151 | **Note:** ``__iadd__`` cannot be called directly (``a.__iadd__(other)`` fails) and 152 | is not present in ``__dict__``, however ``a += other`` does work. 153 | """ 154 | def __repr__(self) -> str: 155 | """ 156 | Returns the string representation of ``self``; called as ``str(a)`` or ``repr(a)```, 157 | where ``a`` is an ``array``. 158 | Returns the string 'array(, [])', 159 | where ```` is the type code letter for ``self`` and ```` is a 160 | comma separated list of the elements of ``self``. 161 | **Note:** ``__repr__`` cannot be called directly (``a.__repr__()`` fails) and 162 | is not present in ``__dict__``, however ``str(a)`` and ``repr(a)`` both work. 163 | """ 164 | -------------------------------------------------------------------------------- /micropython_typesheds/ubinascii.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | binary/ASCII conversions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/binascii.rst. 6 | =========================================== 7 | 8 | .. module:: binascii 9 | :synopsis: binary/ASCII conversions 10 | 11 | |see_cpython_module| :mod:`python:binascii`. 12 | 13 | This module implements conversions between binary data and various 14 | encodings of it in ASCII form (in both directions). 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | def hexlify(data: bytes, sep: str | bytes = ..., /) -> bytes: 23 | """ 24 | Convert the bytes in the *data* object to a hexadecimal representation. 25 | Returns a bytes object. 26 | 27 | If the additional argument *sep* is supplied it is used as a separator 28 | between hexadecimal values. 29 | """ 30 | 31 | def unhexlify(data: str | bytes, /) -> bytes: 32 | """ 33 | Convert hexadecimal data to binary representation. Returns bytes string. 34 | (i.e. inverse of hexlify) 35 | """ 36 | 37 | def a2b_base64(data: str | bytes, /) -> bytes: 38 | """ 39 | Decode base64-encoded data, ignoring invalid characters in the input. 40 | Conforms to `RFC 2045 s.6.8 `_. 41 | Returns a bytes object. 42 | """ 43 | 44 | def b2a_base64(data: bytes, /) -> bytes: 45 | """ 46 | Encode binary data in base64 format, as in `RFC 3548 47 | `_. Returns the encoded data 48 | followed by a newline character, as a bytes object. 49 | """ 50 | -------------------------------------------------------------------------------- /micropython_typesheds/ucollections.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | collection and container types. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/collections.rst. 6 | ==================================================== 7 | 8 | .. module:: collections 9 | :synopsis: collection and container types 10 | 11 | |see_cpython_module| :mod:`python:collections`. 12 | 13 | This module implements advanced collection and container types to 14 | hold/accumulate various objects. 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import overload, Any, Type, Iterable, TypeVar, Generic, Mapping, Dict, Final 23 | 24 | _KT: Final = TypeVar("_KT") 25 | _VT: Final = TypeVar("_VT") 26 | 27 | def namedtuple(name: str, fields: str | Iterable[str]) -> Type[tuple[Any, ...]]: 28 | """ 29 | This is factory function to create a new namedtuple type with a specific 30 | name and set of fields. A namedtuple is a subclass of tuple which allows 31 | to access its fields not just by numeric index, but also with an attribute 32 | access syntax using symbolic field names. Fields is a sequence of strings 33 | specifying field names. For compatibility with CPython it can also be a 34 | a string with space-separated field named (but this is less efficient). 35 | Example of use:: 36 | 37 | from collections import namedtuple 38 | 39 | MyTuple = namedtuple("MyTuple", ("id", "name")) 40 | t1 = MyTuple(1, "foo") 41 | t2 = MyTuple(2, "bar") 42 | print(t1.name) 43 | assert t2.name == t2[1] 44 | """ 45 | 46 | # noinspection PyPep8Naming 47 | class deque: 48 | """ 49 | Minimal implementation of a deque that implements a FIFO buffer. 50 | """ 51 | 52 | def __init__(self, iterable: tuple[Any], maxlen: int, flags: int = 0, /): 53 | """ 54 | Deques (double-ended queues) are a list-like container that support O(1) 55 | appends and pops from either side of the deque. New deques are created 56 | using the following arguments: 57 | 58 | - *iterable* must be the empty tuple, and the new deque is created empty. 59 | 60 | - *maxlen* must be specified and the deque will be bounded to this 61 | maximum length. Once the deque is full, any new items added will 62 | discard items from the opposite end. 63 | 64 | - The optional *flags* can be 1 to check for overflow when adding items. 65 | """ 66 | def __bool__(self) -> bool: 67 | """ 68 | Returns true if the `deque` isn't empty. 69 | 70 | **Note:** The method isn't listed by ``dir(deque)`` and can't be called directly, 71 | however ``bool(deque)`` and automatic conversion work! 72 | """ 73 | def __len__(self) -> int: 74 | """ 75 | Returns the number of items in the `deque`. 76 | 77 | **Note:** The method isn't listed by ``dir(deque)`` and can't be called directly, 78 | however ``len(deque)`` works! 79 | """ 80 | def append(self, x: Any, /) -> None: 81 | """ 82 | Add *x* to the right side of the deque. 83 | Raises IndexError if overflow checking is enabled and there is no more room left. 84 | """ 85 | def popleft(self) -> Any: 86 | """ 87 | Remove and return an item from the left side of the deque. 88 | Raises IndexError if no items are present. 89 | """ 90 | 91 | class OrderedDict(Dict[_KT, _VT], Generic[_KT, _VT]): 92 | """ 93 | W 94 | h 95 | e 96 | n 97 | 98 | o 99 | r 100 | d 101 | e 102 | r 103 | e 104 | d 105 | 106 | d 107 | i 108 | c 109 | t 110 | 111 | i 112 | s 113 | 114 | i 115 | t 116 | e 117 | r 118 | a 119 | t 120 | e 121 | d 122 | 123 | o 124 | v 125 | e 126 | r 127 | , 128 | 129 | k 130 | e 131 | y 132 | s 133 | / 134 | i 135 | t 136 | e 137 | m 138 | s 139 | 140 | a 141 | r 142 | e 143 | 144 | r 145 | e 146 | t 147 | u 148 | r 149 | n 150 | e 151 | d 152 | 153 | i 154 | n 155 | 156 | t 157 | h 158 | e 159 | 160 | o 161 | r 162 | d 163 | e 164 | r 165 | 166 | t 167 | h 168 | e 169 | y 170 | 171 | w 172 | e 173 | r 174 | e 175 | 176 | a 177 | d 178 | d 179 | e 180 | d 181 | . 182 | """ 183 | 184 | @overload 185 | def __init__(self): 186 | """ 187 | ``dict`` type subclass which remembers and preserves the order of keys 188 | added. When ordered dict is iterated over, keys/items are returned in 189 | the order they were added:: 190 | 191 | from collections import OrderedDict 192 | 193 | # To make benefit of ordered keys, OrderedDict should be initialized 194 | # from sequence of (key, value) pairs. 195 | d = OrderedDict([("z", 1), ("a", 2)]) 196 | # More items can be added as usual 197 | d["w"] = 5 198 | d["b"] = 3 199 | for k, v in d.items(): 200 | print(k, v) 201 | 202 | Output:: 203 | 204 | z 1 205 | a 2 206 | w 5 207 | b 3 208 | """ 209 | @overload 210 | def __init__(self, **kwargs: _VT): 211 | """ 212 | ``dict`` type subclass which remembers and preserves the order of keys 213 | added. When ordered dict is iterated over, keys/items are returned in 214 | the order they were added:: 215 | 216 | from collections import OrderedDict 217 | 218 | # To make benefit of ordered keys, OrderedDict should be initialized 219 | # from sequence of (key, value) pairs. 220 | d = OrderedDict([("z", 1), ("a", 2)]) 221 | # More items can be added as usual 222 | d["w"] = 5 223 | d["b"] = 3 224 | for k, v in d.items(): 225 | print(k, v) 226 | 227 | Output:: 228 | 229 | z 1 230 | a 2 231 | w 5 232 | b 3 233 | """ 234 | @overload 235 | def __init__(self, map: Mapping[_KT, _VT], **kwargs: _VT): 236 | """ 237 | ``dict`` type subclass which remembers and preserves the order of keys 238 | added. When ordered dict is iterated over, keys/items are returned in 239 | the order they were added:: 240 | 241 | from collections import OrderedDict 242 | 243 | # To make benefit of ordered keys, OrderedDict should be initialized 244 | # from sequence of (key, value) pairs. 245 | d = OrderedDict([("z", 1), ("a", 2)]) 246 | # More items can be added as usual 247 | d["w"] = 5 248 | d["b"] = 3 249 | for k, v in d.items(): 250 | print(k, v) 251 | 252 | Output:: 253 | 254 | z 1 255 | a 2 256 | w 5 257 | b 3 258 | """ 259 | -------------------------------------------------------------------------------- /micropython_typesheds/ucryptolib.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | cryptographic ciphers. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/cryptolib.rst. 6 | ========================================= 7 | 8 | .. module:: cryptolib 9 | :synopsis: cryptographic ciphers 10 | """ 11 | 12 | __author__ = "Howard C Lovatt" 13 | __copyright__ = "Howard C Lovatt, 2020 onwards." 14 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 15 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 16 | 17 | from typing import overload 18 | 19 | from uio import AnyReadableBuf, AnyWritableBuf 20 | 21 | # noinspection PyPep8Naming 22 | class aes: 23 | """ 24 | .. class:: aes 25 | """ 26 | 27 | @overload 28 | def __init__(self, key: AnyReadableBuf, mode: int, /): 29 | """ 30 | Initialize cipher object, suitable for encryption/decryption. Note: 31 | after initialization, cipher object can be use only either for 32 | encryption or decryption. Running decrypt() operation after encrypt() 33 | or vice versa is not supported. 34 | 35 | Parameters are: 36 | 37 | * *key* is an encryption/decryption key (bytes-like). 38 | * *mode* is: 39 | 40 | * ``1`` (or ``cryptolib.MODE_ECB`` if it exists) for Electronic Code Book (ECB). 41 | * ``2`` (or ``cryptolib.MODE_CBC`` if it exists) for Cipher Block Chaining (CBC). 42 | * ``6`` (or ``cryptolib.MODE_CTR`` if it exists) for Counter mode (CTR). 43 | 44 | * *IV* is an initialization vector for CBC mode. 45 | * For Counter mode, *IV* is the initial value for the counter. 46 | """ 47 | @overload 48 | def __init__(self, key: AnyReadableBuf, mode: int, IV: AnyReadableBuf, /): 49 | """ 50 | Initialize cipher object, suitable for encryption/decryption. Note: 51 | after initialization, cipher object can be use only either for 52 | encryption or decryption. Running decrypt() operation after encrypt() 53 | or vice versa is not supported. 54 | 55 | Parameters are: 56 | 57 | * *key* is an encryption/decryption key (bytes-like). 58 | * *mode* is: 59 | 60 | * ``1`` (or ``cryptolib.MODE_ECB`` if it exists) for Electronic Code Book (ECB). 61 | * ``2`` (or ``cryptolib.MODE_CBC`` if it exists) for Cipher Block Chaining (CBC). 62 | * ``6`` (or ``cryptolib.MODE_CTR`` if it exists) for Counter mode (CTR). 63 | 64 | * *IV* is an initialization vector for CBC mode. 65 | * For Counter mode, *IV* is the initial value for the counter. 66 | """ 67 | @overload 68 | def encrypt(self, in_buf: AnyReadableBuf, /) -> bytes: 69 | """ 70 | Encrypt *in_buf*. If no *out_buf* is given result is returned as a 71 | newly allocated `bytes` object. Otherwise, result is written into 72 | mutable buffer *out_buf*. *in_buf* and *out_buf* can also refer 73 | to the same mutable buffer, in which case data is encrypted in-place. 74 | """ 75 | @overload 76 | def encrypt(self, in_buf: AnyReadableBuf, out_buf: AnyWritableBuf, /) -> None: 77 | """ 78 | Encrypt *in_buf*. If no *out_buf* is given result is returned as a 79 | newly allocated `bytes` object. Otherwise, result is written into 80 | mutable buffer *out_buf*. *in_buf* and *out_buf* can also refer 81 | to the same mutable buffer, in which case data is encrypted in-place. 82 | """ 83 | @overload 84 | def decrypt(self, in_buf: AnyReadableBuf, /) -> bytes: 85 | """ 86 | Like `encrypt()`, but for decryption. 87 | """ 88 | @overload 89 | def decrypt(self, in_buf: AnyReadableBuf, out_buf: AnyWritableBuf, /) -> None: 90 | """ 91 | Like `encrypt()`, but for decryption. 92 | """ 93 | -------------------------------------------------------------------------------- /micropython_typesheds/uerrno.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | system error codes. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/errno.rst. 6 | ================================== 7 | 8 | .. module:: errno 9 | :synopsis: system error codes 10 | 11 | |see_cpython_module| :mod:`python:errno`. 12 | 13 | This module provides access to symbolic error codes for `OSError` exception. 14 | A particular inventory of codes depends on :term:`MicroPython port`. 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import Final, Dict 23 | 24 | EEXIST: Final[int] = ... 25 | """ 26 | Error codes, based on ANSI C/POSIX standard. All error codes start with 27 | "E". As mentioned above, inventory of the codes depends on 28 | :term:`MicroPython port`. Errors are usually accessible as ``exc.errno`` 29 | where ``exc`` is an instance of `OSError`. Usage example:: 30 | 31 | try: 32 | os.mkdir("my_dir") 33 | except OSError as exc: 34 | if exc.errno == errno.EEXIST: 35 | print("Directory already exists") 36 | """ 37 | 38 | EAGAIN: Final[int] = ... 39 | """ 40 | Error codes, based on ANSI C/POSIX standard. All error codes start with 41 | "E". As mentioned above, inventory of the codes depends on 42 | :term:`MicroPython port`. Errors are usually accessible as ``exc.errno`` 43 | where ``exc`` is an instance of `OSError`. Usage example:: 44 | 45 | try: 46 | os.mkdir("my_dir") 47 | except OSError as exc: 48 | if exc.errno == errno.EEXIST: 49 | print("Directory already exists") 50 | """ 51 | 52 | errorcode: Final[Dict[int, str]] = ... 53 | """ 54 | Dictionary mapping numeric error codes to strings with symbolic error 55 | code (see above):: 56 | 57 | >>> print(errno.errorcode[errno.EEXIST]) 58 | EEXIST 59 | """ 60 | -------------------------------------------------------------------------------- /micropython_typesheds/uhashlib.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | hashing algorithms. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/hashlib.rst. 6 | ==================================== 7 | 8 | .. module:: hashlib 9 | :synopsis: hashing algorithms 10 | 11 | |see_cpython_module| :mod:`python:hashlib`. 12 | 13 | This module implements binary data hashing algorithms. The exact inventory 14 | of available algorithms depends on a board. Among the algorithms which may 15 | be implemented: 16 | 17 | * SHA256 - The current generation, modern hashing algorithm (of SHA2 series). 18 | It is suitable for cryptographically-secure purposes. Included in the 19 | MicroPython core and any board is recommended to provide this, unless 20 | it has particular code size constraints. 21 | 22 | * SHA1 - A previous generation algorithm. Not recommended for new usages, 23 | but SHA1 is a part of number of Internet standards and existing 24 | applications, so boards targeting network connectivity and 25 | interoperability will try to provide this. 26 | 27 | * MD5 - A legacy algorithm, not considered cryptographically secure. Only 28 | selected boards, targeting interoperability with legacy applications, 29 | will offer this. 30 | """ 31 | 32 | __author__ = "Howard C Lovatt" 33 | __copyright__ = "Howard C Lovatt, 2020 onwards." 34 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 35 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 36 | 37 | from abc import ABC 38 | from typing import overload 39 | 40 | from uio import AnyReadableBuf 41 | 42 | # noinspection PyPep8Naming 43 | class sha256("_Hash"): 44 | """ 45 | The current generation, modern hashing algorithm (of SHA2 series). 46 | It is suitable for cryptographically-secure purposes. Included in the 47 | MicroPython core and any board is recommended to provide this, unless 48 | it has particular code size constraints. 49 | """ 50 | 51 | @overload 52 | def __init__(self): 53 | """ 54 | Create an SHA256 hasher object and optionally feed ``data`` into it. 55 | """ 56 | @overload 57 | def __init__(self, data: AnyReadableBuf): 58 | """ 59 | Create an SHA256 hasher object and optionally feed ``data`` into it. 60 | """ 61 | 62 | # noinspection PyPep8Naming 63 | class sha1("_Hash"): 64 | """ 65 | A previous generation algorithm. Not recommended for new usages, 66 | but SHA1 is a part of number of Internet standards and existing 67 | applications, so boards targeting network connectivity and 68 | interoperability will try to provide this. 69 | """ 70 | 71 | @overload 72 | def __init__(self): 73 | """ 74 | Create an SHA1 hasher object and optionally feed ``data`` into it. 75 | """ 76 | @overload 77 | def __init__(self, data: AnyReadableBuf): 78 | """ 79 | Create an SHA1 hasher object and optionally feed ``data`` into it. 80 | """ 81 | 82 | # noinspection PyPep8Naming 83 | class md5("_Hash"): 84 | """ 85 | A legacy algorithm, not considered cryptographically secure. Only 86 | selected boards, targeting interoperability with legacy applications, 87 | will offer this. 88 | """ 89 | 90 | def __init__(self, data: AnyReadableBuf = ..., /): 91 | """ 92 | Create an MD5 hasher object and optionally feed ``data`` into it. 93 | """ 94 | 95 | class _Hash(ABC): 96 | """ 97 | Abstract base class for hashing algorithms that defines methods available in all algorithms. 98 | """ 99 | 100 | def update(self, data: AnyReadableBuf, /) -> None: 101 | """ 102 | Feed more binary data into hash. 103 | """ 104 | def digest(self) -> bytes: 105 | """ 106 | Return hash for all data passed through hash, as a bytes object. After this 107 | method is called, more data cannot be fed into the hash any longer. 108 | """ 109 | def hexdigest(self) -> str: 110 | """ 111 | This method is NOT implemented. Use ``binascii.hexlify(hash.digest())`` 112 | to achieve a similar effect. 113 | """ 114 | -------------------------------------------------------------------------------- /micropython_typesheds/uheapq.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | heap queue algorithm. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/heapq.rst. 6 | ==================================== 7 | 8 | .. module:: heapq 9 | :synopsis: heap queue algorithm 10 | 11 | |see_cpython_module| :mod:`python:heapq`. 12 | 13 | This module implements the 14 | `min heap queue algorithm `_. 15 | 16 | A heap queue is essentially a list that has its elements stored in such a way 17 | that the first item of the list is always the smallest. 18 | """ 19 | 20 | __author__ = "Howard C Lovatt" 21 | __copyright__ = "Howard C Lovatt, 2020 onwards." 22 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 23 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 24 | 25 | from typing import TypeVar, Any, Final 26 | 27 | _T: Final = TypeVar("_T") 28 | 29 | def heappush(heap: list[_T], item: _T, /) -> None: 30 | """ 31 | Push the ``item`` onto the ``heap``. 32 | """ 33 | 34 | def heappop(heap: list[_T], /) -> _T: 35 | """ 36 | Pop the first item from the ``heap``, and return it. Raise ``IndexError`` if 37 | ``heap`` is empty. 38 | 39 | The returned item will be the smallest item in the ``heap``. 40 | """ 41 | 42 | def heapify(x: list[Any], /) -> None: 43 | """ 44 | Convert the list ``x`` into a heap. This is an in-place operation. 45 | """ 46 | -------------------------------------------------------------------------------- /micropython_typesheds/ujson.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | JSON encoding and decoding. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/json.rst. 6 | ========================================= 7 | 8 | .. module:: json 9 | :synopsis: JSON encoding and decoding 10 | 11 | |see_cpython_module| :mod:`python:json`. 12 | 13 | This modules allows to convert between Python objects and the JSON 14 | data format. 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import Any, AnyStr 23 | 24 | from uio import IOBase 25 | 26 | def dump( 27 | obj: Any, stream: IOBase[str, Any], separators: tuple[str, str] | None = None, / 28 | ) -> None: 29 | """ 30 | Serialise *obj* to a JSON string, writing it to the given *stream*. 31 | 32 | If specified, separators should be an ``(item_separator, key_separator)`` 33 | tuple. The default is ``(', ', ': ')``. To get the most compact JSON 34 | representation, you should specify ``(',', ':')`` to eliminate whitespace. 35 | """ 36 | 37 | def dumps(obj: Any, separators: tuple[str, str] | None = None) -> str: 38 | """ 39 | Return *obj* represented as a JSON string. 40 | 41 | The arguments have the same meaning as in `dump`. 42 | """ 43 | 44 | def load(stream: IOBase[str, Any]) -> Any: 45 | """ 46 | Parse the given *stream*, interpreting it as a JSON string and 47 | deserialising the data to a Python object. The resulting object is 48 | returned. 49 | 50 | Parsing continues until end-of-file is encountered. 51 | A :exc:`ValueError` is raised if the data in *stream* is not correctly formed. 52 | """ 53 | 54 | def loads(str: AnyStr) -> Any: 55 | """ 56 | Parse the JSON *str* and return an object. Raises :exc:`ValueError` if the 57 | string is not correctly formed. 58 | """ 59 | -------------------------------------------------------------------------------- /micropython_typesheds/ure.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | regular expressions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/re.rst. 6 | ======================================= 7 | 8 | .. module:: re 9 | :synopsis: regular expressions 10 | 11 | |see_cpython_module| :mod:`python:re`. 12 | 13 | This module implements regular expression operations. Regular expression 14 | syntax supported is a subset of CPython ``re`` module (and actually is 15 | a subset of POSIX extended regular expressions). 16 | 17 | Supported operators and special sequences are: 18 | 19 | ``.`` 20 | Match any character. 21 | 22 | ``[...]`` 23 | Match set of characters. Individual characters and ranges are supported, 24 | including negated sets (e.g. ``[^a-c]``). 25 | 26 | ``^`` 27 | Match the start of the string. 28 | 29 | ``$`` 30 | Match the end of the string. 31 | 32 | ``?`` 33 | Match zero or one of the previous sub-pattern. 34 | 35 | ``*`` 36 | Match zero or more of the previous sub-pattern. 37 | 38 | ``+`` 39 | Match one or more of the previous sub-pattern. 40 | 41 | ``??`` 42 | Non-greedy version of ``?``, match zero or one, with the preference 43 | for zero. 44 | 45 | ``*?`` 46 | Non-greedy version of ``*``, match zero or more, with the preference 47 | for the shortest match. 48 | 49 | ``+?`` 50 | Non-greedy version of ``+``, match one or more, with the preference 51 | for the shortest match. 52 | 53 | ``|`` 54 | Match either the left-hand side or the right-hand side sub-patterns of 55 | this operator. 56 | 57 | ``(...)`` 58 | Grouping. Each group is capturing (a substring it captures can be accessed 59 | with `match.group()` method). 60 | 61 | ``\d`` 62 | Matches digit. Equivalent to ``[0-9]``. 63 | 64 | ``\D`` 65 | Matches non-digit. Equivalent to ``[^0-9]``. 66 | 67 | ``\s`` 68 | Matches whitespace. Equivalent to ``[ \t-\r]``. 69 | 70 | ``\S`` 71 | Matches non-whitespace. Equivalent to ``[^ \t-\r]``. 72 | 73 | ``\w`` 74 | Matches "word characters" (ASCII only). Equivalent to ``[A-Za-z0-9_]``. 75 | 76 | ``\W`` 77 | Matches non "word characters" (ASCII only). Equivalent to ``[^A-Za-z0-9_]``. 78 | 79 | ``\`` 80 | Escape character. Any other character following the backslash, except 81 | for those listed above, is taken literally. For example, ``\*`` is 82 | equivalent to literal ``*`` (not treated as the ``*`` operator). 83 | Note that ``\r``, ``\n``, etc. are not handled specially, and will be 84 | equivalent to literal letters ``r``, ``n``, etc. Due to this, it's 85 | not recommended to use raw Python strings (``r""``) for regular 86 | expressions. For example, ``r"\r\n"`` when used as the regular 87 | expression is equivalent to ``"rn"``. To match CR character followed 88 | by LF, use ``"\r\n"``. 89 | 90 | **NOT SUPPORTED**: 91 | 92 | * counted repetitions (``{m,n}``) 93 | * named groups (``(?P...)``) 94 | * non-capturing groups (``(?:...)``) 95 | * more advanced assertions (``\b``, ``\B``) 96 | * special character escapes like ``\r``, ``\n`` - use Python's own escaping 97 | instead 98 | * etc. 99 | 100 | Example:: 101 | 102 | import re 103 | 104 | # As re doesn't support escapes itself, use of r"" strings is not 105 | # recommended. 106 | regex = re.compile("[\r\n]") 107 | 108 | regex.split("line1\rline2\nline3\r\n") 109 | 110 | # Result: 111 | # ['line1', 'line2', 'line3', '', ''] 112 | """ 113 | 114 | __author__ = "Howard C Lovatt" 115 | __copyright__ = "Howard C Lovatt, 2020 onwards." 116 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 117 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 118 | 119 | from typing import AnyStr, Callable, Generic, Final, Any 120 | 121 | _StrLike: Final = str | bytes 122 | 123 | def compile(regex_str: _StrLike, flags: int = ..., /) -> "ure": 124 | """ 125 | Compile regular expression, return `regex ` object. 126 | """ 127 | 128 | def match(regex_str: _StrLike, string: AnyStr, /) -> "Match[AnyStr]": 129 | """ 130 | Compile *regex_str* and match against *string*. Match always happens 131 | from starting position in a string. 132 | """ 133 | 134 | def search(regex_str: _StrLike, string: AnyStr, /) -> "Match[AnyStr]": 135 | """ 136 | Compile *regex_str* and search it in a *string*. Unlike `match`, this will search 137 | string for first position which matches regex (which still may be 138 | 0 if regex is anchored). 139 | """ 140 | 141 | def sub( 142 | regex_str: _StrLike, 143 | replace: AnyStr | Callable[["Match[AnyStr]"], AnyStr], 144 | string: AnyStr, 145 | count: int = 0, 146 | flags: int = 0, 147 | /, 148 | ) -> AnyStr: 149 | """ 150 | Compile *regex_str* and search for it in *string*, replacing all matches 151 | with *replace*, and returning the new string. 152 | 153 | *replace* can be a string or a function. If it is a string then escape 154 | sequences of the form ``\`` and ``\g`` can be used to 155 | expand to the corresponding group (or an empty string for unmatched groups). 156 | If *replace* is a function then it must take a single argument (the match) 157 | and should return a replacement string. 158 | 159 | If *count* is specified and non-zero then substitution will stop after 160 | this many substitutions are made. The *flags* argument is ignored. 161 | 162 | Note: availability of this function depends on :term:`MicroPython port`. 163 | """ 164 | 165 | DEBUG: Final[int] = ... 166 | """ 167 | Flag value, display debug information about compiled expression. 168 | (Availability depends on :term:`MicroPython port`.) 169 | """ 170 | 171 | # noinspection PyPep8Naming 172 | class ure: 173 | """ 174 | Compiled regular expression. Instances of this class are created using 175 | `re.compile()`. 176 | """ 177 | 178 | def match(self, string: AnyStr, /) -> "Match[AnyStr]": 179 | """ 180 | Similar to the module-level functions :meth:`match`, :meth:`search` 181 | and :meth:`sub`. 182 | Using methods is (much) more efficient if the same regex is applied to 183 | multiple strings. 184 | """ 185 | def search(self, string: AnyStr, /) -> "Match[AnyStr]": 186 | """ 187 | Similar to the module-level functions :meth:`match`, :meth:`search` 188 | and :meth:`sub`. 189 | Using methods is (much) more efficient if the same regex is applied to 190 | multiple strings. 191 | """ 192 | def sub( 193 | self, 194 | replace: AnyStr | Callable[["Match[AnyStr]"], AnyStr], 195 | string: AnyStr, 196 | count: int = 0, 197 | flags: int = 0, 198 | /, 199 | ) -> AnyStr: 200 | """ 201 | Similar to the module-level functions :meth:`match`, :meth:`search` 202 | and :meth:`sub`. 203 | Using methods is (much) more efficient if the same regex is applied to 204 | multiple strings. 205 | """ 206 | def split(self, string: AnyStr, max_split: int = -1, /) -> list[AnyStr]: 207 | """ 208 | Split a *string* using regex. If *max_split* is given, it specifies 209 | maximum number of splits to perform. Returns list of strings (there 210 | may be up to *max_split+1* elements if it's specified). 211 | """ 212 | 213 | class Match(Generic[AnyStr]): 214 | """ 215 | Match objects as returned by `match()` and `search()` methods, and passed 216 | to the replacement function in `sub()`. 217 | 218 | The name, `Match`, used for typing is not the same as the runtime name, `match` (note lowercase `m`). 219 | The reason for this difference is that the runtime uses `match` as both a class name and as a method name and 220 | this is not possible within code written entirely in Python and therefore not possible within typing code. 221 | """ 222 | 223 | def group(self, index: int, /) -> AnyStr: 224 | """ 225 | Return matching (sub)string. *index* is 0 for entire match, 226 | 1 and above for each capturing group. Only numeric groups are supported. 227 | """ 228 | def groups(self) -> tuple[AnyStr | Any, ...]: 229 | """ 230 | Return a tuple containing all the substrings of the groups of the match. 231 | 232 | Note: availability of this method depends on :term:`MicroPython port`. 233 | """ 234 | def start(self, index: int = ..., /) -> int: 235 | """ 236 | Return the index in the original string of the start or end of the 237 | substring group that was matched. *index* defaults to the entire 238 | group, otherwise it will select a group. 239 | 240 | Note: availability of these methods depends on :term:`MicroPython port`. 241 | """ 242 | def end(self, index: int = ..., /) -> int: 243 | """ 244 | Return the index in the original string of the start or end of the 245 | substring group that was matched. *index* defaults to the entire 246 | group, otherwise it will select a group. 247 | 248 | Note: availability of these methods depends on :term:`MicroPython port`. 249 | """ 250 | def span(self, index: int = ..., /) -> tuple[int, int]: 251 | """ 252 | Returns the 2-tuple ``(match.start(index), match.end(index))``. 253 | 254 | Note: availability of this method depends on :term:`MicroPython port`. 255 | """ 256 | -------------------------------------------------------------------------------- /micropython_typesheds/uselect.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | wait for events on a set of streams. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/select.rst. 6 | ==================================================== 7 | 8 | .. module:: select 9 | :synopsis: wait for events on a set of streams 10 | 11 | |see_cpython_module| :mod:`python:select`. 12 | 13 | This module provides functions to efficiently wait for events on multiple 14 | `streams ` (select streams which are ready for operations). 15 | """ 16 | 17 | __author__ = "Howard C Lovatt" 18 | __copyright__ = "Howard C Lovatt, 2020 onwards." 19 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 20 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 21 | 22 | from typing import Iterable, Any, Final, Iterator 23 | 24 | from uio import IOBase 25 | 26 | POLLIN: Final[int] = ... 27 | """Data available for reading.""" 28 | 29 | POLLOUT: Final[int] = ... 30 | """More data can be written.""" 31 | 32 | POLLHUP: Final[int] = ... 33 | """Socket is no longer connected.""" 34 | 35 | POLLERR: Final[int] = ... 36 | """Socket got an asynchronous error.""" 37 | 38 | def poll() -> "Poll": 39 | """ 40 | Create an instance of the Poll class. 41 | """ 42 | 43 | def select( 44 | rlist: Iterable[Any], 45 | wlist: Iterable[Any], 46 | xlist: Iterable[Any], 47 | timeout: int = -1, 48 | /, 49 | ) -> list[tuple[Any, int, Any, ...]]: 50 | """ 51 | Wait for activity on a set of objects. 52 | 53 | This function is provided by some MicroPython ports for compatibility 54 | and is not efficient. Usage of :class:`Poll` is recommended instead. 55 | """ 56 | 57 | class Poll: 58 | """ 59 | The name, `Poll`, used for typing is not the same as the runtime name, `poll` (note lowercase `p`). 60 | The reason for this difference is that the runtime uses `poll` as both a class name and as a method name and 61 | this is not possible within code written entirely in Python and therefore not possible within typing code. 62 | """ 63 | 64 | def register(self, obj: IOBase, eventmask: int = POLLIN | POLLOUT, /) -> None: 65 | """ 66 | Register `stream` *obj* for polling. *eventmask* is logical OR of: 67 | 68 | * ``select.POLLIN`` - data available for reading 69 | * ``select.POLLOUT`` - more data can be written 70 | 71 | Note that flags like ``select.POLLHUP`` and ``select.POLLERR`` are 72 | *not* valid as input eventmask (these are unsolicited events which 73 | will be returned from `poll()` regardless of whether they are asked 74 | for). This semantics is per POSIX. 75 | 76 | *eventmask* defaults to ``select.POLLIN | select.POLLOUT``. 77 | 78 | It is OK to call this function multiple times for the same *obj*. 79 | Successive calls will update *obj*'s eventmask to the value of 80 | *eventmask* (i.e. will behave as `modify()`). 81 | """ 82 | def unregister(self, obj: IOBase, /) -> None: 83 | """ 84 | Unregister *obj* from polling. 85 | """ 86 | def modify(self, obj: IOBase, eventmask: int, /) -> None: 87 | """ 88 | Modify the *eventmask* for *obj*. If *obj* is not registered, `OSError` 89 | is raised with error of ENOENT. 90 | """ 91 | def poll(self, timeout: int = -1, /) -> list[tuple[Any, int, Any, ...]]: 92 | """ 93 | Wait for at least one of the registered objects to become ready or have an 94 | exceptional condition, with optional timeout in milliseconds (if *timeout* 95 | arg is not specified or -1, there is no timeout). 96 | 97 | Returns list of (``obj``, ``event``, ...) tuples. There may be other elements in 98 | tuple, depending on a platform and version, so don't assume that its size is 2. 99 | The ``event`` element specifies which events happened with a stream and 100 | is a combination of ``select.POLL*`` constants described above. Note that 101 | flags ``select.POLLHUP`` and ``select.POLLERR`` can be returned at any time 102 | (even if were not asked for), and must be acted on accordingly (the 103 | corresponding stream unregistered from poll and likely closed), because 104 | otherwise all further invocations of `poll()` may return immediately with 105 | these flags set for this stream again. 106 | 107 | In case of timeout, an empty list is returned. 108 | 109 | .. admonition:: Difference to CPython 110 | :class: attention 111 | 112 | Tuples returned may contain more than 2 elements as described above. 113 | """ 114 | def ipoll( 115 | self, timeout: int = -1, flags: int = 0, / 116 | ) -> Iterator[tuple[Any, int, Any, ...]]: 117 | """ 118 | Like :meth:`poll.poll`, but instead returns an iterator which yields a 119 | `callee-owned tuple`. This function provides an efficient, allocation-free 120 | way to poll on streams. 121 | 122 | If *flags* is 1, one-shot behaviour for events is employed: streams for 123 | which events happened will have their event masks automatically reset 124 | (equivalent to ``poll.modify(obj, 0)``), so new events for such a stream 125 | won't be processed until new mask is set with `poll.modify()`. This 126 | behaviour is useful for asynchronous I/O schedulers. 127 | 128 | .. admonition:: Difference to CPython 129 | :class: attention 130 | 131 | This function is a MicroPython extension. 132 | """ 133 | -------------------------------------------------------------------------------- /micropython_typesheds/ussl.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | TLS/SSL wrapper for socket objects. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/ssl.rst. 6 | 7 | |see_cpython_module| :mod:`python:ssl`. 8 | 9 | This module provides access to Transport Layer Security (previously and 10 | widely known as “Secure Sockets Layer”) encryption and peer authentication 11 | facilities for network sockets, both client-side and server-side. 12 | 13 | .. admonition:: Difference to CPython 14 | :class: attention 15 | The CPython version of ``ssl`` uses ``SSLError``. 16 | This exception does NOT exist. Instead its base class, OSError, is used. 17 | """ 18 | 19 | __author__ = "Howard C Lovatt" 20 | __copyright__ = "Howard C Lovatt, 2020 onwards." 21 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 22 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 23 | 24 | from typing import Final 25 | 26 | from uio import StrOrBytesPath 27 | from usocket import Socket 28 | 29 | def wrap_socket( 30 | sock: Socket, 31 | server_side: bool = False, 32 | keyfile: StrOrBytesPath | None = None, 33 | certfile: StrOrBytesPath | None = None, 34 | cert_reqs: int = "CERT_NONE", 35 | ca_certs: str | None = None, 36 | do_handshake: bool = True, 37 | /, 38 | ) -> Socket: 39 | """ 40 | Takes a `stream` *sock* (usually socket.socket instance of ``SOCK_STREAM`` type), 41 | and returns an instance of ssl.SSLSocket, which wraps the underlying stream in 42 | an SSL context. Returned object has the usual `stream` interface methods like 43 | ``read()``, ``write()``, etc. 44 | A server-side SSL socket should be created from a normal socket returned from 45 | :meth:`~socket.socket.accept()` on a non-SSL listening server socket. 46 | 47 | - *do_handshake* determines whether the handshake is done as part of the ``wrap_socket`` 48 | or whether it is deferred to be done as part of the initial reads or writes 49 | (there is no ``do_handshake`` method as in CPython). 50 | For blocking sockets doing the handshake immediately is standard. For non-blocking 51 | sockets (i.e. when the *sock* passed into ``wrap_socket`` is in non-blocking mode) 52 | the handshake should generally be deferred because otherwise ``wrap_socket`` blocks 53 | until it completes. Note that in AXTLS the handshake can be deferred until the first 54 | read or write but it then blocks until completion. 55 | 56 | Depending on the underlying module implementation in a particular 57 | :term:`MicroPython port`, some or all keyword arguments above may be not supported. 58 | """ 59 | 60 | CERT_NONE: Final[int] = ... 61 | """ 62 | Supported values for *cert_reqs* parameter. 63 | """ 64 | 65 | CERT_OPTIONAL: Final[int] = ... 66 | """ 67 | Supported values for *cert_reqs* parameter. 68 | """ 69 | 70 | CERT_REQUIRED: Final[int] = ... 71 | """ 72 | Supported values for *cert_reqs* parameter. 73 | """ 74 | -------------------------------------------------------------------------------- /micropython_typesheds/ustruct.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | pack and unpack primitive data types. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/struct.rst. 6 | ===================================================== 7 | 8 | .. module:: struct 9 | :synopsis: pack and unpack primitive data types 10 | 11 | |see_cpython_module| :mod:`python:struct`. 12 | 13 | Supported size/byte order prefixes: ``@``, ``<``, ``>``, ``!``. 14 | 15 | Supported format codes: ``b``, ``B``, ``h``, ``H``, ``i``, ``I``, ``l``, 16 | ``L``, ``q``, ``Q``, ``s``, ``P``, ``f``, ``d`` (the latter 2 depending 17 | on the floating-point support). 18 | 19 | .. admonition:: Difference to CPython 20 | :class: attention 21 | 22 | Whitespace is not supported in format strings. 23 | """ 24 | 25 | __author__ = "Howard C Lovatt" 26 | __copyright__ = "Howard C Lovatt, 2020 onwards." 27 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 28 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 29 | 30 | from typing import Any 31 | 32 | from uio import AnyReadableBuf, AnyWritableBuf 33 | 34 | def calcsize(fmt: str | bytes, /,) -> int: 35 | """ 36 | Return the number of bytes needed to store the given *fmt*. 37 | """ 38 | 39 | def pack(fmt: str | bytes, /, *v: Any) -> bytes: 40 | """ 41 | Pack the values *v1*, *v2*, ... according to the format string *fmt*. 42 | The return value is a bytes object encoding the values. 43 | """ 44 | 45 | def pack_into( 46 | fmt: str | bytes, buffer: AnyWritableBuf, offset: int, /, *v: Any 47 | ) -> None: 48 | """ 49 | Pack the values *v1*, *v2*, ... according to the format string *fmt* 50 | into a *buffer* starting at *offset*. *offset* may be negative to count 51 | from the end of *buffer*. 52 | """ 53 | 54 | def unpack(fmt: str | bytes, data: AnyReadableBuf, /) -> tuple[Any, ...]: 55 | """ 56 | Unpack from the *data* according to the format string *fmt*. 57 | The return value is a tuple of the unpacked values. 58 | """ 59 | 60 | def unpack_from( 61 | fmt: str | bytes, data: AnyReadableBuf, offset: int = 0, / 62 | ) -> tuple[Any, ...]: 63 | """ 64 | Unpack from the *data* starting at *offset* according to the format string 65 | *fmt*. *offset* may be negative to count from the end of *buffer*. The return 66 | value is a tuple of the unpacked values. 67 | """ 68 | -------------------------------------------------------------------------------- /micropython_typesheds/usys.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | system specific functions. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/sys.rst. 6 | ======================================= 7 | 8 | .. module:: sys 9 | :synopsis: system specific functions 10 | 11 | |see_cpython_module| :mod:`python:sys`. 12 | """ 13 | 14 | __author__ = "Howard C Lovatt" 15 | __copyright__ = "Howard C Lovatt, 2020 onwards." 16 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 17 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 18 | 19 | from typing import Callable, Final, Literal, NoReturn 20 | 21 | from uio import IOBase 22 | 23 | class Implementation(tuple[str, tuple[int, int, int], int]): 24 | name: str 25 | version: tuple[int, int, int] 26 | mpy: int 27 | 28 | class ModuleType: 29 | __class__: str 30 | __name__: str 31 | 32 | def exit(retval: object = 0, /) -> NoReturn: 33 | """ 34 | Terminate current program with a given exit code. Underlyingly, this 35 | function raise as `SystemExit` exception. If an argument is given, its 36 | value given as an argument to `SystemExit`. 37 | """ 38 | 39 | def atexit(func: Callable[[], None] | None, /) -> Callable[[], None] | None: 40 | """ 41 | Register *func* to be called upon termination. *func* must be a callable 42 | that takes no arguments, or ``None`` to disable the call. The ``atexit`` 43 | function will return the previous value set by this function, which is 44 | initially ``None``. 45 | 46 | .. admonition:: Difference to CPython 47 | :class: attention 48 | 49 | This function is a MicroPython extension intended to provide similar 50 | functionality to the :mod:`atexit` module in CPython. 51 | """ 52 | 53 | def print_exception(exc: BaseException, file: IOBase[str] = "stdout", /) -> None: 54 | """ 55 | Print exception with a traceback to a file-like object *file* (or 56 | `sys.stdout` by default). 57 | 58 | .. admonition:: Difference to CPython 59 | :class: attention 60 | 61 | This is simplified version of a function which appears in the 62 | ``traceback`` module in CPython. Unlike ``traceback.print_exception()``, 63 | this function takes just exception value instead of exception type, 64 | exception value, and traceback object; *file* argument should be 65 | positional; further arguments are not supported. CPython-compatible 66 | ``traceback`` module can be found in `micropython-lib`. 67 | 68 | .. function:: settrace(tracefunc) 69 | 70 | Enable tracing of bytecode execution. For details see the `CPython 71 | documentaion `_. 72 | 73 | This function requires a custom MicroPython build as it is typically not 74 | present in pre-built firmware (due to it affecting performance). The relevant 75 | configuration option is *MICROPY_PY_SYS_SETTRACE*. 76 | """ 77 | 78 | argv: Final[list[str]] = ... 79 | """ 80 | A mutable list of arguments the current program was started with. 81 | """ 82 | 83 | byteorder: Final[Literal["little", "big"]] = ... 84 | """ 85 | The byte order of the system (``"little"`` or ``"big"``). 86 | """ 87 | 88 | implementation: Final[Implementation] = ... 89 | """ 90 | Object with information about the current Python implementation. For 91 | MicroPython, it has following attributes: 92 | 93 | * *name* - string "micropython" 94 | * *version* - tuple (major, minor, micro), e.g. (1, 7, 0) 95 | 96 | This object is the recommended way to distinguish MicroPython from other 97 | Python implementations (note that it still may not exist in the very 98 | minimal ports). 99 | 100 | .. admonition:: Difference to CPython 101 | :class: attention 102 | 103 | CPython mandates more attributes for this object, but the actual useful 104 | bare minimum is implemented in MicroPython. 105 | """ 106 | 107 | maxsize: Final[int] = ... 108 | """ 109 | Maximum value which a native integer type can hold on the current platform, 110 | or maximum value representable by MicroPython integer type, if it's smaller 111 | than platform max value (that is the case for MicroPython ports without 112 | long int support). 113 | 114 | This attribute is useful for detecting "bitness" of a platform (32-bit vs 115 | 64-bit, etc.). It's recommended to not compare this attribute to some 116 | value directly, but instead count number of bits in it:: 117 | 118 | bits = 0 119 | v = sys.maxsize 120 | while v: 121 | bits += 1 122 | v >>= 1 123 | if bits > 32: 124 | # 64-bit (or more) platform 125 | ... 126 | else: 127 | # 32-bit (or less) platform 128 | # Note that on 32-bit platform, value of bits may be less than 32 129 | # (e.g. 31) due to peculiarities described above, so use "> 16", 130 | # "> 32", "> 64" style of comparisons. 131 | """ 132 | 133 | modules: Final[dict[str, ModuleType]] = ... 134 | """ 135 | Dictionary of loaded modules. On some ports, it may not include builtin 136 | modules. 137 | """ 138 | 139 | path: Final[list[str]] = ... 140 | """ 141 | A mutable list of directories to search for imported modules. 142 | 143 | .. admonition:: Difference to CPython 144 | :class: attention 145 | 146 | On MicroPython, an entry with the value ``".frozen"`` will indicate that import 147 | should search :term:`frozen modules ` at that point in the search. 148 | If no frozen module is found then search will *not* look for a directory called 149 | ``.frozen``, instead it will continue with the next entry in ``sys.path``. 150 | """ 151 | 152 | platform: Final[str] = ... 153 | """ 154 | The platform that MicroPython is running on. For OS/RTOS ports, this is 155 | usually an identifier of the OS, e.g. ``"linux"``. For baremetal ports it 156 | is an identifier of a board, e.g. ``"pyboard"`` for the original MicroPython 157 | reference board. It thus can be used to distinguish one board from another. 158 | If you need to check whether your program runs on MicroPython (vs other 159 | Python implementation), use `sys.implementation` instead. 160 | """ 161 | 162 | stderr: Final[IOBase[str]] = ... 163 | """ 164 | Standard error `stream`. 165 | """ 166 | 167 | stdin: Final[IOBase[str]] = ... 168 | """ 169 | Standard input `stream`. 170 | """ 171 | 172 | stdout: Final[IOBase[str]] = ... 173 | """ 174 | Standard output `stream`. 175 | """ 176 | 177 | version: Final[str] = ... 178 | """ 179 | Python language version that this implementation conforms to, as a string. 180 | """ 181 | 182 | version_info: Final[tuple[int, int, int]] = ... 183 | """ 184 | Python language version that this implementation conforms to, as a tuple of ints. 185 | 186 | .. admonition:: Difference to CPython 187 | :class: attention 188 | 189 | Only the first three version numbers (major, minor, micro) are supported and 190 | they can be referenced only by index, not by name. 191 | """ 192 | -------------------------------------------------------------------------------- /micropython_typesheds/uzlib.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | zlib decompression. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/zlib.rst. 6 | ================================= 7 | 8 | .. module:: zlib 9 | :synopsis: zlib decompression 10 | 11 | |see_cpython_module| :mod:`python:zlib`. 12 | 13 | This module allows to decompress binary data compressed with 14 | `DEFLATE algorithm `_ 15 | (commonly used in zlib library and gzip archiver). Compression 16 | is not yet implemented. 17 | """ 18 | 19 | __author__ = "Howard C Lovatt" 20 | __copyright__ = "Howard C Lovatt, 2020 onwards." 21 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 22 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 23 | 24 | from uio import IOBase 25 | 26 | def decompress(data: bytes, wbits: int = 0, bufsize: int = 0, /) -> bytes: 27 | """ 28 | Return decompressed *data* as bytes. *wbits* is DEFLATE dictionary window 29 | size used during compression (8-15, the dictionary size is power of 2 of 30 | that value). Additionally, if value is positive, *data* is assumed to be 31 | zlib stream (with zlib header). Otherwise, if it's negative, it's assumed 32 | to be raw DEFLATE stream. *bufsize* parameter is for compatibility with 33 | CPython and is ignored. 34 | """ 35 | 36 | class DecompIO(IOBase[bytes]): 37 | """ 38 | Steam wrapper that decompresses a given stream containing zlib compressed data. 39 | """ 40 | 41 | def __init__(self, stream: IOBase[bytes], wbits: int = 0, /): 42 | """ 43 | Create a `stream` wrapper which allows transparent decompression of 44 | compressed data in another *stream*. This allows to process compressed 45 | streams with data larger than available heap size. In addition to 46 | values described in :func:`decompress`, *wbits* may take values 47 | 24..31 (16 + 8..15), meaning that input stream has gzip header. 48 | 49 | .. admonition:: Difference to CPython 50 | :class: attention 51 | 52 | This class is MicroPython extension. It's included on provisional 53 | basis and may be changed considerably or removed in later versions. 54 | """ 55 | -------------------------------------------------------------------------------- /micropython_typesheds/wipy.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | WiPy specific features. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/wipy.rst. 6 | ************************************* 7 | 8 | .. module:: wipy 9 | :synopsis: WiPy specific features 10 | 11 | The ``wipy`` module contains functions to control specific features of the 12 | WiPy, such as the heartbeat LED. 13 | """ 14 | 15 | __author__ = "Howard C Lovatt" 16 | __copyright__ = "Howard C Lovatt, 2020 onwards." 17 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 18 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 19 | 20 | from typing import overload 21 | @overload 22 | def heartbeat(enable: bool, /) -> None: 23 | """ 24 | Get or set the state (enabled or disabled) of the heartbeat LED. Accepts and 25 | returns boolean values (``True`` or ``False``). 26 | """ 27 | 28 | @overload 29 | def heartbeat() -> bool: 30 | """ 31 | Get or set the state (enabled or disabled) of the heartbeat LED. Accepts and 32 | returns boolean values (``True`` or ``False``). 33 | """ 34 | -------------------------------------------------------------------------------- /micropython_typesheds/zlib.pyi: -------------------------------------------------------------------------------- 1 | """ 2 | zlib decompression. 3 | 4 | Descriptions taken from: 5 | https://raw.githubusercontent.com/micropython/micropython/master/docs/library/zlib.rst. 6 | ================================= 7 | 8 | .. module:: zlib 9 | :synopsis: zlib decompression 10 | 11 | |see_cpython_module| :mod:`python:zlib`. 12 | 13 | This module allows to decompress binary data compressed with 14 | `DEFLATE algorithm `_ 15 | (commonly used in zlib library and gzip archiver). Compression 16 | is not yet implemented. 17 | """ 18 | 19 | __author__ = "Howard C Lovatt" 20 | __copyright__ = "Howard C Lovatt, 2020 onwards." 21 | __license__ = "MIT https://opensource.org/licenses/MIT (as used by MicroPython)." 22 | __version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver 23 | 24 | from uio import IOBase 25 | 26 | def decompress(data: bytes, wbits: int = 0, bufsize: int = 0, /) -> bytes: 27 | """ 28 | Return decompressed *data* as bytes. *wbits* is DEFLATE dictionary window 29 | size used during compression (8-15, the dictionary size is power of 2 of 30 | that value). Additionally, if value is positive, *data* is assumed to be 31 | zlib stream (with zlib header). Otherwise, if it's negative, it's assumed 32 | to be raw DEFLATE stream. *bufsize* parameter is for compatibility with 33 | CPython and is ignored. 34 | """ 35 | 36 | class DecompIO(IOBase[bytes]): 37 | """ 38 | Steam wrapper that decompresses a given stream containing zlib compressed data. 39 | """ 40 | 41 | def __init__(self, stream: IOBase[bytes], wbits: int = 0, /): 42 | """ 43 | Create a `stream` wrapper which allows transparent decompression of 44 | compressed data in another *stream*. This allows to process compressed 45 | streams with data larger than available heap size. In addition to 46 | values described in :func:`decompress`, *wbits* may take values 47 | 24..31 (16 + 8..15), meaning that input stream has gzip header. 48 | 49 | .. admonition:: Difference to CPython 50 | :class: attention 51 | 52 | This class is MicroPython extension. It's included on provisional 53 | basis and may be changed considerably or removed in later versions. 54 | """ 55 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from os import listdir 2 | 3 | import setuptools 4 | 5 | 6 | def read_text(file_name: str) -> str: 7 | with open(file_name, "r") as f: 8 | return f.read() 9 | 10 | 11 | setuptools.setup( 12 | name="micropython-typesheds", 13 | version="7.5.3", 14 | url="https://github.com/hlovatt/PyBoardTypeshed", 15 | license="MIT License", # Can only have one line `license`; setuptools bug. 16 | author="Howard C Lovatt", 17 | author_email="howard.lovatt@gmail.com", 18 | description="Typesheds (a.k.a.: interface stubs, `pyi` files, and type hints) for MicroPython.", 19 | long_description=read_text("README.md"), 20 | long_description_content_type="text/markdown", 21 | py_modules=["micropython_typesheds"], 22 | platforms=["any"], 23 | python_requires=">=3.8", 24 | classifiers=[ # These must have a space either side of `::`, despite PyPI website giving them without! 25 | "Intended Audience :: Developers", 26 | "Programming Language :: Python :: Implementation :: MicroPython", 27 | "License :: OSI Approved :: MIT License", 28 | "Operating System :: OS Independent", 29 | ], 30 | ) 31 | --------------------------------------------------------------------------------