Skip to content

Releases: Josverl/micropython-stubs

Update micropython boards stubs to v1.24.1

05 Feb 22:32
Compare
Choose a tag to compare

The new stubs contain additional type information for parameters and return types.
The depend on new functionality added in micropython-stdlib-stubs==1.24.1

esp32:

  • micropython-esp32-stubs v1.24.1.post1
  • micropython-esp32-esp32_generic-stubs v1.24.1.post1
  • micropython-esp32-esp32_generic_c6-stubs v1.24.1.post1
  • micropython-esp32-esp32_generic_s3-stubs v1.24.1.post1

rp2:

  • micropython-rp2-stubs v1.24.1.post1
  • micropython-rp2-arduino_nano_rp2040_connect-stubs v1.24.1.post1
  • micropython-rp2-rpi_pico-stubs v1.24.1.post1
  • micropython-rp2-rpi_pico2-stubs v1.24.1.post1
  • micropython-rp2-rpi_pico_w-stubs v1.24.1.post1

samd:

  • micropython-samd-stubs v1.24.1.post1
  • micropython-samd-seeed_wio_terminal-stubs v1.24.1.post1

stm32:

  • micropython-stm32-stubs v1.24.1.post1
  • micropython-stm32-pybv11-stubs v1.24.1.post1

Relevant and related updates in the MicroPython-stubs repo

reference-stubs

The reference stubs themselves are created using the stubber tool to combine and merge infromation from the following sources.

  • The v1.24.1 docstubs , generated from the micropython library documentation.
  • PyBoardTypeshed created by Howard Lovatt
  • PoC of type hints for the RP2 PIO assembler by Jos Verlinde
  • Stubs for modules lacking documentation such as _threads and pars of hashlib and random
  • A new _mpy_shed module has been created based on the _typeshed module. This allows the different micropython stub modules to refer to common types and constants, that are different than the standard CPython types and constants.

micropython-stdlib-stubs

The stubs for the async and uasyncio modules of earlier versions had many issues.
In this version, the stunb for asyncio are based on typeshed stdlib.asyncio stub, that has been tuned specifically for micropython by removing the features and functionality that is not available in MicroPython. However the Doc strings are taken from doc-stubs, to keep them in sync in line with the MicroPython Documentaion

For distribution the _mpy_shed module is added to the micropython-stdlib-stubs package.

Significant effort has been done to improve the ability for mypy to perform type checking on the micropython code,
while maintaining compatibility with the way the micropython documentation, is structured.
There are further improvement to be made, but this is a significant step forward for mypy users.

While parts of the stdlib modules are hand-edited, they can be updated by running the python build.py.
This functionality has not been merged into the stubber tool at this time.

Know limitations

the stubs are not perfect, I am aware of a number of problems yet to solve.
Known Limitations v1.24.1

MicroPython-stdlib-stubs 1.24.1 : Improved Type Checking, Documentation Sync, and _mpy_shed Integration

05 Feb 22:06
Compare
Choose a tag to compare

The stubs for the async and uasyncio modules of earlier versions had many issues.
In this version, the stunb for asyncio are based on typeshed stdlib.asyncio stub, that has been tuned specifically for micropython by removing the features and functionality that is not available in MicroPython. However the Doc strings are taken from doc-stubs, to keep them in sync in line with the MicroPython Documentaion

For distribution the _mpy_shed module is added to the micropython-stdlib-stubs package.

Significant effort has been done to improve the ability for mypy to perform type checking on the micropython code,
while maintaining compatibility with the way the micropython documentation, is structured.
There are further improvement to be made, but this is a significant step forward for mypy users.

While parts of the stdlib modules are hand-edited, they can be updated by running the python build.py.
This functionality has not been merged into the stubber tool at this time.

The stdlib stubs are now build using uv which uses hatchling

v1.1.2-micropython-stdlib

28 Jan 15:51
Compare
Choose a tag to compare

What's Changed

Remove module top-level attributes from sys, collections, io and ssl modules

Note that while in this release the top level attributes are limited to those available in MicroPython,
the same is not yet implemented for top level classes and functions/methods

Full Changelog: v1.1.1-micropython-stdlib...v1.1.2-micropython-stdlib

Thanks to @paulober for reporting.

Stubs for MicroPython v1.22.0

03 Jan 15:19
Compare
Choose a tag to compare

This release updates the majority of the stubs distribution packages to match the v1.22.0 release of MicroPython

Ports and boards included in this release:

  • rp2: based on RPI_PIO_W and RPI_PICO,, ARDUINO_NANO_RP2040_CONNECT, PIMORONI_PICOLIPO_16MB
  • esp32: based on ESP32-GENERIC-SPIRAM
  • esp32S3: based on ESP32_GENERIC_S3
  • samd: based on SEEED_WIO_TERMINAL
  • stm32: based on PYBV11

v1.22.0 Stubs for Unix, Windows and Webassembly will be published at a later time.

Note: The esp8266 stubs cannot be updated currently due to device constraints

