← index #17453Issue #17203
Off-topic · high · value 3.012
QUERY · ISSUE

micropython.const inconsistent behaviour in class

openby konomikittenopened 2025-06-07updated 2025-06-08
bug

Port, board and/or hardware

Waveshare ESP32-C3-Zero Development Board

MicroPython version

MicroPython v1.25.0 on 2025-04-15; ESP32C3 module with ESP32C3

Reproduction

with_const.py

from micropython import const

class HelloWorld:
    TEST = const("Hello World!")

    def __init__(self):
        print(TEST)
>>> import with_const
>>> hello_world = with_const.HelloWorld()
Hello World!
>>>

without_const.py

class HelloWorld:
    TEST = "Hello World!"

    def __init__(self):
        print(TEST)
>>> import without_const
>>> hello_world = without_const.HelloWorld()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "without_const.py", line 5, in __init__
NameError: name 'TEST' isn't defined
>>>

I wouldn't have noticed that I wasn't properly referencing my class constant variable if it wasn't for PyLint telling me I was making mistakes. This seems like a bug?

Expected behaviour

I expected the example using micropython.const() to error.

Observed behaviour

There is no error.

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

creating virtual timer on MicroPython v1.25.0 on esp32 s3 fails

closedby NilsBeopened 2025-04-28updated 2025-04-28
bug

Port, board and/or hardware

esp32 s3

MicroPython version

MicroPython v1.25.0 on 2025-04-15; Generic ESP32S3 module with ESP32S3

Reproduction

import machine
t = machine.Timer(-1)

Expected behaviour

no error on MicroPython v1.24.1 on 2024-11-29; Generic ESP32S3 module with ESP32S3

Observed behaviour

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid Timer number

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

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