This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xflr6
Recipients ebreck, taleinat, xflr6
Date 2021-08-07.14:57:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628348225.56.0.708449688444.issue44861@roundup.psfhosted.org>
In-reply-to
Content
AFAICT there was an undocumented change in behaviour related to the fix of https://bugs.python.org/issue12178 (also reported in https://bugs.python.org/issue12178#msg397440):

Python 3.9 quotes values with escapechar:

```
import csv
import io

kwargs = {'escapechar': '\\'}

value = 'spam\\eggs'

print(value)

with io.StringIO() as buf:
    writer = csv.writer(buf, **kwargs)
    writer.writerow([value])
    line = buf.getvalue()

print(line.strip())

with io.StringIO(line) as buf:
    reader = csv.reader(buf, **kwargs)
    (new_value,), = reader

print(new_value)
spam\eggs
"spam\eggs"
spameggs
```

- quotes escapechar
- fails to double the escapechar (https://bugs.python.org/issue12178)

From https://docs.python.org/3/library/csv.html#csv.QUOTE_MINIMAL

> only quote those fields which contain special characters
> such as delimiter, quotechar or any of the characters in
> lineterminator.

The previous behaviour seems incorrect because escapechar is not explicitly mentioned, but at the same time the docs says 'such as'.

The new might better matching the name 'minimal', but at the same time one might regard 'quote when in doubt' as a safer behaviour for the default quoting rule.

Python 3.10:

https://github.com/python/cpython/blob/5c0eed7375fdd791cc5e19ceabfab4170ad44062/Lib/test/test_csv.py#L207-L208

See also https://github.com/xflr6/csv23/actions/runs/1027687524
History
Date User Action Args
2021-08-07 14:57:05xflr6setrecipients: + xflr6, taleinat, ebreck
2021-08-07 14:57:05xflr6setmessageid: <1628348225.56.0.708449688444.issue44861@roundup.psfhosted.org>
2021-08-07 14:57:05xflr6linkissue44861 messages
2021-08-07 14:57:04xflr6create