← index #15615Issue #12743
Off-topic · high · value 0.246
QUERY · ISSUE

Native code decorator should be best-effort

openby darconeousopened 2024-08-08updated 2026-03-24
bugpy-core

Port, board and/or hardware

MacOS X (Apple Silicon)

MicroPython version

MicroPython v1.23.0 on 2024-05-31; darwin [GCC 4.2.1] version

Reproduction

Try running the following code on a macOS device running Apple Silicon using a version of Micropython built for Apple Silicon:

@micropython.native
def test_fun():
    print("Hello, World!")

Expected behaviour

I understand that native code execution is not supported on Apple Silicon, but I would expect to still be able to generally execute code even if marked up with native decorators (in order words, I would expect them to be ignored in that case).

Observed behaviour

When trying to test this code locally on my MacBook Pro M2, all functions with the decorator @micropython.native end up generating the following exception:

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SyntaxError: invalid micropython decorator
>>> 

Additional Information

I understand that the @micropython.viper decorator has different behavior and might not be a good candidate for being ignored, so we may want different behavior there. Perhaps an opt-in for allowing it to be ignored? Something like this:

@micropython.viper(optional=true)
def test_fun():
    print("Hello, World!")

This would force anyone wanting to test code like this to attest that the behavior would be the same.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

Native code emitter: "while True"-loop can not be interrupted.

closedby nspsckopened 2023-10-19updated 2023-10-19

Here is a simple code which is interruptable with the Ctrl+C command without the @micropython.native decorator. However, if the @micropython.native decorator was specified, you can no longer interrupt the code using the 'Ctrl+C' command on the rp2 and eps32 port. Surprisingly, the stm32 port actually can be interrupted both with and without the decorator. I do not have boards of other ports, hence I have no idea how these would behave.

# @micropython.native
def foo():
    while True:
        pass
        
foo()

After reading about the native code emitter and it's limitations, I assume this is a unwanted behavior.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied