micropython/ports/esp32/modules
Damien George 2752d398ad esp32/modules: Use "from machine import *" instead of __getattr__.
The esp32 port has the machine Counter and Encoder classes implemented in
Python, requiring a `machine.py` that extends the built-in machine module.

That previously used `__getattr__()` to delegate lookups to the built-in,
but that means any failed lookup raises an `AttributeError` instead of an
`ImportError`.  This means (among other things) that certain tests like
CAN and I2CTarget would fail because they couldn't skip the test correctly.

This commit improves the situation by using `from machine import *` instead
of `__getattr__()`, which puts all the built-in functions/classes/constants
directly in the `machine.py` global namespace.  That means an `ImportError`
is now correctly raised for attributes that don't exist.

Although this takes up a bit more RAM, it's now a lot faster to import from
the machine module: what used to take around 100us to lookup a name now
takes only 5us.

Signed-off-by: Damien George <damien@micropython.org>
2026-04-15 16:08:34 +10:00
..
_boot.py ports: Use vfs module instead of os. 2024-02-07 13:25:09 +11:00
apa106.py esp32: Add new port to Espressif ESP32 SoC. 2017-12-13 14:48:53 +11:00
espnow.py esp32,esp8266: Add support for the Espressif ESP-NOW protocol. 2023-05-01 16:47:21 +10:00
flashbdev.py esp32/modules: Create ffat partition object with block_size=512. 2022-02-22 00:37:55 +11:00
inisetup.py ports: Use vfs module instead of os. 2024-02-07 13:25:09 +11:00
machine.py esp32/modules: Use "from machine import *" instead of __getattr__. 2026-04-15 16:08:34 +10:00