Skip to content

The bytearray() value set to bytes.partition() and bytes.rpartition() is not converted to a bytes() value, keeping a bytearray() value in a tuple #137217

@hyperkai

Description

@hyperkai

Bug report

Bug description:

The bytearray() value set to bytes.partition() and bytes.rpartition() is not converted to a bytes() value, keeping a bytearray() value in a tuple as shown below:

v = bytes(b'ABCD')

                # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓           # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
print(v.partition(bytearray(b'BC')))  # (b'A', bytearray(b'BC'), b'D')
print(v.rpartition(bytearray(b'BC'))) # (b'A', bytearray(b'BC'), b'D')
                 # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑          # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

The bytearray() value set to bytes.partition() and bytes.rpartition() should be converted to a bytes() value, not keeping a bytearray() value in a tuple because they are bytes functions and because of readability and consistency as shown below:

v = bytes(b'ABCD')

                # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓           # ↓↓↓↓↓
print(v.partition(bytearray(b'BC')))  # (b'A', b'BC', b'D')
print(v.rpartition(bytearray(b'BC'))) # (b'A', b'BC', b'D')
                 # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑          # ↑↑↑↑↑

In addition, the bytes() value set to bytearray.partition() and bytearray.rpartition() is converted to a bytearray() value, not keeping a bytes() value in a tuple as shown below:

v = bytearray(b'ABCD')

                # ↓↓↓↓↓↓↓↓↓↓↓↓                      # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
print(v.partition(bytes(b'BC')))  # (bytearray(b'A'), bytearray(b'BC'), bytearray(b'D'))
print(v.rpartition(bytes(b'BC'))) # (bytearray(b'A'), bytearray(b'BC'), bytearray(b'D'))
                 # ↑↑↑↑↑↑↑↑↑↑↑↑                     # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

CPython versions tested on:

3.12

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions