comparison mercurial/dispatch.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 22129ce9f86d
children 73ab542565e0
comparison
equal deleted inserted replaced
52639:9db77d46de79 52640:24ee91ba9aa8
107 if hasattr(ui, 'fout'): 107 if hasattr(ui, 'fout'):
108 assert ui is not None # help pytype 108 assert ui is not None # help pytype
109 assert ui.fout is not None # help pytype 109 assert ui.fout is not None # help pytype
110 try: 110 try:
111 ui.fout.flush() 111 ui.fout.flush()
112 except IOError as e: 112 except OSError as e:
113 err = e 113 err = e
114 status = -1 114 status = -1
115 115
116 if hasattr(ui, 'ferr'): 116 if hasattr(ui, 'ferr'):
117 assert ui is not None # help pytype 117 assert ui is not None # help pytype
122 b'abort: %s\n' % encoding.strtolocal(err.strerror) 122 b'abort: %s\n' % encoding.strtolocal(err.strerror)
123 ) 123 )
124 ui.ferr.flush() 124 ui.ferr.flush()
125 # There's not much we can do about an I/O error here. So (possibly) 125 # There's not much we can do about an I/O error here. So (possibly)
126 # change the status code and move on. 126 # change the status code and move on.
127 except IOError: 127 except OSError:
128 status = -1 128 status = -1
129 129
130 return status 130 return status
131 131
132 132
206 continue 206 continue
207 # Check if the file is okay 207 # Check if the file is okay
208 try: 208 try:
209 fp.flush() 209 fp.flush()
210 continue 210 continue
211 except IOError: 211 except OSError:
212 pass 212 pass
213 # Otherwise mark it as closed to silence "Exception ignored in" 213 # Otherwise mark it as closed to silence "Exception ignored in"
214 # message emitted by the interpreter finalizer. 214 # message emitted by the interpreter finalizer.
215 try: 215 try:
216 fp.close() 216 fp.close()
217 except IOError: 217 except OSError:
218 pass 218 pass
219 219
220 220
221 def _formatargs(args): 221 def _formatargs(args):
222 return b' '.join(procutil.shellquote(a) for a in args) 222 return b' '.join(procutil.shellquote(a) for a in args)
498 ui.warn(b"(%s)\n" % error.similarity_hint(sim)) 498 ui.warn(b"(%s)\n" % error.similarity_hint(sim))
499 suggested = True 499 suggested = True
500 if not suggested: 500 if not suggested:
501 ui.warn(nocmdmsg) 501 ui.warn(nocmdmsg)
502 ui.warn(_(b"(use 'hg help' for a list of commands)\n")) 502 ui.warn(_(b"(use 'hg help' for a list of commands)\n"))
503 except IOError: 503 except OSError:
504 raise 504 raise
505 except KeyboardInterrupt: 505 except KeyboardInterrupt:
506 raise 506 raise
507 except: # probably re-raises 507 except: # probably re-raises
508 if not handlecommandexception(ui): 508 if not handlecommandexception(ui):