comparison mercurial/util.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 fca7d38e040b
children 5cc8deb96b48
comparison
equal deleted inserted replaced
52639:9db77d46de79 52640:24ee91ba9aa8
2021 oslink(src, dest) 2021 oslink(src, dest)
2022 if nb_bytes is not None: 2022 if nb_bytes is not None:
2023 m = "the `nb_bytes` argument is incompatible with `hardlink`" 2023 m = "the `nb_bytes` argument is incompatible with `hardlink`"
2024 raise error.ProgrammingError(m) 2024 raise error.ProgrammingError(m)
2025 return 2025 return
2026 except (IOError, OSError) as exc: 2026 except OSError as exc:
2027 if exc.errno != errno.EEXIST and no_hardlink_cb is not None: 2027 if exc.errno != errno.EEXIST and no_hardlink_cb is not None:
2028 no_hardlink_cb() 2028 no_hardlink_cb()
2029 # fall back to normal copy 2029 # fall back to normal copy
2030 if os.path.islink(src): 2030 if os.path.islink(src):
2031 os.symlink(os.readlink(src), dest) 2031 os.symlink(os.readlink(src), dest)
2087 settopic() 2087 settopic()
2088 2088
2089 if hardlink: 2089 if hardlink:
2090 try: 2090 try:
2091 oslink(src, dst) 2091 oslink(src, dst)
2092 except (IOError, OSError) as exc: 2092 except OSError as exc:
2093 if exc.errno != errno.EEXIST: 2093 if exc.errno != errno.EEXIST:
2094 hardlink = False 2094 hardlink = False
2095 # XXX maybe try to relink if the file exist ? 2095 # XXX maybe try to relink if the file exist ?
2096 shutil.copy(src, dst) 2096 shutil.copy(src, dst)
2097 else: 2097 else:
2488 if emptyok: 2488 if emptyok:
2489 return temp 2489 return temp
2490 try: 2490 try:
2491 try: 2491 try:
2492 ifp = posixfile(name, b"rb") 2492 ifp = posixfile(name, b"rb")
2493 except IOError as inst: 2493 except OSError as inst:
2494 if inst.errno == errno.ENOENT: 2494 if inst.errno == errno.ENOENT:
2495 return temp 2495 return temp
2496 if not getattr(inst, 'filename', None): 2496 if not getattr(inst, 'filename', None):
2497 inst.filename = name 2497 inst.filename = name
2498 raise 2498 raise