mypy chia.util.files

This commit is contained in:
Adam Kelly
2023-02-10 10:14:35 -08:00
parent c7fbf8b10a
commit 0c943993bd
2 changed files with 8 additions and 6 deletions
+7 -5
View File
@@ -13,7 +13,7 @@ from typing_extensions import Literal
log = logging.getLogger(__name__)
def move_file(src: Path, dst: Path):
def move_file(src: Path, dst: Path) -> None:
"""
Attempts to move the file at src to dst, falling back to a copy if the move fails.
"""
@@ -35,7 +35,7 @@ def move_file(src: Path, dst: Path):
raise
async def move_file_async(src: Path, dst: Path, *, reattempts: int = 6, reattempt_delay: float = 0.5):
async def move_file_async(src: Path, dst: Path, *, reattempts: int = 6, reattempt_delay: float = 0.5) -> None:
"""
Attempts to move the file at src to dst, making multiple attempts if the move fails.
"""
@@ -60,7 +60,9 @@ async def move_file_async(src: Path, dst: Path, *, reattempts: int = 6, reattemp
log.debug(f"Moved {src} to {dst}")
async def write_file_async(file_path: Path, data: Union[str, bytes], *, file_mode: int = 0o600, dir_mode: int = 0o700):
async def write_file_async(
file_path: Path, data: Union[str, bytes], *, file_mode: int = 0o600, dir_mode: int = 0o700
) -> None:
"""
Writes the provided data to a temporary file and then moves it to the final destination.
"""
@@ -71,8 +73,8 @@ async def write_file_async(file_path: Path, data: Union[str, bytes], *, file_mod
mode: Literal["w+", "w+b"] = "w+" if type(data) == str else "w+b"
temp_file_path: Path
async with tempfile.NamedTemporaryFile(dir=file_path.parent, mode=mode, delete=False) as f:
temp_file_path = f.name # type: ignore[assignment]
await f.write(data) # type: ignore[arg-type]
temp_file_path = f.name
await f.write(data)
await f.flush()
os.fsync(f.fileno())
+1 -1
View File
File diff suppressed because one or more lines are too long