Skip to content

Commit

Permalink
Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree
Browse files Browse the repository at this point in the history
  • Loading branch information
groodt committed Jul 10, 2023
1 parent ea727e4 commit 25f4e6e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ def get_prog() -> str:
# Tenacity raises RetryError by default, explicitly raise the original exception
@retry(reraise=True, stop=stop_after_delay(3), wait=wait_fixed(0.5))
def rmtree(dir: str, ignore_errors: bool = False) -> None:
shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler)
if sys.version_info >= (3, 12):
shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler)
else:
shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler)


def rmtree_errorhandler(func: Callable[..., Any], path: str, exc_info: ExcInfo) -> None:
def rmtree_errorhandler(func: Callable[..., Any], path: str, exc_info: Union[ExcInfo, BaseException]) -> None:
"""On Windows, the files in .svn are read-only, so when rmtree() tries to
remove them, an exception is thrown. We catch that here, remove the
read-only attribute, and hopefully continue without problems."""
Expand Down

0 comments on commit 25f4e6e

Please sign in to comment.