comparison mercurial/posix.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 dd052842fc8e
children
comparison
equal deleted inserted replaced
52639:9db77d46de79 52640:24ee91ba9aa8
258 os.mkdir(cachedir) 258 os.mkdir(cachedir)
259 if os.path.exists(storedir): 259 if os.path.exists(storedir):
260 copymode(storedir, cachedir) 260 copymode(storedir, cachedir)
261 else: 261 else:
262 copymode(basedir, cachedir) 262 copymode(basedir, cachedir)
263 except (IOError, OSError): 263 except OSError:
264 # we other fallback logic triggers 264 # we other fallback logic triggers
265 pass 265 pass
266 if os.path.isdir(cachedir): 266 if os.path.isdir(cachedir):
267 checkisexec = os.path.join(cachedir, b'checkisexec') 267 checkisexec = os.path.join(cachedir, b'checkisexec')
268 checknoexec = os.path.join(cachedir, b'checknoexec') 268 checknoexec = os.path.join(cachedir, b'checknoexec')
308 fn = None 308 fn = None
309 return True 309 return True
310 finally: 310 finally:
311 if fn is not None: 311 if fn is not None:
312 unlink(fn) 312 unlink(fn)
313 except (IOError, OSError): 313 except OSError:
314 # we don't care, the user probably won't be able to commit anyway 314 # we don't care, the user probably won't be able to commit anyway
315 return False 315 return False
316 316
317 317
318 def checklink(path: bytes) -> bool: 318 def checklink(path: bytes) -> bool:
781 try: 781 try:
782 s = pipe.read() 782 s = pipe.read()
783 if not s: 783 if not s:
784 break 784 break
785 chunks.append(s) 785 chunks.append(s)
786 except IOError: 786 except OSError:
787 break 787 break
788 788
789 return b''.join(chunks) 789 return b''.join(chunks)
790 finally: 790 finally:
791 fcntl.fcntl(pipe, fcntl.F_SETFL, oldflags) 791 fcntl.fcntl(pipe, fcntl.F_SETFL, oldflags)