Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: constant must be an integer #1082

Open
Thesnake66six opened this issue Dec 11, 2022 · 2 comments · May be fixed by microbit-foundation/micropython-microbit-v2-simulator#113
Open

Comments

@Thesnake66six
Copy link

Thesnake66six commented Dec 11, 2022

Although code runs fine on the actual microbit, it throws this error in the simulator.

from micropython import const

MY_CONST = const(0.5)
@microbit-matt-hillsdon
Copy link
Collaborator

Thanks for the report.

This seems to be a difference between MicroPython for the micro:bit V1 board version (where it works) and MicroPython for the micro:bit V2 where it does not. The simulator is based on MicroPython for micro:bit V2.

I'll get some input on why this difference exists and follow up here.

@microbit-matt-hillsdon
Copy link
Collaborator

For V1 const isn't doing anything, it's simply returning its argument. This is unlikely to change at this point due to code size and implementation effort constraints. If you're free to change this code then you can simply remove the const call.

For V2 we're using MicroPython 1.18.0 where using const is optimising the integer constants and intentionally failing for non-integer values.

Coincidentally, upstream MicroPython 1.19.1 now has support for more types of constant. We'll plan an upgrade in future which will align the behaviour (though V1 will still lack the optimisation).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants