Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/loggingutil.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 | f4733654f144 |
children |
comparison
equal
deleted
inserted
replaced
52664:9db77d46de79 | 52665:24ee91ba9aa8 |
---|---|
95 self._name, | 95 self._name, |
96 maxfiles=self._maxfiles, | 96 maxfiles=self._maxfiles, |
97 maxsize=self._maxsize, | 97 maxsize=self._maxsize, |
98 ) as fp: | 98 ) as fp: |
99 fp.write(line) | 99 fp.write(line) |
100 except IOError as err: | 100 except OSError as err: |
101 ui.debug( | 101 ui.debug( |
102 b'cannot write to %s: %s\n' | 102 b'cannot write to %s: %s\n' |
103 % (self._name, stringutil.forcebytestr(err)) | 103 % (self._name, stringutil.forcebytestr(err)) |
104 ) | 104 ) |
105 | 105 |
117 def log(self, ui, event, msg, opts): | 117 def log(self, ui, event, msg, opts): |
118 line = _formatlogline(msg) | 118 line = _formatlogline(msg) |
119 try: | 119 try: |
120 self._fp.write(line) | 120 self._fp.write(line) |
121 self._fp.flush() | 121 self._fp.flush() |
122 except IOError as err: | 122 except OSError as err: |
123 ui.debug( | 123 ui.debug( |
124 b'cannot write to %s: %s\n' | 124 b'cannot write to %s: %s\n' |
125 % ( | 125 % ( |
126 stringutil.forcebytestr(self._fp.name), | 126 stringutil.forcebytestr(self._fp.name), |
127 stringutil.forcebytestr(err), | 127 stringutil.forcebytestr(err), |