add proper typechecked json parsing and dumping

This commit is contained in:
Nick Sweeting 2019-03-30 15:03:46 -04:00
parent 35c05c321f
commit 73f46b0b29
3 changed files with 75 additions and 22 deletions
archivebox

View file

@ -675,8 +675,8 @@ class ExtendedEncoder(JSONEncoder):
return JSONEncoder.default(self, obj)
def atomic_write(contents: Union[dict, str], path: str):
"""Safe atomic file write and swap using a tmp file"""
def atomic_write(contents: Union[dict, str], path: str) -> None:
"""Safe atomic write to filesystem by writing to temp file + atomic rename"""
try:
tmp_file = '{}.tmp'.format(path)
with open(tmp_file, 'w+', encoding='utf-8') as f: