vfs: handle shutil.rmtree deprecation of onerror in Python 3.12 stable
authorMads Kiilerich <mads@kiilerich.com>
Tue, 27 Jun 2023 08:39:12 +0200
branchstable
changeset 50754 f173c2c23289
parent 50753 a2df74853f8d
child 50755 b9eb65a1ec14
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.
mercurial/vfs.py
--- a/mercurial/vfs.py	Tue Jun 27 10:09:11 2023 +0200
+++ b/mercurial/vfs.py	Tue Jun 27 08:39:12 2023 +0200
@@ -274,7 +274,7 @@
         """
         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,17 @@
                 os.remove(path)
 
         else:
-            onerror = None
-        return shutil.rmtree(
-            self.join(path), ignore_errors=ignore_errors, onerror=onerror
-        )
+            onexc = None
+        try:
+            # pytype: disable=wrong-keyword-args
+            return shutil.rmtree(
+                self.join(path), ignore_errors=ignore_errors, onexc=onexc
+            )
+            # pytype: enable=wrong-keyword-args
+        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)