From 181df51a0c77ac520f7fc4ac7d2cde4591686ec3 Mon Sep 17 00:00:00 2001 From: Saiyam Jain Date: Sun, 25 Oct 2026 20:56:00 +0530 Subject: [PATCH 1/2] gh-160106: Fix csv.Dialect.__replace__() losing slot-backed attributes copy.replace() on a csv.Dialect subclass that stores dialect options in __slots__ would silently drop those attributes. __replace__() only copied self.__dict__, so any attribute stored in a slot was missing from the new object, causing csv.reader/writer to fall back to the default value. Fix by iterating the MRO for __slots__ entries and copying any dialect attribute that was not already set via __dict__. --- Lib/csv.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/csv.py b/Lib/csv.py index b406d82efffd9f3..1bf15177aa0d3a5 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -125,6 +125,15 @@ def __replace__(self, /, **changes): f'argument {min(unexpected)!r}') new = object.__new__(self.__class__) new.__dict__.update(self.__dict__) + # Copy slot-backed dialect attributes from the instance's MRO, + # since __dict__ only captures attributes stored in __dict__. + for cls in type(self).__mro__: + for attr in getattr(cls, '__slots__', ()): + if attr in _dialect_attributes and attr not in new.__dict__: + try: + new.__dict__[attr] = getattr(self, attr) + except AttributeError: + pass new.__dict__.update(changes) new._validate() return new From 376074f8051049b05e447d241ac3b2f8f97d42be Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:33:29 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2026-10-25-15-33-28.gh-issue-160106.G7eA2V.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2026-10-25-15-33-28.gh-issue-160106.G7eA2V.rst diff --git a/Misc/NEWS.d/next/Library/2026-10-25-15-33-28.gh-issue-160106.G7eA2V.rst b/Misc/NEWS.d/next/Library/2026-10-25-15-33-28.gh-issue-160106.G7eA2V.rst new file mode 100644 index 000000000000000..ff1d43731b4a3d4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-25-15-33-28.gh-issue-160106.G7eA2V.rst @@ -0,0 +1 @@ +Fix :func:`copy.replace` on :class:`csv.Dialect` subclasses losing slot-backed attributes.