diff mercurial/ui.py @ 52665: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 cc918741a22a
children e627cc25b6f3
line wrap: on
line diff
--- a/mercurial/ui.py	Mon Jan 06 14:15:40 2025 -0500
+++ b/mercurial/ui.py	Sun Jan 05 21:03:17 2025 -0500
@@ -464,7 +464,7 @@
     ) -> None:
         try:
             fp = resourceutil.open_resource(name[0], name[1])
-        except IOError:
+        except OSError:
             if not sections:  # ignore unless we were looking for something
                 return
             raise
@@ -478,7 +478,7 @@
     ) -> None:
         try:
             fp = open(filename, 'rb')
-        except IOError:
+        except OSError:
             if not sections:  # ignore unless we were looking for something
                 return
             raise
@@ -1261,7 +1261,7 @@
                     label = opts.get('label', b'')
                     msg = self.label(msg, label)
                 dest.write(msg)
-        except IOError as err:
+        except OSError as err:
             raise error.StdioError(err)
         finally:
             self._blockedtimes[b'stdio_blocked'] += (
@@ -1310,7 +1310,7 @@
             # including stdout.
             if dest is self._ferr and not getattr(dest, 'closed', False):
                 dest.flush()
-        except IOError as err:
+        except OSError as err:
             if dest is self._ferr and err.errno in (
                 errno.EPIPE,
                 errno.EIO,
@@ -1350,13 +1350,13 @@
         try:
             try:
                 self._fout.flush()
-            except IOError as err:
+            except OSError as err:
                 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF):
                     raise error.StdioError(err)
             finally:
                 try:
                     self._ferr.flush()
-                except IOError as err:
+                except OSError as err:
                     if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF):
                         raise error.StdioError(err)
         finally: