[PATCH 3 of 6] vfs: handle shutil.rmtree deprecation of onerror in Python 3.12
Mads Kiilerich
mads at kiilerich.com
Wed Jun 28 14:43:38 UTC 2023
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1687847952 -7200
# Tue Jun 27 08:39:12 2023 +0200
# Branch stable
# Node ID b6633799949e428d27f7704636da0da31a599e6b
# Parent 27c7a6d21b9dae4d465a569480331d2467b423f2
vfs: handle shutil.rmtree deprecation of onerror in Python 3.12
Tests would fail with warnings:
.../mercurial/vfs.py:289: DeprecationWarning: onerror argument is deprecated, use onexc instead
The excinfo changed slightly, but we don't use it anyway.
diff --git a/mercurial/vfs.py b/mercurial/vfs.py
--- a/mercurial/vfs.py
+++ b/mercurial/vfs.py
@@ -274,7 +274,7 @@ class abstractvfs:
"""
if forcibly:
- def onerror(function, path, excinfo):
+ def onexc(function, path, excinfo):
if function is not os.remove:
raise
# read-only files cannot be unlinked under Windows
@@ -285,10 +285,15 @@ class abstractvfs:
os.remove(path)
else:
- onerror = None
- return shutil.rmtree(
- self.join(path), ignore_errors=ignore_errors, onerror=onerror
- )
+ onexc = None
+ try:
+ return shutil.rmtree(
+ self.join(path), ignore_errors=ignore_errors, onexc=onexc
+ )
+ except TypeError: # onexc was introduced in Python 3.12
+ return shutil.rmtree(
+ self.join(path), ignore_errors=ignore_errors, onerror=onexc
+ )
def setflags(self, path: bytes, l: bool, x: bool):
return util.setflags(self.join(path), l, x)
More information about the Mercurial-devel
mailing list