diff mercurial/transaction.py @ 52640:24ee91ba9aa8

pyupgrade: drop usage of py3 aliases for `OSError` These were different classes in py2, but now a handful of error classes are just an alias of `OSError`, like `IOError`, `EnvironmentError`, `WindowsError`, etc. This is the result of running a hacked version of `pyupgrade` 3.19.1[1] $ hg files -0 'relglob:**.py' | xargs -0 \ pyupgrade --py38-plus --keep-percent-format --keep-mock --keep-runtime-typing The hack is because it doesn't have command line switches to disable most changes, so it makes tons of unrelated changes all at once. The hack is to 1) patch `pyupgrade._main._fix_tokens()` to immediately return its content arg 2) change `pyupgrade._data.register_decorator()` to only register the function if it's from the fixer we're interested in: if func.__module__ in ( "pyupgrade._plugins.exceptions", ): FUNCS[tp].append(func) return func [1] https://github.com/asottile/pyupgrade
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 05 Jan 2025 21:03:17 -0500
parents f4733654f144
children ae2848198462
line wrap: on
line diff
--- a/mercurial/transaction.py	Mon Jan 06 14:15:40 2025 -0500
+++ b/mercurial/transaction.py	Sun Jan 05 21:03:17 2025 -0500
@@ -126,7 +126,7 @@
         try:
             util.copyfile(backuppath, filepath, checkambig=checkambig)
             backupfiles.append((vfs, b))
-        except IOError as exc:
+        except OSError as exc:
             e_msg = stringutil.forcebytestr(exc)
             report(_(b"failed to recover %s (%s)\n") % (f, e_msg))
             raise
@@ -169,7 +169,7 @@
                     )
                 fp.truncate(o)
                 fp.close()
-            except IOError:
+            except OSError:
                 report(_(b"failed to truncate %s\n") % f)
                 raise
         else:
@@ -206,7 +206,7 @@
                     # in both case, our target result (delete the file) is
                     # already achieved.
                     pass
-        except (IOError, OSError, error.Abort):
+        except (OSError, error.Abort):
             if not c:
                 raise
 
@@ -219,7 +219,7 @@
         for vfs, f in backupfiles:
             if vfs.exists(f):
                 vfs.unlink(f)
-    except (IOError, OSError, error.Abort):
+    except (OSError, error.Abort):
         # only pure backup file remains, it is sage to ignore any error
         pass
 
@@ -709,7 +709,7 @@
             if not f and b and vfs.exists(b):
                 try:
                     vfs.unlink(b)
-                except (IOError, OSError, error.Abort) as inst:
+                except (OSError, error.Abort) as inst:
                     if not c:
                         raise
                     # Abort may be raise by read only opener
@@ -737,7 +737,7 @@
             if b and vfs.exists(b):
                 try:
                     vfs.unlink(b)
-                except (IOError, OSError, error.Abort) as inst:
+                except (OSError, error.Abort) as inst:
                     if not c:
                         raise
                     # Abort may be raise by read only opener