Typeshed (type hint interface stubs .pyi
) for a
PyBoard,
i.e. type hints and documentation for functions, classes, and constants
for MicroPython.
These typesheds are useful for IDEs that understand type hints,
like PyCharm and VSCode, and for IDE plugins like the PyCharm's
MicroPython plugin.
Once installed, see next section, the typesheds offer:
-
Code completion (in this case prompting completion for
pyb
):
-
Rich help text (in this case constructor for
LCD160CR
showing types and overloads as well as description):
-
Typos (in this case
colour
instead ofcolor
; error can be avoided by using code completion, see point 1 above):
There are three ways of installing the Typesheds:
hopefully in the future via plugins,
manually install in IDE, and copy the .pyi
files into a project.
Currently, August 2020, have pull request in with PyCharm Micropython plugin to add these typesheds. If JetBrains add these typesheds it will be the easiest solution and also the typesheds will get updated everytime the plugin is updated. The other options, below, unfortunately require manual updating and are more involved (though not difficult).
Note: The following procedure, below, only needs to be done for one project; after which all projects using the MicroPython plugin will pick up the typesheds:
-
Install the MicroPython plugin (also see section "Via an IDE plugin" above).
-
Enable the plugin for the project (two stages in project preferences/options: add the plugin to the project and then select options in the plugin):
-
Unpack the ZIP file.
-
Drag (or copy and past) the
.pyi
(only) files into the Micropython Plugin (.pyi
files normally go intoMicropython -> micropython
but the files who's name begin withu
go intoMicropython -> stdlib
):
-
Disable and re-enable plugin by going to preferences/options un-tick Micropython support and Apply then re-tick MicroPython support and OK (so that it picks up the changes):
-
Plugin now has typesheds from this repository and those provided by the Micropython plugin:
Note: The following procedure, below, needs to be done for all projects:
-
Unpack the ZIP file.
The typesheds are generated by
https://github.com/hlovatt/PyBoardTypeshedGenerator
from the MicroPython .rst
doc files.
The philosophy of generating the typesheds is to take a superset of what is
in the docs and what is listed by the dir
command on a PyBoard
(the docs and dir
don't agree!).
An example of the dir
command having more information than the docs is
the docs for pyb.Pin
mentions board
and cpu
classes
and implies they contain declarations of available Pin
s;
dir(pyb.Pin.cpu)
on the other hand lists the Pin
s,
therefore the generated typeshed contains board
and cpu
with Pin
definitions.
Note: In the descriptions above, PyBoard means PyBoard V1.1, not any other PyBoard. Though the other PyBoards are similar and therefore the typesheds are still useful.