Josverl / micropython-stubs

Stubs of most MicroPython ports, boards and versions to make writing code that much simpler.
https://micropython-stubs.readthedocs.io
MIT License
133 stars 21 forks source link

rp2: micropython.const return value is not int #721

Closed mishal closed 1 year ago

mishal commented 1 year ago

The return value of micropython.const for rp2 port (I did not not check other ports) is wrong:

def const(expr) -> int:

Micropython allows to declare also string, tuple,... if built with enabled flags MICROPY_COMP_CONST and MICROPY_COMP_CONST_TUPLE, enabled by default in rp2 build (by MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES flag)

from micropython import const

_INT = const(123)
_STR = const("str")
_BYTES = const(b"bytes")
_TUPLE = const((_INT, _STR, _BYTES))
_TUPLE2 = const((None, False, True, ..., (), _TUPLE))

See the test in micropython source:

https://github.com/micropython/micropython/blob/master/tests/micropython/const_alltypes.py

Josverl commented 1 year ago

Thanks for the report,

I'll update it to `Union[int,str,bytes,Tuple] That way it will not be wrong, even if it doesn't get the details of a specific port/board/build

Josverl commented 1 year ago

@mishal , just published an update to the stubs for versions 1.19.1 and 1.20.0 image @all-contributors please add @mishal for stubs and bugs

allcontributors[bot] commented 1 year ago

@Josverl

I couldn't determine any contributions to add, did you specify any contributions? Please make sure to use valid contribution names.

I've put up a pull request to add @mishal! :tada: