File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change 5656import sys
5757import tempfile
5858import urllib .parse
59+ import warnings
5960from collections import defaultdict , deque
6061from operator import methodcaller
6162from typing import (
@@ -532,6 +533,12 @@ def write_lines(
532533 .. versionchanged:: 2.4.0 Added the ``trailing_whitespace`` option.
533534 """
534535
536+ if isinstance (data , str ):
537+ warnings .warn (
538+ "Passing a string to PathPlus.write_lines writes each character to its own line.\n "
539+ "That probably isn't what you intended."
540+ )
541+
535542 if trailing_whitespace :
536543 data = list (data )
537544 if data [- 1 ].strip ():
Original file line number Diff line number Diff line change @@ -521,6 +521,11 @@ def test_write_lines(tmp_pathplus):
521521 content = tmp_file .read_text ()
522522 assert content == "this\n is\n a\n list\n of\n words\n to\n write\n to\n the\n file\n "
523523
524+ with pytest .warns (UserWarning , match = "Passing a string to PathPlus.write_lines writes each character to its own line." ):
525+ tmp_file .write_lines ("abcdefg" )
526+
527+ assert tmp_file .read_text () == "a\n b\n c\n d\n e\n f\n g\n "
528+
524529
525530def test_write_lines_trailing_whitespace (tmp_pathplus : PathPlus ):
526531 tmp_file = tmp_pathplus / "test.txt"
You can’t perform that action at this time.
0 commit comments