Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV Writer Regression in Python 3.11+: Escaping Required but Unnecessary #128064

Open
cspurk opened this issue Dec 18, 2024 · 0 comments
Open

CSV Writer Regression in Python 3.11+: Escaping Required but Unnecessary #128064

cspurk opened this issue Dec 18, 2024 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@cspurk
Copy link

cspurk commented Dec 18, 2024

Bug report

Bug description:

The following csvtest.py script works for Python 3.10 and earlier but fails for 3.11 and later:

import csv
import io
b = io.StringIO()
csv.writer(b, quoting=csv.QUOTE_NONE, lineterminator='\n').writerow(["\r"])
print(repr(b.getvalue()))

For example, running the shell script …

for v in 9 10 11 12 13; do
    pyenv shell 3.$v
    python --version
    python csvtest.py
done

… yields:

Python 3.9.21
'\r\n'
Python 3.10.16
'\r\n'
Python 3.11.11
Traceback (most recent call last):
  File "/tmp/csvtest.py", line 4, in <module>
    csv.writer(b, quoting=csv.QUOTE_NONE, lineterminator='\n').writerow(["\r"])
_csv.Error: need to escape, but no escapechar set
Python 3.12.8
Traceback (most recent call last):
  File "/tmp/csvtest.py", line 4, in <module>
    csv.writer(b, quoting=csv.QUOTE_NONE, lineterminator='\n').writerow(["\r"])
_csv.Error: need to escape, but no escapechar set
Python 3.13.1
Traceback (most recent call last):
  File "/tmp/csvtest.py", line 4, in <module>
    csv.writer(b, quoting=csv.QUOTE_NONE, lineterminator='\n').writerow(["\r"])
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
_csv.Error: need to escape, but no escapechar set

As in Python 3.10 and earlier, escaping the carriage return character (\r) should not be necessary (due to the custom lineterminator), but Python 3.11+ still expects it.

CPython versions tested on:

3.9, 3.10, 3.11, 3.12, 3.13

Operating systems tested on:

Linux

@cspurk cspurk added the type-bug An unexpected behavior, bug, or error label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

1 participant