diff --git a/path/__init__.py b/path/__init__.py index 33dd979..d278091 100644 --- a/path/__init__.py +++ b/path/__init__.py @@ -928,7 +928,7 @@ def lines( def write_lines( self, - lines: list[str], + lines: Iterable[str], encoding: str | None = None, errors: str = 'strict', *, @@ -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. diff --git a/tests/test_path.py b/tests/test_path.py index b424bb6..dd92544 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -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'