Title: csv: support multi-character lineterminator in writer by jinmay · Pull Request #8328 · RustPython/RustPython · GitHub
Open Graph Title: csv: support multi-character lineterminator in writer by jinmay · Pull Request #8328 · RustPython/RustPython
X Title: csv: support multi-character lineterminator in writer by jinmay · Pull Request #8328 · RustPython/RustPython
Description: Closes #8322 This PR follows our AI policy Summary csv.writer rejected any lineterminator that was not a single character — including the default '\r\n' when passed explicitly — because the dialect stored it as a single-byte csv_core::Terminator. CPython accepts an arbitrary-length terminator. The dialect now stores the line terminator as an owned String (dropping PyDialect's Copy derive). The hand-written writer paths (QUOTE_MINIMAL / QUOTE_NONE / QUOTE_STRINGS / QUOTE_NOTNULL) emit the full terminator directly. The csv_core-backed QUOTE_ALL / QUOTE_NONNUMERIC paths still rely on csv_core for its quoting bookkeeping, so they emit a one-byte sentinel terminator (keeping csv_core's closing-quote / empty-record handling intact) and then replace that sentinel with the real terminator. field_needs_quotes / field_needs_escape now quote/escape a field containing any byte of the terminator, matching CPython. The reader now ignores lineterminator and always splits on \r / \n / \r\n, matching CPython (csv.reader never honored the dialect terminator) and avoiding a mid-UTF-8 record split that a multi-byte terminator would otherwise cause. import csv, io sio = io.StringIO() csv.writer(sio, lineterminator="!@#").writerow(["a", "b"]) # before: TypeError: "lineterminator" must be a 1-character string # after: 'a,b!@#' (matches CPython) Scoped to ASCII terminators; non-ASCII/surrogate terminators and empty-terminator acceptance are left for a follow-up. Test plan Unmarks test_write_lineterminator (@unittest.expectedFailure before). cargo run --release -- -m test test_csv: 128 run, 7 skipped, SUCCESS. extra_tests/snippets/stdlib_csv.py: passes (added test_multichar_lineterminator covering multi-char terminators, terminator-byte quoting, QUOTE_ALL / QUOTE_NONNUMERIC, QUOTE_NONE escaping, register_dialect round-trip, and reader behavior; verified on both RustPython and CPython). cargo fmt --check / cargo clippy: clean (no new warnings). Compared against CPython 3.14 on the same machine; the writer outputs match for ASCII terminators. Assisted-by: Claude Code:claude-opus-4-8 Summary by CodeRabbit Bug Fixes CSV dialects and lineterminator now support arbitrary non-empty multi-character line terminators. CSV writers emit the full configured terminator consistently across quoting modes, including QUOTE_NONE escaping. CSV readers reliably split records on \r\n, keeping any other terminator text as normal field content (CPython-aligned). Dialect registration and retrieval preserve the complete lineterminator value. Tests Added a snippet test for multi-character terminators covering multiple quoting modes, dialect round-tripping, and reader behavior.
Open Graph Description: Closes #8322 This PR follows our AI policy Summary csv.writer rejected any lineterminator that was not a single character — including the default '\r\n' when passed explicitly — because t...
X Description: Closes #8322 This PR follows our AI policy Summary csv.writer rejected any lineterminator that was not a single character — including the default '\r\n' when passed explicitly — b...
Opengraph URL: https://github.com/RustPython/RustPython/pull/8328
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4b3b319e-bf7c-6c68-1ec3-07fb34bf15e2 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | D3EC:2EB4B1:1A83672:2531AF3:6A5FB5FD |
| html-safe-nonce | 6d43b042d506267f9c1dfed8e8b15a1bbb05609cb422a4f8ac265c05585be7b2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEM0VDOjJFQjRCMToxQTgzNjcyOjI1MzFBRjM6NkE1RkI1RkQiLCJ2aXNpdG9yX2lkIjoiNTAxMTI4NDI2NzU3NjI2ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 927cca11b5280f657c85c79dbbb2fcc6082b6d701980f119538cf4364c0c4617 |
| hovercard-subject-tag | pull_request:4087771910 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8328/files |
| twitter:image | https://avatars.githubusercontent.com/u/13075035?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/13075035?s=400&v=4 |
| og:image:alt | Closes #8322 This PR follows our AI policy Summary csv.writer rejected any lineterminator that was not a single character — including the default '\r\n' when passed explicitly — because t... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e0cfc367faf9c4c774d2a903897aa214c786247c4f45ffcee48cda2b819fb0c8 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git |
| octolytics-dimension-user_id | 39710557 |
| octolytics-dimension-user_login | RustPython |
| octolytics-dimension-repository_id | 135201145 |
| octolytics-dimension-repository_nwo | RustPython/RustPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 135201145 |
| octolytics-dimension-repository_network_root_nwo | RustPython/RustPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 94569c859bc88d6bf7de7e0ce3f2a11cd529a131 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width