Skip to content

Conversation

@massimosala
Copy link
Owner

Hi

Please see
micropython#11735

The official page
https://docs.micropython.org/en/latest/genrst/builtin_types.html#float
should be updated about the different result of

float('_')

(and eventually other inconsistencies) between Python and MicroPython.

jepler and others added 29 commits September 28, 2025 23:23
Signed-off-by: Jeff Epler <jepler@unpythonic.net>
The check for 'fits in a small int' is specific to the 31-bit int of other
object representations.

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This showed up some interesting errors (hopefully all fixed now).

Signed-off-by: Jeff Epler <jepler@unpythonic.net>
This change follows CPython behaviour, allowing use of:

    from instance import method

to import a bound method from a class instance, eg registered via
setting `sys.modules["instance"] = instance`.

Admittedly this is probably a very rarely used pattern in Python, but it
resolves a long standing comment about whether or not this is actually
possible (it turns out it is possible!).  A test is added to show how it
works.

The main reason for this change is to fix a problem with imports in the
webassembly port: prior to this fix, it was not possible to do `from
js_module import function`, where `js_module` is a JavaScript object
registered to be visible to Python through the webassembly API function
`registerJsModule(js_module)`.  But now with this fix that is possible.

Signed-off-by: Damien George <damien@micropython.org>
This tests `from mod import foo` where `mod` is a module registered using
the webassembly API `registerJsModule(mod)`, and where `foo` is a
JavaScript function.  Prior to the parent commit, this would fail.

Signed-off-by: Damien George <damien@micropython.org>
`cur_task` can never be `None` in the webassembly port, so test it for the
top-level task to see if an asyncio Task is active or not.

This fixes a bug where await'ing on a JavaScript awaitable that ends up
raising an error would not be caught on the Python side.  The fix here
makes sure it is caught by Python, as tested by the new test.

Signed-off-by: Damien George <damien@micropython.org>
Prior to this fix, if a JavaScript thenable/Promise that was part of an
asyncio chain was rejected it would be ignored because the Python-side
`ThenableEvent` did not register a handler for the rejection.

That's fixed by this commit, and a corresponding test added.

Signed-off-by: Damien George <damien@micropython.org>
The problem with ESP board spurious reset happens at disconnect time on
Windows (clearing DTR before RTS triggers a reset).

Previous workarounds tried to detect possible ESP boards and apply the
correct DTR and RTS settings when opening the port.

Instead, we can manually clear RTS before closing the port and thereby
avoid the reset issue. Opening the port can keep the default behaviour
(RTS & DTR both set).

close() is called from a finally block in the mpremote main module
(via do_disconnect()) - so this should always happen provided the Python
process isn't terminated by the OS.

One additional workaround is needed to prevent a spurious reset first time
a Silicon Labs CP210x-based ESP board is opened by mpremote after
enumeration.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Most MCUs apart from Cortex-M0 with Thumb 1 have an instruction
for computing the "high part" of a multiplication (e.g., the upper
32 bits of a 32x32 multiply).

When they do, gcc uses this to implement a small and fast
overflow check using the __builtin_mul_overflow intrinsic, which
is preferable to the guard division method previously used in smallint.c.

However, in contrast to the previous mp_small_int_mul_overflow
routine, which checks that the result fits not only within mp_int_t
but is SMALL_INT_FITS(), __builtin_mul_overflow only checks for
overflow of the C type. As a result, a slight change in the code
flow is needed for MP_BINARY_OP_MULTIPLY.

Other sites using mp_small_int_mul_overflow already had the
result value flow through to a SMALL_INT_FITS check so they didn't
need any additional changes.

Do similarly for the _ll and _ull multiply overflows checks.

Signed-off-by: Jeff Epler <jepler@gmail.com>
Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
NameError occurred when trying to access the argument of RTC.wakeup()
callback because the callback argument is not initialized.  To fix this
issue, this commit passes EXTI_RTC_WAKEUP to callback argument.

This is equivalent behavior with ExtInt callback.

Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This catches cases where the return type is not a small int, eg it could be
a string, or even a big integer.

Signed-off-by: Damien George <damien@micropython.org>
These tests cannot pass when using `--via-mpy`.

