From f39b054b9c8cbbf884f53123eef028131789990c Mon Sep 17 00:00:00 2001 From: Kwak Byoung Min <67214970+doma17@users.noreply.github.com> Date: Sun, 4 Oct 2026 13:53:35 +0900 Subject: [PATCH] Match CPython quotechar escaping when doublequote is disabled (#8953) Let quote-only fields use the existing unquoted escaping path and enable the existing CPython regression test. Tested: test_csv, CSV snippet, 240 CPython comparisons, workspace and C-API tests, Clippy, prek Assisted-by: Codex:gpt-6.1-sol --- Lib/test/test_csv.py | 1 - crates/stdlib/src/csv.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py index 7e76f4bc1..21b02c2f0 100644 --- a/Lib/test/test_csv.py +++ b/Lib/test/test_csv.py @@ -228,7 +228,6 @@ class Test_Csv(unittest.TestCase): self._write_test(['a','',None,1], '"a","",,"1"', quoting = csv.QUOTE_NOTNULL) - @unittest.expectedFailure # TODO: RUSTPYTHON def test_write_escape(self): self._write_test(['a',1,'p,q'], 'a,1,"p,q"', escapechar='\\') diff --git a/crates/stdlib/src/csv.rs b/crates/stdlib/src/csv.rs index a0f75300e..b07f9c644 100644 --- a/crates/stdlib/src/csv.rs +++ b/crates/stdlib/src/csv.rs @@ -1246,7 +1246,7 @@ mod _csv { fn field_needs_quotes(data: &[u8], dialect: &PyDialect) -> bool { data.iter().any(|&byte| { byte == dialect.delimiter - || dialect.quotechar == Some(byte) + || (dialect.doublequote && dialect.quotechar == Some(byte)) || matches!(byte, b'\r' | b'\n') }) || data_contains_lineterminator_char(data, dialect) }