Skip to content

Treat write_text newline separators as literal text - #280

Open
Sarbajit-Sengupta wants to merge 1 commit into
jaraco:mainfrom
Sarbajit-Sengupta:fix/literal-newline-replacement
Open

Sarbajit-Sengupta wants to merge 1 commit into
jaraco:mainfrom
Sarbajit-Sengupta:fix/literal-newline-replacement

Conversation

@Sarbajit-Sengupta

Copy link
Copy Markdown

Path.write_text(linesep=...) currently interprets the separator as a regex replacement template. For example, linesep=r'\n' writes a newline instead of the two requested characters, while linesep=r'\1' raises an invalid-group-reference error. A separator consisting of a single backslash also raises an error.

Use a callable replacement so the supplied separator is literal text. Added 16 cases covering backslash sequences, ordinary newline separators, an empty separator and None, in both overwrite and append modes. Added the required release-note fragment.

The four backslash cases fail on the base revision. tox -e py313 passes on Windows with 174 passed and 7 skipped, including doctests, Ruff formatting/lint checks, mypy and coverage (98% overall). git diff --check also passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant