changeset 50750:f173c2c23289 stable

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.
author Mads Kiilerich <mads@kiilerich.com>
date Tue, 27 Jun 2023 08:39:12 +0200
parents a2df74853f8d
children b9eb65a1ec14
files mercurial/vfs.py
diffstat 1 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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)