Skip to content

Commit 47d3bd3

Browse files
committed
py: enumerate(): Add NotImplementedError for kwargs.
Addresses adafruit#577.
1 parent 33b3a69 commit 47d3bd3

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

py/argcheck.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,10 @@ void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_all
103103
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "extra keyword arguments given"));
104104
}
105105
}
106+
107+
#if MICROPY_CPYTHON_COMPAT
108+
void mp_arg_error_unimpl_kw() {
109+
nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError,
110+
"keyword argument(s) not yet implemented - use normal args instead"));
111+
}
112+
#endif

py/objenumerate.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ typedef struct _mp_obj_enumerate_t {
4141

4242
STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in);
4343

44-
/* TODO: enumerate is one of the ones that can take args or kwargs.
45-
Sticking to args for now */
4644
STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
45+
/* TODO: enumerate is one of the ones that can take args or kwargs.
46+
Sticking to args for now */
47+
#if MICROPY_CPYTHON_COMPAT
48+
if (n_kw != 0) {
49+
mp_arg_error_unimpl_kw();
50+
}
51+
#endif
4752
assert(n_args > 0);
4853
mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t);
4954
o->base.type = &mp_type_enumerate;

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void mp_deinit(void);
5656

5757
void mp_arg_check_num(uint n_args, uint n_kw, uint n_args_min, uint n_args_max, bool takes_kw);
5858
void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
59+
NORETURN void mp_arg_error_unimpl_kw();
5960

6061
mp_obj_dict_t *mp_locals_get(void);
6162
void mp_locals_set(mp_obj_dict_t *d);

0 commit comments

Comments
 (0)