Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.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 | 89215c5b714c |
children | e627cc25b6f3 |
comparison
equal
deleted
inserted
replaced
52639:9db77d46de79 | 52640:24ee91ba9aa8 |
---|---|
1161 try: | 1161 try: |
1162 if isstdiofilename(logfile): | 1162 if isstdiofilename(logfile): |
1163 message = ui.fin.read() | 1163 message = ui.fin.read() |
1164 else: | 1164 else: |
1165 message = b'\n'.join(util.readfile(logfile).splitlines()) | 1165 message = b'\n'.join(util.readfile(logfile).splitlines()) |
1166 except IOError as inst: | 1166 except OSError as inst: |
1167 raise error.Abort( | 1167 raise error.Abort( |
1168 _(b"can't read commit message '%s': %s") | 1168 _(b"can't read commit message '%s': %s") |
1169 % (logfile, encoding.strtolocal(inst.strerror)) | 1169 % (logfile, encoding.strtolocal(inst.strerror)) |
1170 ) | 1170 ) |
1171 return message | 1171 return message |
1794 else: | 1794 else: |
1795 # Preserve stat info on renames, not on copies; this matches | 1795 # Preserve stat info on renames, not on copies; this matches |
1796 # Linux CLI behavior. | 1796 # Linux CLI behavior. |
1797 util.copyfile(src, target, copystat=rename) | 1797 util.copyfile(src, target, copystat=rename) |
1798 srcexists = True | 1798 srcexists = True |
1799 except IOError as inst: | 1799 except OSError as inst: |
1800 if inst.errno == errno.ENOENT: | 1800 if inst.errno == errno.ENOENT: |
1801 ui.warn(_(b'%s: deleted in working directory\n') % relsrc) | 1801 ui.warn(_(b'%s: deleted in working directory\n') % relsrc) |
1802 srcexists = False | 1802 srcexists = False |
1803 else: | 1803 else: |
1804 ui.warn( | 1804 ui.warn( |