Mercurial > public > mercurial-scm > hg
comparison tests/tinyproxy.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 | 127d33e63d1a |
children | f8f14e6d032b |
comparison
equal
deleted
inserted
replaced
52639:9db77d46de79 | 52640:24ee91ba9aa8 |
---|---|
71 else: | 71 else: |
72 host_port = netloc, 80 | 72 host_port = netloc, 80 |
73 print("\t" "connect to %s:%d" % host_port) | 73 print("\t" "connect to %s:%d" % host_port) |
74 try: | 74 try: |
75 soc.connect(host_port) | 75 soc.connect(host_port) |
76 except socket.error as e: | 76 except OSError as e: |
77 self.send_error(404, e.strerror) | 77 self.send_error(404, e.strerror) |
78 return 0 | 78 return 0 |
79 return 1 | 79 return 1 |
80 | 80 |
81 def do_CONNECT(self): | 81 def do_CONNECT(self): |
147 out = self.connection | 147 out = self.connection |
148 else: | 148 else: |
149 out = soc | 149 out = soc |
150 try: | 150 try: |
151 data = i.recv(8192) | 151 data = i.recv(8192) |
152 except socket.error: | 152 except OSError: |
153 break | 153 break |
154 if data: | 154 if data: |
155 out.send(data) | 155 out.send(data) |
156 count = 0 | 156 count = 0 |
157 else: | 157 else: |