Skip to content

Commit 293dd23

Browse files
authored
Remove binding of captured exceptions when not used to reduce the chances of creating cycles (GH-17246)
Capturing exceptions into names can lead to reference cycles though the __traceback__ attribute of the exceptions in some obscure cases that have been reported previously and fixed individually. As these variables are not used anyway, we can remove the binding to reduce the chances of creating reference cycles. See for example GH-13135
1 parent c6b20be commit 293dd23

28 files changed

+39
-39
lines changed

Lib/asynchat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def handle_read(self):
117117
data = self.recv(self.ac_in_buffer_size)
118118
except BlockingIOError:
119119
return
120-
except OSError as why:
120+
except OSError:
121121
self.handle_error()
122122
return
123123

Lib/asyncio/proactor_events.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ async def _sock_sendfile_native(self, sock, file, offset, count):
711711
raise exceptions.SendfileNotAvailableError("not a regular file")
712712
try:
713713
fsize = os.fstat(fileno).st_size
714-
except OSError as err:
714+
except OSError:
715715
raise exceptions.SendfileNotAvailableError("not a regular file")
716716
blocksize = count if count else fsize
717717
if not blocksize:

Lib/asyncio/unix_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ async def create_unix_server(
330330
async def _sock_sendfile_native(self, sock, file, offset, count):
331331
try:
332332
os.sendfile
333-
except AttributeError as exc:
333+
except AttributeError:
334334
raise exceptions.SendfileNotAvailableError(
335335
"os.sendfile() is not available")
336336
try:
@@ -339,7 +339,7 @@ async def _sock_sendfile_native(self, sock, file, offset, count):
339339
raise exceptions.SendfileNotAvailableError("not a regular file")
340340
try:
341341
fsize = os.fstat(fileno).st_size
342-
except OSError as err:
342+
except OSError:
343343
raise exceptions.SendfileNotAvailableError("not a regular file")
344344
blocksize = count if count else fsize
345345
if not blocksize:

Lib/codeop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _maybe_compile(compiler, source, filename, symbol):
8080

8181
try:
8282
code = compiler(source, filename, symbol)
83-
except SyntaxError as err:
83+
except SyntaxError:
8484
pass
8585

8686
try:

Lib/ctypes/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def _findLib_ld(name):
302302
res = re.search(expr, os.fsdecode(out))
303303
if res:
304304
result = res.group(0)
305-
except Exception as e:
305+
except Exception:
306306
pass # result will be None
307307
return result
308308

Lib/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, s
420420
if module is None:
421421
try:
422422
module = sys._getframe(2).f_globals['__name__']
423-
except (AttributeError, ValueError, KeyError) as exc:
423+
except (AttributeError, ValueError, KeyError):
424424
pass
425425
if module is None:
426426
_make_class_unpicklable(enum_class)

Lib/filecmp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ def phase2(self): # Distinguish files, directories, funnies
156156
ok = 1
157157
try:
158158
a_stat = os.stat(a_path)
159-
except OSError as why:
159+
except OSError:
160160
# print('Can\'t stat', a_path, ':', why.args[1])
161161
ok = 0
162162
try:
163163
b_stat = os.stat(b_path)
164-
except OSError as why:
164+
except OSError:
165165
# print('Can\'t stat', b_path, ':', why.args[1])
166166
ok = 0
167167

Lib/getpass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def unix_getpass(prompt='Password: ', stream=None):
5252
stack.enter_context(input)
5353
if not stream:
5454
stream = input
55-
except OSError as e:
55+
except OSError:
5656
# If that fails, see if stdin can be controlled.
5757
stack.close()
5858
try:

Lib/importlib/abc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
_frozen_importlib = None
1111
try:
1212
import _frozen_importlib_external
13-
except ImportError as exc:
13+
except ImportError:
1414
_frozen_importlib_external = _bootstrap_external
1515
import abc
1616
import warnings

Lib/lib2to3/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def write_file(self, new_text, filename, old_text, encoding):
9090
if os.path.lexists(backup):
9191
try:
9292
os.remove(backup)
93-
except OSError as err:
93+
except OSError:
9494
self.log_message("Can't remove backup %s", backup)
9595
try:
9696
os.rename(filename, backup)
97-
except OSError as err:
97+
except OSError:
9898
self.log_message("Can't rename %s to %s", filename, backup)
9999
# Actually write the new file
100100
write = super(StdoutRefactoringTool, self).write_file

0 commit comments

Comments
 (0)