mypy chia.util.files (#14541)

<!-- Merging Requirements:
- Please give your PR a title that is release-note friendly
- In order to be merged, you must add the most appropriate category
Label (Added, Changed, Fixed) to your PR
-->
<!-- Explain why this is an improvement (Does this add missing
functionality, improve performance, or reduce complexity?) -->
### Purpose:

Code cleanup

<!-- Does this PR introduce a breaking change? -->
### Current Behavior:



### New Behavior:



<!-- As we aim for complete code coverage, please include details
regarding unit, and regression tests -->
### Testing Notes:



<!-- Attach any visual examples, or supporting evidence (attach any
.gif/video/console output below) -->
This commit is contained in:
Justin England 2023-04-11 14:29:42 -06:00 committed by GitHub
commit c0621737c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

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,6 +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:
# Ignoring type error since it is not obvious how to tie the type of the data
# being passed in to the type of the file object, etc.
temp_file_path = f.name # type: ignore[assignment]
await f.write(data) # type: ignore[arg-type]
await f.flush()

File diff suppressed because one or more lines are too long