The `bytearray()` value set to `bytes.partition()` and `bytes.rpartition()` is not converted to a `bytes()` value, keeping a `bytearray()` value in a tuple
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the provided Python examples first, then locate the bytes.partition(), bytes.rpartition(), bytearray.partition(), and bytearray.rpartition() implementations and their tests. Done means the returned tuple elements consistently match the type of the object on which partitioning is called, with regression coverage for both directions and both argument types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100