comparison mercurial/win32.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 f4733654f144
children
comparison
equal deleted inserted replaced
52639:9db77d46de79 52640:24ee91ba9aa8
716 '''try to implement POSIX' unlink semantics on Windows''' 716 '''try to implement POSIX' unlink semantics on Windows'''
717 717
718 if os.path.isdir(path): 718 if os.path.isdir(path):
719 # use EPERM because it is POSIX prescribed value, even though 719 # use EPERM because it is POSIX prescribed value, even though
720 # unlink(2) on directories returns EISDIR on Linux 720 # unlink(2) on directories returns EISDIR on Linux
721 raise IOError( 721 raise OSError(
722 errno.EPERM, 722 errno.EPERM,
723 r"Unlinking directory not permitted: '%s'" 723 r"Unlinking directory not permitted: '%s'"
724 % encoding.strfromlocal(path), 724 % encoding.strfromlocal(path),
725 ) 725 )
726 726
747 os.rename(path, temp) 747 os.rename(path, temp)
748 break 748 break
749 except FileExistsError: 749 except FileExistsError:
750 pass 750 pass
751 else: 751 else:
752 raise IOError(errno.EEXIST, "No usable temporary filename found") 752 raise OSError(errno.EEXIST, "No usable temporary filename found")
753 753
754 try: 754 try:
755 os.unlink(temp) 755 os.unlink(temp)
756 except OSError: 756 except OSError:
757 # The unlink might have failed because the READONLY attribute may heave 757 # The unlink might have failed because the READONLY attribute may heave