Skip to content

Commit 4e1eac2

Browse files
committed
pybricks/pybricks: Fix auto-import in REPL.
Fixes pybricks/support#741 This was broken by cd16b4c
1 parent 57efb61 commit 4e1eac2

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
speed as a numerical derivative of the motor position, instead of a
3232
model-based estimate. For most use cases, this is a more intuitive result
3333
because this speed value is not affected by mechanical load.
34+
- When using the REPL, everything from all Pybricks modules was automatically
35+
imported for convenience. Now, everything from all available MicroPython
36+
modules is also automatically imported ([support#741]).
3437

3538
### Fixed
3639
- Fixed motors going out of sync when starting program ([support#679]).
@@ -40,6 +43,7 @@
4043
- Fixed REPL history corrupt after soft reset ([support#699]).
4144
- Fixed "ValueError: incompatible .mpy file" when pressing the button when
4245
there is no program yet ([support#599]).
46+
- Fixed automatic imports when using the REPL ([support#741]).
4347

4448
[pybricks-micropython#115]: https://github.com/pybricks/pybricks-micropython/pull/115
4549
[support#232]: https://github.com/pybricks/support/issues/232
@@ -49,6 +53,7 @@
4953
[support#692]: https://github.com/pybricks/support/issues/692
5054
[support#699]: https://github.com/pybricks/support/issues/699
5155
[support#729]: https://github.com/pybricks/support/issues/729
56+
[support#741]: https://github.com/pybricks/support/issues/741
5257

5358
## [3.2.0b3] - 2022-07-20
5459

pybricks/pybricks.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,17 @@ MP_REGISTER_MODULE(MP_QSTR_pybricks, pb_package_pybricks);
6262
#endif
6363

6464
/**
65-
* Import all pybricks.* modules.
65+
* import * from all builtin Pybricks and MicroPython modules.
6666
*/
6767
static void pb_package_import_all(void) {
6868

69-
// Go through each module in the package.
70-
for (size_t i = 0; i < MP_ARRAY_SIZE(pybricks_globals_table); i++) {
71-
mp_rom_obj_t module = pybricks_globals_table[i].value;
72-
if (mp_obj_is_type(module, &mp_type_module)) {
73-
// Import everything from the module.
74-
mp_import_all((mp_obj_t)module);
75-
}
69+
// Go through all modules in mp_builtin_module_map.
70+
for (size_t i = 0; i < mp_builtin_module_map.used; i++) {
71+
// This is a constant map of modules, so we can skip checks for
72+
// filled slots and module types.
73+
mp_import_all(mp_builtin_module_map.table[i].value);
7674
}
75+
7776
#if PYBRICKS_PY_HUBS
7877
// Initialize hub instance
7978
const mp_obj_t args;

0 commit comments

Comments
 (0)