Write text to file atomically to prevent corruption on interruption.
(path: Path, text: str)
| 2 | |
| 3 | |
| 4 | def atomic_write(path: Path, text: str) -> None: |
| 5 | """Write text to file atomically to prevent corruption on interruption.""" |
| 6 | tmp_file = path.with_suffix(".tmp") |
| 7 | tmp_file.write_text(text) |
| 8 | tmp_file.rename(path) |
no outgoing calls
no test coverage detected