Summary
csv.writer panics when quoting is set to csv.QUOTE_STRINGS or
csv.QUOTE_NOTNULL.
Both constants are exposed by RustPython, but the writer path still reaches a
todo!() implementation for these quote styles.
Reproducer
import csv
import io
buf = io.StringIO()
csv.writer(buf, quoting=csv.QUOTE_STRINGS).writerow(["x", 1, None, ""])
print(repr(buf.getvalue()))
buf = io.StringIO()
csv.writer(buf, quoting=csv.QUOTE_NOTNULL).writerow(["x", 1, None, ""])
print(repr(buf.getvalue()))
Expected
CPython exits normally and produces:
'"x",1,,""\r\n'
'"x","1",,""\r\n'
QUOTE_STRINGS quotes fields whose original value is a string, while None
is written as an empty unquoted field.
QUOTE_NOTNULL quotes every field except None, which is written as an empty
unquoted field.
A single empty field produced from None should raise csv.Error:
csv.writer(io.StringIO(), quoting=csv.QUOTE_STRINGS).writerow([None])
csv.writer(io.StringIO(), quoting=csv.QUOTE_NOTNULL).writerow([None])
Actual
RustPython panics with:
thread 'main' panicked at crates/stdlib/src/csv.rs:...:
not yet implemented
The panic comes from the QuoteStyle::Strings / QuoteStyle::Notnull mapping
inside the native _csv implementation.
Python Documentation
csv.QUOTE_STRINGS and csv.QUOTE_NOTNULL are documented quoting constants:
https://docs.python.org/3/library/csv.html#csv.QUOTE_STRINGS
https://docs.python.org/3/library/csv.html#csv.QUOTE_NOTNULL
Summary
csv.writerpanics whenquotingis set tocsv.QUOTE_STRINGSorcsv.QUOTE_NOTNULL.Both constants are exposed by RustPython, but the writer path still reaches a
todo!()implementation for these quote styles.Reproducer
Expected
CPython exits normally and produces:
QUOTE_STRINGSquotes fields whose original value is a string, whileNoneis written as an empty unquoted field.
QUOTE_NOTNULLquotes every field exceptNone, which is written as an emptyunquoted field.
A single empty field produced from
Noneshould raisecsv.Error:Actual
RustPython panics with:
The panic comes from the
QuoteStyle::Strings/QuoteStyle::Notnullmappinginside the native
_csvimplementation.Python Documentation
csv.QUOTE_STRINGSandcsv.QUOTE_NOTNULLare documented quoting constants:https://docs.python.org/3/library/csv.html#csv.QUOTE_STRINGS
https://docs.python.org/3/library/csv.html#csv.QUOTE_NOTNULL