Skip to content

Commit ee6bd09

Browse files
committed
Rename method, and remove redundant checks
1 parent a7406ec commit ee6bd09

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

locale/circuitpython.pot

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,10 +2942,6 @@ msgstr ""
29422942
msgid "file must be a file opened in byte mode"
29432943
msgstr ""
29442944

2945-
#: shared-bindings/audiomp3/MP3Decoder.c
2946-
msgid "file path must be provided as input"
2947-
msgstr ""
2948-
29492945
#: shared-bindings/traceback/__init__.c
29502946
msgid "file write is not available"
29512947
msgstr ""

shared-bindings/audiomp3/MP3Decoder.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,20 @@ STATIC mp_obj_t audiomp3_mp3file_obj_set_file(mp_obj_t self_in, mp_obj_t file) {
172172
}
173173
MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_set_file_obj, audiomp3_mp3file_obj_set_file);
174174

175-
//| def open_file(self, str) -> None:
175+
//| def open(self, str) -> None:
176176
//| """Takes in the name of a mp3 file, opens it, and replaces the old playback file."""
177177
//| ...
178178
//|
179-
STATIC mp_obj_t audiomp3_mp3file_obj_open_file(mp_obj_t self_in, mp_obj_t path) {
179+
STATIC mp_obj_t audiomp3_mp3file_obj_open(mp_obj_t self_in, mp_obj_t path) {
180180
audiomp3_mp3file_obj_t *self = MP_OBJ_TO_PTR(self_in);
181-
mp_obj_t file;
182181
check_for_deinit(self);
183-
if (!mp_obj_is_str(path)) {
184-
mp_raise_TypeError(translate("file path must be provided as input"));
185-
}
186-
file = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), path, MP_ROM_QSTR(MP_QSTR_rb));
187-
if (!mp_obj_is_type(file, &mp_type_fileio)) {
188-
mp_raise_TypeError(translate("file must be a file opened in byte mode"));
189-
}
182+
183+
mp_obj_t file = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), path, MP_ROM_QSTR(MP_QSTR_rb));
184+
190185
common_hal_audiomp3_mp3file_set_file(self, file);
191186
return mp_const_none;
192187
}
193-
MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_open_file_obj, audiomp3_mp3file_obj_open_file);
188+
MP_DEFINE_CONST_FUN_OBJ_2(audiomp3_mp3file_open_obj, audiomp3_mp3file_obj_open);
194189

195190
MP_PROPERTY_GETSET(audiomp3_mp3file_file_obj,
196191
(mp_obj_t)&audiomp3_mp3file_get_file_obj,
@@ -276,7 +271,7 @@ MP_PROPERTY_GETTER(audiomp3_mp3file_samples_decoded_obj,
276271

277272
STATIC const mp_rom_map_elem_t audiomp3_mp3file_locals_dict_table[] = {
278273
// Methods
279-
{ MP_ROM_QSTR(MP_QSTR_open_file), MP_ROM_PTR(&audiomp3_mp3file_open_file_obj) },
274+
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&audiomp3_mp3file_open_obj) },
280275
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&audiomp3_mp3file_deinit_obj) },
281276
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
282277
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&audiomp3_mp3file___exit___obj) },

0 commit comments

Comments
 (0)