Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update write_text to include newline variable #362

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion cloudpathlib/cloudpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections import defaultdict
import collections.abc
from contextlib import contextmanager
import io
import os
from pathlib import ( # type: ignore
Path,
Expand Down Expand Up @@ -626,15 +627,20 @@ def write_text(
data: str,
encoding: Optional[str] = None,
errors: Optional[str] = None,
newline: Optional[str] = None,
) -> int:
"""Open the file in text mode, write to it, and close the file.

NOTE: vendored from pathlib since we override open
https://github.com/python/cpython/blob/3.8/Lib/pathlib.py#L1244-L1252
pricemg marked this conversation as resolved.
Show resolved Hide resolved
https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L1146-L1155
"""
if not isinstance(data, str):
raise TypeError("data must be str, not %s" % data.__class__.__name__)
with self.open(mode="w", encoding=encoding, errors=errors) as f:

encoding = io.text_encoding(encoding)

with self.open(mode='w', encoding=encoding, errors=errors, newline=newline) as f:
pricemg marked this conversation as resolved.
Show resolved Hide resolved
return f.write(data)

def read_bytes(self) -> bytes:
Expand Down