summaryrefslogtreecommitdiff
path: root/file_utils.py
diff options
context:
space:
mode:
authorScott <[email protected]>2022-02-02 09:14:12 -0800
committerScott <[email protected]>2022-02-02 09:14:12 -0800
commita4bf4d05230474ad14243d67ac7f8c938f670e58 (patch)
tree673fb8bea628ce51b942d93ba5df433732c7384e /file_utils.py
parent971d4ba141459f78d10d5770b9459d1ead7d49a0 (diff)
More type annotations.
Diffstat (limited to 'file_utils.py')
-rw-r--r--file_utils.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/file_utils.py b/file_utils.py
index cd37f30..f273ea4 100644
--- a/file_utils.py
+++ b/file_utils.py
@@ -14,7 +14,7 @@ import time
from typing import Optional
import glob
from os.path import isfile, join, exists
-from typing import List
+from typing import List, TextIO
from uuid import uuid4
@@ -332,11 +332,13 @@ def get_file_md5(filename: str) -> str:
def set_file_raw_atime(filename: str, atime: float):
mtime = get_file_raw_mtime(filename)
+ assert mtime
os.utime(filename, (atime, mtime))
def set_file_raw_mtime(filename: str, mtime: float):
atime = get_file_raw_atime(filename)
+ assert atime
os.utime(filename, (atime, mtime))
@@ -434,8 +436,8 @@ def describe_file_mtime(filename: str, *, brief=False) -> Optional[str]:
return describe_file_timestamp(filename, lambda x: x.st_mtime, brief=brief)
-def touch_file(filename: str, *, mode: Optional[int] = 0o666) -> bool:
- return pathlib.Path(filename, mode=mode).touch()
+def touch_file(filename: str, *, mode: Optional[int] = 0o666):
+ pathlib.Path(filename, mode=mode).touch()
def expand_globs(in_filename: str):
@@ -470,14 +472,14 @@ class FileWriter(object):
self.filename = filename
uuid = uuid4()
self.tempfile = f'{filename}-{uuid}.tmp'
- self.handle = None
+ self.handle: Optional[TextIO] = None
- def __enter__(self) -> io.TextIOWrapper:
+ def __enter__(self) -> TextIO:
assert not does_path_exist(self.tempfile)
self.handle = open(self.tempfile, mode="w")
return self.handle
- def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
+ def __exit__(self, exc_type, exc_val, exc_tb) -> Optional[bool]:
if self.handle is not None:
self.handle.close()
cmd = f'/bin/mv -f {self.tempfile} {self.filename}'