Signed-off-by: Damien George <damien@micropython.org>
Currently testing on the unix port with `--via-mpy` only runs tests in the
`basics`, `float` and `micropython` test directories.

This commit removes that restriction and now runs `--via-mpy` tests using
all possible test directories.  This improves test coverage.

Signed-off-by: Damien George <damien@micropython.org>
Running the tests now requires CPython 3.8.2 or newer, which was
released February 2020 and should be widely available.

A few examples of features that were previously not supported by CPython,
but which are now:
- %-formatting for bytes and bytearray (PEP 461), CPython 3.5
- annotated variables (PEP 526), CPython 3.6
- assignment expressions (PEP 572), CPython 3.8

Note that `basics/fun_code_full.py.exp` is added here because that requires
CPython 3.10 or newer.

Signed-off-by: Damien George <damien@micropython.org>
Changes here are:
- Split out string format module sub-test to a separate test file, so it
  can be skipped on targets that don't have str% capabilities.
- Print the whole type instead of `.__name__` to support targets that don't
  have `.__name__` enabled (this still tests the same thing).
- Print `RuntimeError` exception message to be sure the correct exception
  is being raised.

This test now runs on unix and zephyr minimal configurations.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
This skips some additional tests that use slice, and no longer skips
`basics/string_format_modulo.py` which doesn't actually use slice (but
`float/string_format_modulo.py` does).

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
So it can be used on targets without set enabled (or at least not raise a
SyntaxError when compiling it).

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
This is needed by the zephyr port.  Combining it with the existing
`MICROPY_PY_MATH_POW_FIX_NAN` option should be safe, and eliminates the
need for a separate option.

Signed-off-by: Damien George <damien@micropython.org>
This is needed because zephyr incorrectly has `pow(-1, NaN) = 1`.

Signed-off-by: Damien George <damien@micropython.org>
With the recent improvements to the test suite, and fixes for `pow`, the
full test suite can now be run (and appropriate tests will be automatically
skipped).

Signed-off-by: Damien George <damien@micropython.org>
pi-anl and others added 30 commits November 22, 2025 00:06
When `MICROPY_PYEXEC_COMPILE_ONLY` is enabled and the global
`mp_compile_only` is True, code is compiled but not executed.

Also add comprehensive tests for compile-only functionality covering both
successful compilation and syntax error detection.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Provides support for command line `-X compile-only` option on unix port.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add a general normalize_newlines() function that handles newline variations
(\\r\\r\\n, \\r\\n) to \\n while preserving literal \\r characters that are
part of test content.

This provides a robust solution for cross-platform test compatibility,
particularly addressing PTY double-newline issues that can occur with some
terminal implementations.

The function is applied to all test output before comparison, eliminating
platform-specific newline issues.

Includes a unit test to verify the normalization behavior.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Consolidates file and string execution to use the standard pyexec interface
for consistency with other ports.

Simplify execute_from_lexer for remaining usage: Remove unused LEX_SRC_VSTR
and LEX_SRC_FILENAME cases, keeping only LEX_SRC_STR for REPL and
LEX_SRC_STDIN for stdin execution.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
This ensures that ctrl-C works on the unix port when executing code at the
REPL.

Signed-off-by: Damien George <damien@micropython.org>
Enable `MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING` to propagate `sys.exit()`
exit codes properly. Update `convert_pyexec_result()` to handle return
values where pyexec returns the exit code with `PYEXEC_FORCED_EXIT` flag
set for `SystemExit`. Extract the exit code from the lower 8 bits when the
flag is set, otherwise return as-is (0 for success, 1 for exception).

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
When `MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING` is enabled, `SystemExit`
now sets the `PYEXEC_FORCED_EXIT` flag in addition to the exit code. This
allows the REPL to properly detect and exit when SystemExit is raised,
while still preserving the exit code in the lower bits.

