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

Aberta
#137,217 5 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

interpreter-core type-bug
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Execute primeiro os exemplos de Python fornecidos e, em seguida, localize as implementações de bytes.partition(), bytes.rpartition(), bytearray.partition() e bytearray.rpartition(), além de seus testes. A tarefa estará concluída quando os elementos da tupla retornada corresponderem consistentemente ao tipo do objeto no qual o particionamento é chamado, com cobertura de regressão para ambas as direções e ambos os tipos de argumento.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
backend
Tipo de issue
Bug
Dificuldade
4/5
Tempo estimado
3-5 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.