Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@cspurk

Description

@cspurk
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    Status

    No status
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.