Fixes `repl_lock.py` test which expects REPL to exit on `SystemExit`.

Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
Add wrapper macros that by default expand to the callback name.
Users can define this macro to add a prefix (e.g., mp_) to
callback implementations, to redirect or completely override
MicroPython's TinyUSB callbacks.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit adds a `--json` option to `mpy-tool.py`, in order to generate
Compiler-Explorer-compatible JSON annotation information for the bytecode
disassembly. Some of this information might be theoretically possible to
parse out from the text itself, but not all of it is, e.g. disambiguating
child references with non-unique simple names.

Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
Signed-off-by: Damien George <damien@micropython.org>
This is 0.19.0 plus the following changes:
- remove obsolete dcd_esp32sx
- fix for HID stylus descriptor and HID example
- typos, docs and generator scripts
- MTP fix
- DWC2 enumeration when EP0 size=8
- DWC2 fix for EP0 IN
- stm32 FSDEV IRQ remapping fix
- DWC2 ZLP fix

The reason we need the extra 24 commits is due to a bug with TinyUSB's
handling of zero-length-packets in the DWC2 (Synopsis) backend, which
affects the stm32 port.  That's fixed by
hathach/tinyusb#3293

Signed-off-by: Damien George <damien@micropython.org>
It's now available in the version of TinyUSB used by this repository.

Also, update to the newer `tud_cdc_configure_t` struct name and newer
`tud_cdc_configure()` function name.

Signed-off-by: Damien George <damien@micropython.org>
Noted while adding C2 support that some of these comments are a bit out of
date. Spun out to its own commit, and also mention C5 as well.

This change also adds some recommendation on which ESP32 board to pick, as
we occasionally see issues or questions that would be non-issues on a board
with more RAM (and for small production or personal projects the savings of
picking a cheaper ESP32 chip are basically neglible).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Only set the rate on interfaces that are active.

It seems ESP-IDF 5.4.x or so added checks that the interface is enabled,
whereas previous versions silently did nothing.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Changes are:
- Add constants for some of the supported ESP-NOW data rates.
- Add constants for switching an ESP32 WLAN radio in/out of
  Long Range mode.
- Document the new constants and their usage.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Uses constants added in previous commit.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Add the IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP to modsocket in the Unix
port so that the directives take on the values defined in the system
headers. This is needed because the values of these directives are
different for MacOS vs other Unix systems.

Fixes issue #8456.

Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
This commit adds custom command completion functions for both the zsh
and fish shell.

The behaviour for those new completions follow the existing completion
for the bash shell, including the way to generate the completion alias
(with appropriately named command line switches).

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Fixes issue #18370.

Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
There were a few typos in the documentation for the `I2CTarget.irq` method
description where `IRQ_ADDR_MATCH_READ` was used, however
`IRQ_ADDR_MATCH_WRITE` should have been used.

Fixes issue #18470.

Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
Fixes issue #7915.

Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
Allows using custom DTS things such as bindings.

Signed-off-by: Vdragon <mail@massdriver.space>
Adds the ability to use PSRAM and non-contiguous memory.

Example usage, add this to dts overlay:

    / {
            heap_psram {
                    compatible = "micropython,heap";
                    size = <DT_SIZE_M(4)>;
                    memory-region = <&psram>;
            };

            heap_sram1 {
                    compatible = "micropython,heap";
                    size = <DT_SIZE_K(140)>;
                    memory-region = <&sram1>;
            };
    };

Signed-off-by: Vdragon <mail@massdriver.space>
This commit fixes a regression introduced in
1b92bda, where a new architecture was
added to mpy-cross but it had no matching native emitter exists.

The result was that the architecture emitter entry point would be
correctly calculated according to the native architecture index, but if
the emitters entry points table was not updated to match the new number
of architectures an out of bound access may be performed.

Unfortunately adding RV64IMC shifted the debug emitter index further
down the table, and that table wasn't updated to reflect the lack of an
emitter for RV64.  Adding a NULL entry there would cause a NULL pointer
access as there was no need to perform any check about the emitter entry
point function's validity until now.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit adds a new workflow step to the CI, to test the debug
emitter provided by mpy-cross.  The checks being done are limited to
make sure that the debug emitter does not crash and emits opcodes for a
simple test file that is guaranteed to work for all configurations.

Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Allows using TinyUSB stack on N6.

Note there's still an issue with TinyUSB on the N6: `pyb_usbd_init()` can't
be called multiple times (on soft-reboot).

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Signed-off-by: Mike Tolkachev <contact@miketolkachev.dev>
Signed-off-by: Mike Tolkachev <contact@miketolkachev.dev>
Signed-off-by: Damien George <damien@micropython.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.