Update micropython-stdlib

26 Dec 13:18
Compare
Choose a tag to compare

Functional changes:

Typechecking now works correctly for namedtuples.

No changes are needed ,
you may be able to remove some # type: ignore comments if you used them to suppress false-positive typechecking errors.

Details:

This release is focused on micropython-stdlib-stubs and the packages that depend on it.

  • Rebuilt micropython-stdlib-stubs based on a recent version of the typeshed stdlib
  • Created a script to automate the rebuild, and allow future updates
  • Updated micropython-*-stubs to use the new micropython-stdlib-stubs
  • Updated micrpython-stubber with new functionality to automate this approach
  • additional stub-QA tests have been added to pytest and the CI workflow

The stdlib/collections module needed to be updated with MicroPython specific configuration, as the typecheckers have special handling for namedtuple that only works if it is decalred in stdlib/collections, and not in other modules.
In order to make this work :

  • the micropython-stdlib-stubs package now includes a copy of the stdlib/collections stub.
    • this has been updated with micropython specific docstring
    • __all__ has been changed to only export micropython supported types
  • the micropython-*-stubs packages:
    • no longer include a copy of the collections.pyi stub
    • include a shim stub for ucollections.pyi that imports * from collections
    • have been updated micropython-stdlib-stubs^=1.1.0.

micropython-*-stubs that have been updated to use the new micropython-stdlib-stubs are:

  • v1.19.1.*
  • v1.20.0.*
  • v1.21.0.*
  • prerelease a.k.a. latest

Thanks to North101 for reporting.

v1.21.0-webassembly

04 Dec 07:49
Compare
Choose a tag to compare

New and updated packages published to PyPi

(.post1 indicates a new package, all others are updates)

Micropython Version Published Packages Post Version Package
v1.21.0
micropython-webassembly-stubs 1.21.0.post1 PyPI

The webassembly is based of stubs generated by running the webassembly version on NodeJS.
The supported and available modules are assumed to be the same for the WEB and the NODE variants

stubber_v1.15.0

18 Nov 21:09
Compare
Choose a tag to compare

New and updated packages published to PyPi

(.post1 indicates a new package, all others are updates)

Micropython Version Published Packages Post Version
v1.21.0
micropython-esp32-stubs 1.21.0.post3
micropython-esp32-esp32_generic-stubs 1.21.0.post1
micropython-rp2-stubs 1.21.0.post1
micropython-rp2-rpi_pico-stubs 1.21.0.post2
micropython-rp2-rpi_pico_w-stubs 1.21.0.post2
micropython-samd-stubs 1.21.0.post1
micropython-samd-seeed_wio_terminal-stubs 1.21.0.post2
micropython-stm32-stubs 1.21.0.post1
micropython-stm32-pybv11-stubs 1.21.0.post2
v1.20.0
micropython-esp32-stubs 1.20.0.post4
micropython-esp32-generic_ota-stubs 1.20.0.post1
micropython-esp32-generic_s3-stubs 1.20.0.post1
micropython-rp2-stubs 1.20.0.post4
micropython-rp2-pico-stubs 1.20.0.post4
micropython-rp2-pico_w-stubs 1.20.0.post4
micropython-samd-stubs 1.20.0.post1
micropython-samd-adafruit_feather_m4_express-stubs 1.20.0.post3
micropython-samd-adafruit_itsybitsy_m4_express-stubs 1.20.0.post3
micropython-samd-minisam_m4-stubs 1.20.0.post3
micropython-samd-seeed_wio_terminal-stubs 1.20.0.post4
micropython-stm32-stubs 1.20.0.post4
micropython-stm32-pybv11-stubs 1.20.0.post5
v1.19.1
micropython-esp32-stubs 1.19.1.post15
micropython-esp32-generic_s3-stubs 1.19.1.post1
micropython-esp32-generic_spiram-stubs 1.19.1.post1
micropython-esp32-um_tinypico-stubs 1.19.1.post8
micropython-esp8266-stubs 1.19.1.post12
micropython-rp2-stubs 1.19.1.post14
micropython-stm32-stubs 1.19.1.post12

Improvement in frozen stubs
Some of the module stubs are generated based on the python modules.
There usually contain little or no docstring information, while the documentation does have that infromation

The stubber tool has been updated to to merge the information from the documentation into these frozen stubs, providing combined and richer information where the two can be matched.

Enrich both Python and C modules
Some of the modules are built partly in (frozen) Python and partly in C(++). by convention the C part of the module is prefixes with an _
an example are the rp2 and the _rp2 modules where the classes and methos of both have been documented in a single document rp2/.st
The documentation merge process will now also enrich the _rp2.pyi and similar named stub files

Quality Testing.
In order to keep an eye on quality, and find cases where the stubs prove incorrect type-hints,
I have setup pytest with some custom configuration to track the quality.
Due to the diversity of features and functionality across ports, boards and versions this should help spot where stubs are not providing the expected/desired results.