mercurial/vfs.py
branchstable
changeset 50751 f173c2c23289
parent 50365 d1d458fb96a5
child 50926 18c8c18993f0
--- 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)