python / python/cpython

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

Aperta
#137,217 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

interpreter-core type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui prima gli esempi Python forniti, quindi individua le implementazioni di bytes.partition(), bytes.rpartition(), bytearray.partition() e bytearray.rpartition(), insieme ai relativi test. Il lavoro è completato quando gli elementi della tupla restituita corrispondono sistematicamente al tipo dell’oggetto su cui viene chiamato il partizionamento, con copertura di regressione per entrambe le direzioni ed entrambi i tipi di argomento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.