Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions path/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def lines(

def write_lines(
self,
lines: list[str],
lines: Iterable[str],
encoding: str | None = None,
errors: str = 'strict',
*,
Expand All @@ -940,7 +940,7 @@ def write_lines(

Puts a platform-specific newline sequence on every line.

`lines` - A list of strings.
`lines` - An iterable of strings.

`encoding` - A Unicode encoding to use. This applies only if
`lines` contains any Unicode strings.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,3 +1398,10 @@ def test_ignore(self):
def test_invalid_handler(self):
with pytest.raises(ValueError):
path.Handlers._resolve('raise')


def test_write_lines_iterables(tmp_path) -> None:
target = Path(tmp_path) / 'lines.txt'
target.write_lines(('one\r\n', 'two\n'))
target.write_lines((line for line in ('three', 'four\r')), append=True)
assert target.read_text() == 'one\ntwo\nthree\nfour\n'