Skip to content

csv.writer: multi-character lineterminator is truncated to a single byte #8322

Description

@jinmay

Feature

Follow-up from #8302 / #8315.

csv.writer should accept an arbitrary string as lineterminator. RustPython stores it as a single byte, so a multi-character terminator is truncated instead of being emitted in full.

import csv, io
sio = io.StringIO()
csv.writer(sio, lineterminator="!@#").writerow(["a", "b"])
print(repr(sio.getvalue()))
# CPython:    'a,b!@#'
# RustPython: 'a,b!'

Because of this, test_write_lineterminator (Lib/test/test_csv.py) is marked @unittest.expectedFailure — it fails only on the '!@#' subcase.

Scope is limited to the multi-character lineterminator. Left as separate follow-ups: lineterminator validation parity, non-ASCII delimiter/quotechar/escapechar (see #8310), and reader semantics (CPython's reader ignores lineterminator and only recognizes CR/LF).

Python Documentation or reference to CPython source code

https://docs.python.org/3/library/csv.html#csv.Dialect.lineterminator

Drafted with AI assistance (Claude Code), reviewed by me.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions