Skip to content

Commit e53cf3d

Browse files
authored
Merge pull request #12137 from groodt/groodt-fix-deprecation-warning
2 parents 38a8fb1 + 2c4947d commit e53cf3d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

news/11957.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix deprecation warnings in Python 3.12 for usage of shutil.rmtree

src/pip/_internal/utils/misc.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,15 @@ 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(
137+
func: Callable[..., Any], path: str, exc_info: Union[ExcInfo, BaseException]
138+
) -> None:
134139
"""On Windows, the files in .svn are read-only, so when rmtree() tries to
135140
remove them, an exception is thrown. We catch that here, remove the
136141
read-only attribute, and hopefully continue without problems."""

0 commit comments

Comments
 (0)