Skip to content

Commit c53b408

Browse files
committed
Conflicts: py/argcheck.c py/objenumerate.c py/runtime.h
2 parents 491cbd6 + b473d0a commit c53b408

4 files changed

Lines changed: 27 additions & 0 deletions

File tree

py/argcheck.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,10 @@ void mp_arg_parse_all_kw_array(uint n_pos, uint n_kw, const mp_obj_t *args, uint
109109
mp_map_init_fixed_table(&kw_args, n_kw, args + n_pos);
110110
mp_arg_parse_all(n_pos, args, &kw_args, n_allowed, allowed, out_vals);
111111
}
112+
113+
#if MICROPY_CPYTHON_COMPAT
114+
NORETURN void mp_arg_error_unimpl_kw(void) {
115+
nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError,
116+
"keyword argument(s) not yet implemented - use normal args instead"));
117+
}
118+
#endif

py/objenumerate.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ STATIC const mp_arg_t enumerate_make_new_args[] = {
4848
#define ENUMERATE_MAKE_NEW_NUM_ARGS ARRAY_SIZE(enumerate_make_new_args)
4949

5050
STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
51+
#if MICROPY_CPYTHON_COMPAT
5152
// parse args
5253
mp_arg_val_t vals[ENUMERATE_MAKE_NEW_NUM_ARGS];
5354
mp_arg_parse_all_kw_array(n_args, n_kw, args, ENUMERATE_MAKE_NEW_NUM_ARGS, enumerate_make_new_args, vals);
@@ -57,6 +58,12 @@ STATIC mp_obj_t enumerate_make_new(mp_obj_t type_in, uint n_args, uint n_kw, con
5758
o->base.type = &mp_type_enumerate;
5859
o->iter = mp_getiter(vals[0].u_obj);
5960
o->cur = vals[1].u_int;
61+
#else
62+
mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t);
63+
o->base.type = &mp_type_enumerate;
64+
o->iter = mp_getiter(args[0]);
65+
o->cur = n_args > 1 ? mp_obj_get_int(args[1]) : 0;
66+
#endif
6067

6168
return o;
6269
}

py/objstr.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ STATIC void str_print(void (*print)(void *env, const char *fmt, ...), void *env,
108108
}
109109

110110
STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
111+
#if MICROPY_CPYTHON_COMPAT
112+
if (n_kw != 0) {
113+
mp_arg_error_unimpl_kw();
114+
}
115+
#endif
116+
111117
switch (n_args) {
112118
case 0:
113119
return MP_OBJ_NEW_QSTR(MP_QSTR_);
@@ -146,6 +152,12 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
146152
return mp_const_empty_bytes;
147153
}
148154

155+
#if MICROPY_CPYTHON_COMPAT
156+
if (n_kw != 0) {
157+
mp_arg_error_unimpl_kw();
158+
}
159+
#endif
160+
149161
if (MP_OBJ_IS_STR(args[0])) {
150162
if (n_args < 2 || n_args > 3) {
151163
goto wrong_args;

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void mp_deinit(void);
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);
5959
void mp_arg_parse_all_kw_array(uint n_pos, uint n_kw, const mp_obj_t *args, uint n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals);
60+
NORETURN void mp_arg_error_unimpl_kw(void);
6061

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

0 commit comments

Comments
 (0)