Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

copy.replace loses slot-backed CSV dialect options

Đang mở
#160,106 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@saiyam-jain-dev đang làm issue này rồi.

Từ ngày 25/10/2026.

  • #160641 của @saiyam-jain-dev — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
34/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
77.7k
Fork
38.3k
Merge trung bình
12 giờ 27 phút
Pull request đã merge (30 ngày)
710

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.