Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :func:`copy.replace` on :class:`csv.Dialect` subclasses losing slot-backed attributes.
Loading