-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
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
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error