1- # mypy: allow-untyped-defs
21import atexit
32import contextlib
43from enum import Enum
2322import sys
2423import types
2524from types import ModuleType
25+ from typing import Any
2626from typing import Callable
2727from typing import Dict
2828from typing import Iterable
5959)
6060
6161
62- def _ignore_error (exception ) :
62+ def _ignore_error (exception : Exception ) -> bool :
6363 return (
6464 getattr (exception , "errno" , None ) in _IGNORED_ERRORS
6565 or getattr (exception , "winerror" , None ) in _IGNORED_WINERRORS
@@ -71,7 +71,7 @@ def get_lock_path(path: _AnyPurePath) -> _AnyPurePath:
7171
7272
7373def on_rm_rf_error (
74- func ,
74+ func : Optional [ Callable [..., Any ]] ,
7575 path : str ,
7676 excinfo : Union [
7777 BaseException ,
@@ -196,7 +196,7 @@ def find_suffixes(root: Path, prefix: str) -> Iterator[str]:
196196 return extract_suffixes (find_prefixed (root , prefix ), prefix )
197197
198198
199- def parse_num (maybe_num ) -> int :
199+ def parse_num (maybe_num : str ) -> int :
200200 """Parse number path suffixes, returns -1 on error."""
201201 try :
202202 return int (maybe_num )
@@ -264,7 +264,9 @@ def create_cleanup_lock(p: Path) -> Path:
264264 return lock_path
265265
266266
267- def register_cleanup_lock_removal (lock_path : Path , register = atexit .register ):
267+ def register_cleanup_lock_removal (
268+ lock_path : Path , register : Any = atexit .register
269+ ) -> Any :
268270 """Register a cleanup function for removing a lock, by default on atexit."""
269271 pid = os .getpid ()
270272
@@ -355,7 +357,7 @@ def cleanup_candidates(root: Path, prefix: str, keep: int) -> Iterator[Path]:
355357 yield Path (entry )
356358
357359
358- def cleanup_dead_symlinks (root : Path ):
360+ def cleanup_dead_symlinks (root : Path ) -> None :
359361 for left_dir in root .iterdir ():
360362 if left_dir .is_symlink ():
361363 if not left_dir .resolve ().exists ():
@@ -459,10 +461,14 @@ def parts(s: str) -> Set[str]:
459461 return {sep .join (parts [: i + 1 ]) or sep for i in range (len (parts ))}
460462
461463
462- def symlink_or_skip (src , dst , ** kwargs ):
464+ def symlink_or_skip (
465+ src : Union ["os.PathLike[str]" , str ],
466+ dst : Union ["os.PathLike[str]" , str ],
467+ ** kwargs : Any ,
468+ ) -> None :
463469 """Make a symlink, or skip the test in case symlinks are not supported."""
464470 try :
465- os .symlink (str ( src ), str ( dst ) , ** kwargs )
471+ os .symlink (src , dst , ** kwargs )
466472 except OSError as e :
467473 skip (f"symlinks not supported: { e } " )
468474
0 commit comments