Skip to content

Commit

Permalink
Avoid using private typeshed name
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed May 24, 2024
1 parent d4803cb commit 5b9d6c7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions setuptools/compat/py311.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
if TYPE_CHECKING:
from _typeshed import StrOrBytesPath, ExcInfo

# Same as shutil.__OnExcCallback from typeshed
_OnExcCallback = Callable[[Callable[..., Any], str, BaseException], object]


def shutil_rmtree(
path: StrOrBytesPath,
ignore_errors: bool = False,
onexc: shutil._OnExcCallback | None = None,
onexc: _OnExcCallback | None = None,
) -> None:
if sys.version_info >= (3, 12):
return shutil.rmtree(path, ignore_errors, onexc=onexc)

def _handler(fn: Callable[..., Any], path: str, excinfo: ExcInfo) -> None:
if onexc:
# type-ignore fixed in https://github.com/python/typeshed/pull/12002
onexc(fn, path, excinfo[1]) # type: ignore[arg-type]
onexc(fn, path, excinfo[1])

return shutil.rmtree(path, ignore_errors, onerror=_handler)

0 comments on commit 5b9d6c7

Please sign in to comment.