Skip to content

Commit 3ba5ba6

Browse files
process1183tannewt
authored andcommitted
shared-bindings/storage/__init__.c: Change remount() readonly to kw arg (micropython#286).
The readonly arg to storage.remount() is now a keyword arg that defaults to False. To maintain backwards compatibility, readonly can be passed as a positional arg or keyword arg.
1 parent 535c005 commit 3ba5ba6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

shared-bindings/storage/__init__.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,28 @@ mp_obj_t storage_umount(mp_obj_t mnt_in) {
101101
}
102102
MP_DEFINE_CONST_FUN_OBJ_1(storage_umount_obj, storage_umount);
103103

104-
//| .. function:: remount(mount_path, readonly)
104+
//| .. function:: remount(mount_path, readonly=False)
105105
//|
106106
//| Remounts the given path with new parameters.
107107
//|
108-
mp_obj_t storage_remount(mp_obj_t mount_path, mp_obj_t readonly) {
109-
if (!MP_OBJ_IS_STR(mount_path)) {
110-
mp_raise_ValueError("mount_path must be string");
111-
}
108+
mp_obj_t storage_remount(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
109+
enum { ARG_readonly };
110+
static const mp_arg_t allowed_args[] = {
111+
{ MP_QSTR_readonly, MP_ARG_BOOL | MP_ARG_REQUIRED, {.u_bool = false} },
112+
};
113+
114+
// get the mount point
115+
const char *mnt_str = mp_obj_str_get_str(pos_args[0]);
116+
117+
// parse args
118+
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
119+
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
112120

113-
common_hal_storage_remount(mp_obj_str_get_str(mount_path),
114-
mp_obj_is_true(readonly));
121+
common_hal_storage_remount(mnt_str, args[ARG_readonly].u_bool);
115122

116123
return mp_const_none;
117124
}
118-
MP_DEFINE_CONST_FUN_OBJ_2(storage_remount_obj, storage_remount);
125+
MP_DEFINE_CONST_FUN_OBJ_KW(storage_remount_obj, 1, storage_remount);
119126

120127
STATIC const mp_rom_map_elem_t storage_module_globals_table[] = {
121128
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) },

0 commit comments

Comments
 (0)