From 47d3bd3b3189f44d9979e9ce1555e73629a3bbc7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Tue, 6 May 2014 19:25:25 +0300 Subject: [PATCH] py: enumerate(): Add NotImplementedError for kwargs. Addresses #577. --- py/argcheck.c | 7 +++++++ py/objenumerate.c | 9 +++++++-- py/runtime.h | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/py/argcheck.c b/py/argcheck.c index 924a60c455..40c0cefb7a 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -103,3 +103,10 @@ void mp_arg_parse_all(uint n_pos, const mp_obj_t *pos, mp_map_t *kws, uint n_all nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "extra keyword arguments given")); } } + +#if MICROPY_CPYTHON_COMPAT +void mp_arg_error_unimpl_kw() { + nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError, + "keyword argument(s) not yet implemented - use normal args instead")); +} +#endif diff --git a/py/objenumerate.c b/py/objenumerate.c index fd428da4e3..78169b31c4 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -41,9 +41,14 @@ typedef struct _mp_obj_enumerate_t { STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in); -/* TODO: enumerate is one of the ones that can take args or kwargs. - Sticking to args for now */ STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { + /* TODO: enumerate is one of the ones that can take args or kwargs. + Sticking to args for now */ +#if MICROPY_CPYTHON_COMPAT + if (n_kw != 0) { + mp_arg_error_unimpl_kw(); + } +#endif assert(n_args > 0); mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); o->base.type = &mp_type_enumerate; diff --git a/py/runtime.h b/py/runtime.h index 46be12dec7..beb687e847 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -56,6 +56,7 @@ void mp_deinit(void); void mp_arg_check_num(uint n_args, uint n_kw, uint n_args_min, uint n_args_max, bool takes_kw); 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); +NORETURN void mp_arg_error_unimpl_kw(); mp_obj_dict_t *mp_locals_get(void); void mp_locals_set(mp_obj_dict_t *d);