Replies: 1 comment 1 reply
-
These proposals seem very logical to me, I think they're good clear suggestions. Looping in the likes of pypi is sensible to broaden the appeal too! I do very much like the idea of being able to include ports in this, I presume long-term this could mean that just one stubs package could be built/distributed that covered all the ports? Similarly version support could work towards this goal though I can also see that making the stubs code ever-increasingly complex; perhaps keeping it one package for one version of micropython makes more sense here. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
I intend to propose the below the the Python Typing community and council, as I run into challenges with defining stubs for micropython that are both detailed and correct across the different ports of MicroPython, and wanted to check in for feedback , and possibly support, in this community first.
My questions to this forum:
Related discussions :
Introduction
The Python typing community has made significant strides in improving type-checking capabilities across various Python implementations. However, there is a growing need to address the unique requirements of MicroPython, especially in distinguishing MicroPython-specific code and differentiating type stubs for various ports. This proposal aims to introduce enhancements to type-checkers to better support MicroPython and its diverse platform values.
Current platform checks by type checkers are intentionally limited in the typing spec: https://typing.python.org/en/latest/spec/directives.html#version-and-platform-checking
Current Challenges
MicroPython utilizes approximately 12 additional sys.platform values, such as esp32, esp8266, mimxrt, nrf, renesas-ra, rp2, samd, stm32, unix, webassembly, windows, and zephyr. Currently, developers need to write long and repetitive boilerplate code to handle these platform checks, which is both cumbersome and error-prone.
For example:
Additionally, while MicroPython defines
sys.implementation.name
as 'micropython', a condfitional such asif sys.implementation.name == "micropython":
does not work as expected with type-checkers as the use of this attribute is not part of the typing spec.Proposed Solution
To address these challenges, I propose the following enhancements to the Python typing specification and type-checkers:
Support using
sys.implementation.name
in type checkers:Ensure that type-checkers correctly process sys.implementation.name for MicroPython, allowing type stub authors to use
if sys.implementation.name == "micropython":
orif sys.implementation.name == "pypy":
to simplify stub authoring.Enhanced sys.platform Checks:
Introduce support for more detailed sys.platform checks, allowing patterns such as
if sys.platform in ('esp32', 'esp8266', 'mimxrt', 'nrf', 'renesas-ra', 'rp2', 'samd', 'stm32', 'unix', 'webassembly', 'windows', 'zephyr'):
. This would significantly reduce boilerplate code and improve readability.Benefits
Implementing these enhancements will provide several benefits:
Beta Was this translation helpful? Give feedback.
All reactions