Skip to content

Support copy.replace() for csv dialects #155033

Closed

Description

@serhiy-storchaka

Feature or enhancement

There is no easy way to get a CSV dialect that differs from an existing one in a single formatting parameter. You either repeat all parameters in a csv.Dialect subclass, or pass the individual parameters to csv.reader()/csv.writer() at every call site.

I propose to support copy.replace() for dialects — both instances of csv.Dialect subclasses and the dialect objects returned by csv.get_dialect().

>>> dialect = copy.replace(csv.get_dialect('excel'), delimiter=';', strict=True)
>>> list(csv.reader(['a;b'], dialect))
[['a', 'b']]

Parameters that are not replaced are inherited from the original dialect, and the result is validated like a newly created dialect.

Note that some parameters depend on each other and may need to be replaced together. For example, replacing quotechar with None also requires replacing quoting with QUOTE_NONE, otherwise validation fails with "quotechar must be set if quoting enabled".

Linked PRs

Activity

  1. added a commit that references this issue on Aug 13, 2026
  2. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-featureA feature request or enhancement

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions