Mercurial > public > mercurial-scm > hg
comparison mercurial/extensions.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 | f106d0e629e5 |
children | 42f78c859dd1 |
comparison
equal
deleted
inserted
replaced
52639:9db77d46de79 | 52640:24ee91ba9aa8 |
---|---|
802 def _disabledhelp(path): | 802 def _disabledhelp(path): |
803 '''retrieve help synopsis of a disabled extension (without importing)''' | 803 '''retrieve help synopsis of a disabled extension (without importing)''' |
804 try: | 804 try: |
805 with open(path, 'rb') as src: | 805 with open(path, 'rb') as src: |
806 doc = _moduledoc(src) | 806 doc = _moduledoc(src) |
807 except IOError: | 807 except OSError: |
808 return | 808 return |
809 | 809 |
810 if doc: # extracting localized synopsis | 810 if doc: # extracting localized synopsis |
811 return gettext(doc) | 811 return gettext(doc) |
812 else: | 812 else: |
917 | 917 |
918 | 918 |
919 def _finddisabledcmd(ui, cmd, name, path, strict): | 919 def _finddisabledcmd(ui, cmd, name, path, strict): |
920 try: | 920 try: |
921 cmdtable = _disabledcmdtable(path) | 921 cmdtable = _disabledcmdtable(path) |
922 except (IOError, SyntaxError): | 922 except (OSError, SyntaxError): |
923 return | 923 return |
924 try: | 924 try: |
925 aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict) | 925 aliases, entry = cmdutil.findcmd(cmd, cmdtable, strict) |
926 except (error.AmbiguousCommand, error.UnknownCommand): | 926 except (error.AmbiguousCommand, error.UnknownCommand): |
927 return | 927 return |