Skip to content

bytes(bytes) is inefficient #2125

Closed
Closed
@edwardycl

Description

@edwardycl

Feature

bytes object is immutable, so constructing a new bytes object from another bytes object doesn't need copying.
However, PyBytes and PyByteArray share PyBytesInner implementation, causing an unnecessary copying of immutable data.

CPython:

>>> b = b'foo'
>>> bytes(b) is b
True

RustPython:

>>> b = b'foo'
>>> bytes(b) is b
False

Python Documentation

https://docs.python.org/3/library/stdtypes.html#bytes-objects

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-compatA discrepancy between RustPython and CPython

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions