comparison mercurial/ui.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 cc918741a22a
children e627cc25b6f3
comparison
equal deleted inserted replaced
52639:9db77d46de79 52640:24ee91ba9aa8
462 def read_resource_config( 462 def read_resource_config(
463 self, name, root=None, trust=False, sections=None, remap=None 463 self, name, root=None, trust=False, sections=None, remap=None
464 ) -> None: 464 ) -> None:
465 try: 465 try:
466 fp = resourceutil.open_resource(name[0], name[1]) 466 fp = resourceutil.open_resource(name[0], name[1])
467 except IOError: 467 except OSError:
468 if not sections: # ignore unless we were looking for something 468 if not sections: # ignore unless we were looking for something
469 return 469 return
470 raise 470 raise
471 471
472 self._readconfig( 472 self._readconfig(
476 def readconfig( 476 def readconfig(
477 self, filename, root=None, trust=False, sections=None, remap=None 477 self, filename, root=None, trust=False, sections=None, remap=None
478 ) -> None: 478 ) -> None:
479 try: 479 try:
480 fp = open(filename, 'rb') 480 fp = open(filename, 'rb')
481 except IOError: 481 except OSError:
482 if not sections: # ignore unless we were looking for something 482 if not sections: # ignore unless we were looking for something
483 return 483 return
484 raise 484 raise
485 485
486 self._readconfig(filename, fp, root, trust, sections, remap) 486 self._readconfig(filename, fp, root, trust, sections, remap)
1259 else: 1259 else:
1260 if self._colormode is not None: 1260 if self._colormode is not None:
1261 label = opts.get('label', b'') 1261 label = opts.get('label', b'')
1262 msg = self.label(msg, label) 1262 msg = self.label(msg, label)
1263 dest.write(msg) 1263 dest.write(msg)
1264 except IOError as err: 1264 except OSError as err:
1265 raise error.StdioError(err) 1265 raise error.StdioError(err)
1266 finally: 1266 finally:
1267 self._blockedtimes[b'stdio_blocked'] += ( 1267 self._blockedtimes[b'stdio_blocked'] += (
1268 util.timer() - starttime 1268 util.timer() - starttime
1269 ) * 1000 1269 ) * 1000
1308 dest.write(msg) 1308 dest.write(msg)
1309 # stderr may be buffered under win32 when redirected to files, 1309 # stderr may be buffered under win32 when redirected to files,
1310 # including stdout. 1310 # including stdout.
1311 if dest is self._ferr and not getattr(dest, 'closed', False): 1311 if dest is self._ferr and not getattr(dest, 'closed', False):
1312 dest.flush() 1312 dest.flush()
1313 except IOError as err: 1313 except OSError as err:
1314 if dest is self._ferr and err.errno in ( 1314 if dest is self._ferr and err.errno in (
1315 errno.EPIPE, 1315 errno.EPIPE,
1316 errno.EIO, 1316 errno.EIO,
1317 errno.EBADF, 1317 errno.EBADF,
1318 ): 1318 ):
1348 # opencode timeblockedsection because this is a critical path 1348 # opencode timeblockedsection because this is a critical path
1349 starttime = util.timer() 1349 starttime = util.timer()
1350 try: 1350 try:
1351 try: 1351 try:
1352 self._fout.flush() 1352 self._fout.flush()
1353 except IOError as err: 1353 except OSError as err:
1354 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): 1354 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF):
1355 raise error.StdioError(err) 1355 raise error.StdioError(err)
1356 finally: 1356 finally:
1357 try: 1357 try:
1358 self._ferr.flush() 1358 self._ferr.flush()
1359 except IOError as err: 1359 except OSError as err:
1360 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF): 1360 if err.errno not in (errno.EPIPE, errno.EIO, errno.EBADF):
1361 raise error.StdioError(err) 1361 raise error.StdioError(err)
1362 finally: 1362 finally:
1363 self._blockedtimes[b'stdio_blocked'] += ( 1363 self._blockedtimes[b'stdio_blocked'] += (
1364 util.timer() - starttime 1364 util.timer() - starttime