Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hook.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 |
---|---|
311 # The stderr is fully buffered on Windows when connected to a pipe. | 311 # The stderr is fully buffered on Windows when connected to a pipe. |
312 # A forcible flush is required to make small stderr data in the | 312 # A forcible flush is required to make small stderr data in the |
313 # remote side available to the client immediately. | 313 # remote side available to the client immediately. |
314 try: | 314 try: |
315 procutil.stderr.flush() | 315 procutil.stderr.flush() |
316 except IOError as err: | 316 except OSError as err: |
317 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): | 317 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): |
318 raise error.StdioError(err) | 318 raise error.StdioError(err) |
319 | 319 |
320 if _redirect and oldstdout >= 0: | 320 if _redirect and oldstdout >= 0: |
321 try: | 321 try: |
322 procutil.stdout.flush() # write hook output to stderr fd | 322 procutil.stdout.flush() # write hook output to stderr fd |
323 except IOError as err: | 323 except OSError as err: |
324 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): | 324 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): |
325 raise error.StdioError(err) | 325 raise error.StdioError(err) |
326 os.dup2(oldstdout, stdoutno) | 326 os.dup2(oldstdout, stdoutno) |
327 os.close(oldstdout) | 327 os.close(oldstdout) |
328 | 328 |