Skip to content

Commit ca01784

Browse files
iyassoudpgeorge
authored andcommitted
py/objstr: Make bytes(bytes_obj) return bytes_obj.
Calling the bytes constructor on a bytes object returns the original bytes object. This saves allocating a new instance, and matches CPython. Signed-off-by: Iyassou Shimels <[email protected]>
1 parent bada8c9 commit ca01784

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

py/objstr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size
205205
return mp_const_empty_bytes;
206206
}
207207

208+
if (mp_obj_is_type(args[0], &mp_type_bytes)) {
209+
return args[0];
210+
}
211+
208212
if (mp_obj_is_str(args[0])) {
209213
if (n_args < 2 || n_args > 3) {
210214
goto wrong_args;

0 commit comments

Comments
 (0)