Skip to content

Commit

Permalink
Update write_text to include newline variable (#362) (#363)
Browse files Browse the repository at this point in the history
* Update write_text to include newline variable

* Remove old docstring link

* Update cloudpathlib/cloudpath.py with black correction

* Remove use of io module

* update HISTORY.md

Co-authored-by: Matthew Price <matthew.price23@gmail.com>
  • Loading branch information
pjbull and pricemg committed Sep 14, 2023
1 parent d2079cc commit e6ae9fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY.md
Expand Up @@ -3,6 +3,7 @@
## UNRELEASED
- Add "CloudPath" as return type on `__init__` for mypy issues. ([Issue #179](https://github.com/drivendataorg/cloudpathlib/issues/179), [PR #342](https://github.com/drivendataorg/cloudpathlib/pull/342))
- Add `with_stem` to all path types when python version supports it (>=3.9). ([Issue #287](https://github.com/drivendataorg/cloudpathlib/issues/287), [PR #290](https://github.com/drivendataorg/cloudpathlib/pull/290), thanks to [@Gilthans](https://github.com/Gilthans))
- Add `newline` parameter to the `write_text` method to align to `pathlib` functionality as of Python 3.10. [PR #362]https://github.com/drivendataorg/cloudpathlib/pull/362), thanks to [@pricemg](https://github.com/pricemg).

## v0.15.1 (2023-07-12)

Expand Down
6 changes: 4 additions & 2 deletions cloudpathlib/cloudpath.py
Expand Up @@ -626,15 +626,17 @@ 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
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:

with self.open(mode="w", encoding=encoding, errors=errors, newline=newline) as f:
return f.write(data)

def read_bytes(self) -> bytes:
Expand Down

0 comments on commit e6ae9fa

Please sign in to comment.