Mercurial > public > mercurial-scm > hg
comparison mercurial/keepalive.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 | 1a640aa20e48 |
children | 5cc8deb96b48 |
comparison
equal
deleted
inserted
replaced
52639:9db77d46de79 | 52640:24ee91ba9aa8 |
---|---|
84 | 84 |
85 from __future__ import annotations | 85 from __future__ import annotations |
86 | 86 |
87 import collections | 87 import collections |
88 import hashlib | 88 import hashlib |
89 import socket | |
90 import sys | 89 import sys |
91 import threading | 90 import threading |
92 | 91 |
93 from .i18n import _ | 92 from .i18n import _ |
94 from .node import hex | 93 from .node import hex |
247 # to make the error message slightly more useful. | 246 # to make the error message slightly more useful. |
248 except httplib.BadStatusLine as err: | 247 except httplib.BadStatusLine as err: |
249 raise urlerr.urlerror( | 248 raise urlerr.urlerror( |
250 _(b'bad HTTP status line: %s') % pycompat.sysbytes(err.line) | 249 _(b'bad HTTP status line: %s') % pycompat.sysbytes(err.line) |
251 ) | 250 ) |
252 except (socket.error, httplib.HTTPException) as err: | 251 except (OSError, httplib.HTTPException) as err: |
253 raise urlerr.urlerror(err) | 252 raise urlerr.urlerror(err) |
254 | 253 |
255 # If not a persistent connection, don't try to reuse it. Look | 254 # If not a persistent connection, don't try to reuse it. Look |
256 # for this using getattr() since vcr doesn't define this | 255 # for this using getattr() since vcr doesn't define this |
257 # attribute, and in that case always close the connection. | 256 # attribute, and in that case always close the connection. |
280 try: | 279 try: |
281 self._start_transaction(h, req) | 280 self._start_transaction(h, req) |
282 r = h.getresponse() | 281 r = h.getresponse() |
283 # note: just because we got something back doesn't mean it | 282 # note: just because we got something back doesn't mean it |
284 # worked. We'll check the version below, too. | 283 # worked. We'll check the version below, too. |
285 except (socket.error, httplib.HTTPException): | 284 except (OSError, httplib.HTTPException): |
286 r = None | 285 r = None |
287 except: # re-raises | 286 except: # re-raises |
288 # adding this block just in case we've missed | 287 # adding this block just in case we've missed |
289 # something we will still raise the exception, but | 288 # something we will still raise the exception, but |
290 # lets try and close the connection and remove it | 289 # lets try and close the connection and remove it |
352 h.putrequest( | 351 h.putrequest( |
353 req.get_method(), | 352 req.get_method(), |
354 urllibcompat.getselector(req), | 353 urllibcompat.getselector(req), |
355 **skipheaders, | 354 **skipheaders, |
356 ) | 355 ) |
357 except socket.error as err: | 356 except OSError as err: |
358 raise urlerr.urlerror(err) | 357 raise urlerr.urlerror(err) |
359 for k, v in headers.items(): | 358 for k, v in headers.items(): |
360 h.putheader(k, v) | 359 h.putheader(k, v) |
361 h.endheaders() | 360 h.endheaders() |
362 if urllibcompat.hasdata(req): | 361 if urllibcompat.hasdata(req): |