Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

copy.replace loses slot-backed CSV dialect options

Aberta
#160,106 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@saiyam-jain-dev já está trabalhando nisso.

Desde 25/10/2026.

  • #160641 de @saiyam-jain-dev — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
34/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
backend

Direção de pesquisa

The report identifies Dialect.__replace__() and provides a reproducer, but names no source or test files. Start by locating that method and the CSV dialect tests, then reproduce the example on CPython 3.16. Done means copy.replace() preserves the slot-backed delimiter and both readers return [['alpha', 'beta']]; the reporter says they have already prepared a local fix and regression tests.

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

Descrição

stdlib type-bug
Bug report

copy.replace() loses slot-backed attributes of csv.Dialect subclasses. This can silently change how CSV data is parsed, even when the delimiter was not replaced.

Reproduced with CPython 3.16.0a1. The same implementation is present on main at 31a7d994a559a421814ca9e8edfcab21ae4a5b36.

import copy
import csv

class SemicolonDialect(csv.excel):
    __slots__ = ('delimiter',)

    def __init__(self):
        self.delimiter = ';'
        super().__init__()

dialect = SemicolonDialect()
replacement = copy.replace(dialect, quoting=csv.QUOTE_ALL)

print(list(csv.reader(['alpha;beta'], dialect)))
print(list(csv.reader(['alpha;beta'], replacement)))

Actual output:

[['alpha', 'beta']]
[['alpha;beta']]

Expected: both readers produce [['alpha', 'beta']], since only the quoting setting was replaced.

Dialect.__replace__() copies only __dict__, losing attributes stored in slots. The replacement therefore lacks its delimiter, and csv.reader falls back to the default comma delimiter.

I have prepared a local fix and regression tests.

CPython versions tested on:

3.16

Operating systems tested on:

No response

Linguagem predominante
Python
Estrelas
77.7k
Forks
38.3k
Merge médio
13h 43min
PRs com merge (30d)
704

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

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.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

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