mp_identity(): Add generic identity function.
Useful as getiter method for objects which are their own iterators, etc.
This commit is contained in:
parent
3754c4a040
commit
dff3f896d7
6
py/obj.c
6
py/obj.c
|
@ -288,3 +288,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
|
|||
}
|
||||
return MP_OBJ_NEW_SMALL_INT(len);
|
||||
}
|
||||
|
||||
// Return input argument. Useful as .getiter for objects which are
|
||||
// their own iterators, etc.
|
||||
mp_obj_t mp_identity(mp_obj_t self) {
|
||||
return self;
|
||||
}
|
||||
|
|
2
py/obj.h
2
py/obj.h
|
@ -351,6 +351,8 @@ extern const mp_obj_type_t fun_native_type;
|
|||
extern const mp_obj_type_t fun_bc_type;
|
||||
void mp_obj_fun_bc_get(mp_obj_t self_in, int *n_args, uint *n_state, const byte **code);
|
||||
|
||||
mp_obj_t mp_identity(mp_obj_t self);
|
||||
|
||||
// generator
|
||||
extern const mp_obj_type_t gen_instance_type;
|
||||
|
||||
|
|
Loading…
Reference in New Issue