Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

28 строки
790 B

  1. from __future__ import annotations
  2. import shutil
  3. import sys
  4. from typing import TYPE_CHECKING, Any, Callable
  5. if TYPE_CHECKING:
  6. from _typeshed import ExcInfo, StrOrBytesPath
  7. from typing_extensions import TypeAlias
  8. # Same as shutil._OnExcCallback from typeshed
  9. _OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object]
  10. def shutil_rmtree(
  11. path: StrOrBytesPath,
  12. ignore_errors: bool = False,
  13. onexc: _OnExcCallback | None = None,
  14. ) -> None:
  15. if sys.version_info >= (3, 12):
  16. return shutil.rmtree(path, ignore_errors, onexc=onexc)
  17. def _handler(fn: Callable[..., Any], path: str, excinfo: ExcInfo) -> None:
  18. if onexc:
  19. onexc(fn, path, excinfo[1])
  20. return shutil.rmtree(path, ignore_errors, onerror=_handler)