summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/builtin.c12
-rw-r--r--py/builtin.h1
-rw-r--r--py/mpqstrraw.h1
-rw-r--r--py/runtime.c1
4 files changed, 15 insertions, 0 deletions
diff --git a/py/builtin.c b/py/builtin.c
index f102aa5885..13463ada69 100644
--- a/py/builtin.c
+++ b/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);
diff --git a/py/builtin.h b/py/builtin.h
index 050a2161c1..4257de5bdb 100644
--- a/py/builtin.h
+++ b/py/builtin.h
@@ -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);
diff --git a/py/mpqstrraw.h b/py/mpqstrraw.h
index 10b1fc0d39..9bc01c5851 100644
--- a/py/mpqstrraw.h
+++ b/py/mpqstrraw.h
@@ -40,6 +40,7 @@ Q(any)
Q(array)
Q(bool)
Q(bytearray)
+Q(bytes)
Q(callable)
Q(chr)
Q(complex)
diff --git a/py/runtime.c b/py/runtime.c
index d8fc3ff6e4..72347aff80 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -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);