# HG changeset patch
# User Mads Kiilerich <m...@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)

_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@lists.mercurial-scm.org
https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to