Repository navigation
csv: support non-ASCII Unicode dialect characters - #9367
Conversation
The redundant-test-patches pre-commit hook uses `language: script`, which requires the executable bit, and fails on every commit touching Lib/test. Assisted-by: Claude:claude-sonnet-5-5
Store delimiter, quotechar and escapechar as `char` instead of `u8`, and run the reader state machine and the writer over code points, so that a single non-ASCII character such as `€` is accepted like in CPython. The field size limit is now counted in characters rather than bytes. Fixes RustPython#8408 Assisted-by: Claude:claude-sonnet-5-5
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Unicode dialect attributes crates/stdlib/src/csv.rs |
Dialect character attributes use char values. Parsing and validation retain checks for empty or multi-character values and line-break characters. |
Unicode CSV input and parsing crates/stdlib/src/csv.rs |
The reader decodes input as UTF-8. The parser processes characters, stores fields in a String, and counts field limits by character. |
Unicode CSV output and validation crates/stdlib/src/csv.rs, extra_tests/snippets/stdlib_csv.py |
The writer builds and writes a String, with character-based quoting and escaping. Tests cover non-ASCII dialect characters and invalid delimiter values. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Low
Suggested reviewers: widehyo1, hyoinandout
Merge Risk: 
Minimal · up to eea76
-
No concrete issue requiring a fix before merge is established by the available evidence.
Pre-merge checks: 
3 · 
2
-
Failed checks: 2 warnings Passed checks: 3 passed-
Full details: Title check
-
Explanation
The title "csv: support non-ASCII Unicode dialect characters" matches the main change. The PR changes CSV delimiter, quotechar, and escapechar from u8 to char, and the reader and writer now operate on code points. The added test covers non-ASCII delimiter, quote, and escape characters. The title is concise, specific, and follows the linked issue
#8408scope. Empty and multi-character values remain rejected, as the title implies.
Full details: Linked Issues check
-
Explanation
Issue
#8408requires full Unicode code points fordelimiter,quotechar, andescapechar, while preserving empty and multi-character validation. The summary reportschar/Stringstorage, character-based reader and writer processing, and rejection of invalid lengths. The addedtest_non_ascii_dialect_charscovers reader and writer round trips with€, invalid delimiter lengths, and delimiter/quote conflicts. The reported behavior satisfies the issue requirements.
-
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/traceback.py dependencies:
dependent tests: (170 tests)
[ ] test: cpython/Lib/test/test_external_inspection.py dependencies: dependent tests: (no tests depend on external_inspection) [ ] lib: cpython/Lib/profiling dependencies:
dependent tests: (3 tests)
[ ] test: cpython/Lib/test/test_set.py (TODO: 2) dependencies: dependent tests: (no tests depend on set) [x] lib: cpython/Lib/csv.py dependencies:
dependent tests: (4 tests)
Legend:
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
That would require some sort of speed benchmark/testing, because I think perf should change a bit. But it might go from « unnoticeable » to « significant ». But anyway, the previous behavior was incorrect (delimiter chars never meant to be 1 byte). And also, by doing this change, it fixes few existing unicode mis-handlings. |
|
Thanks for the fix! The implementation looks good to me. |
Fixes #8408
delimiter,quotecharandescapecharwere stored asu8, so valid one-character values outside the byte range (e.g.€) were rejected. They are now stored aschar, and the reader state machine and the writer operate on code points. Empty and multi-character values are still rejected with the same messages.Notes:
UnicodeDecodeErrorin the data path).Lib/test/test_csv.py:test_dialect_apply(which uses aΛdelimiter) now passes, so itsexpectedFailureis removed.test_non_ascii_dialect_charsto the existingextra_tests/snippets/stdlib_csv.py.scripts/check_redundant_patches.pyexecutable: theredundant-test-patcheshook useslanguage: scriptand fails on any commit touchingLib/testotherwise. It is independent and can be dropped if preferred.Tested locally:
cargo run --release -- -m test test_csv, the snippet,cargo clippy -p rustpython-stdlib --all-targets,cargo test -p rustpython-stdlib.AI assistance: written with Claude (see
Assisted-bytrailers).🤖 Generated with Claude Code
Summary by CodeRabbit