Add dummy bytes() constructor.
Currently, MicroPython strings are mix between CPython byte and unicode strings. So, conversion is null so far. This dummy implementation is intended for compatibility with CPython (so, same code can run on both).
This commit is contained in:
12
py/builtin.c
12
py/builtin.c
@@ -347,3 +347,15 @@ static mp_obj_t mp_builtin_str(mp_obj_t o_in) {
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_str_obj, mp_builtin_str);
|
||||
|
||||
// TODO: This should be type, this is just quick CPython compat hack
|
||||
static mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) {
|
||||
if (!MP_OBJ_IS_QSTR(args[0]) && !MP_OBJ_IS_TYPE(args[0], &str_type)) {
|
||||
assert(0);
|
||||
}
|
||||
// Currently, MicroPython strings are mix between CPython byte and unicode
|
||||
// strings. So, conversion is null so far.
|
||||
return args[0];
|
||||
}
|
||||
|
||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_bytes_obj, 1, 3, mp_builtin_bytes);
|
||||
|
||||
@@ -5,6 +5,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin___repl_print___obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_abs_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_all_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_any_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_bytes_obj); // Temporary hack
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_callable_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
|
||||
|
||||
@@ -40,6 +40,7 @@ Q(any)
|
||||
Q(array)
|
||||
Q(bool)
|
||||
Q(bytearray)
|
||||
Q(bytes)
|
||||
Q(callable)
|
||||
Q(chr)
|
||||
Q(complex)
|
||||
|
||||
@@ -130,6 +130,7 @@ void rt_init(void) {
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_abs, (mp_obj_t)&mp_builtin_abs_obj);
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_all, (mp_obj_t)&mp_builtin_all_obj);
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_any, (mp_obj_t)&mp_builtin_any_obj);
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_bytes, (mp_obj_t)&mp_builtin_bytes_obj);
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_callable, (mp_obj_t)&mp_builtin_callable_obj);
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_chr, (mp_obj_t)&mp_builtin_chr_obj);
|
||||
mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
|
||||
|
||||
Reference in New Issue
Block a user