Skip to content

Commit 25f4e6e

Browse files
committed
Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree
1 parent ea727e4 commit 25f4e6e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/pip/_internal/utils/misc.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,13 @@ def get_prog() -> str:
127127
# Tenacity raises RetryError by default, explicitly raise the original exception
128128
@retry(reraise=True, stop=stop_after_delay(3), wait=wait_fixed(0.5))
129129
def rmtree(dir: str, ignore_errors: bool = False) -> None:
130-
shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler)
130+
if sys.version_info >= (3, 12):
131+
shutil.rmtree(dir, ignore_errors=ignore_errors, onexc=rmtree_errorhandler)
132+
else:
133+
shutil.rmtree(dir, ignore_errors=ignore_errors, onerror=rmtree_errorhandler)
131134

132135

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

0 commit comments

Comments
 (0)