Skip to content

Remove binding of captured exceptions when not used to reduce the chances of creating cycles #17246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/asynchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def handle_read(self):
data = self.recv(self.ac_in_buffer_size)
except BlockingIOError:
return
except OSError as why:
except OSError:
self.handle_error()
return

Expand Down
2 changes: 1 addition & 1 deletion Lib/asyncio/proactor_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ async def _sock_sendfile_native(self, sock, file, offset, count):
raise exceptions.SendfileNotAvailableError("not a regular file")
try:
fsize = os.fstat(fileno).st_size
except OSError as err:
except OSError:
raise exceptions.SendfileNotAvailableError("not a regular file")
blocksize = count if count else fsize
if not blocksize:
Expand Down
4 changes: 2 additions & 2 deletions Lib/asyncio/unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def create_unix_server(
async def _sock_sendfile_native(self, sock, file, offset, count):
try:
os.sendfile
except AttributeError as exc:
except AttributeError:
raise exceptions.SendfileNotAvailableError(
"os.sendfile() is not available")
try:
Expand All @@ -339,7 +339,7 @@ async def _sock_sendfile_native(self, sock, file, offset, count):
raise exceptions.SendfileNotAvailableError("not a regular file")
try:
fsize = os.fstat(fileno).st_size
except OSError as err:
except OSError:
raise exceptions.SendfileNotAvailableError("not a regular file")
blocksize = count if count else fsize
if not blocksize:
Expand Down
2 changes: 1 addition & 1 deletion Lib/codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _maybe_compile(compiler, source, filename, symbol):

try:
code = compiler(source, filename, symbol)
except SyntaxError as err:
except SyntaxError:
pass

try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/ctypes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _findLib_ld(name):
res = re.search(expr, os.fsdecode(out))
if res:
result = res.group(0)
except Exception as e:
except Exception:
pass # result will be None
return result

Expand Down
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, s
if module is None:
try:
module = sys._getframe(2).f_globals['__name__']
except (AttributeError, ValueError, KeyError) as exc:
except (AttributeError, ValueError, KeyError):
pass
if module is None:
_make_class_unpicklable(enum_class)
Expand Down
4 changes: 2 additions & 2 deletions Lib/filecmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ def phase2(self): # Distinguish files, directories, funnies
ok = 1
try:
a_stat = os.stat(a_path)
except OSError as why:
except OSError:
# print('Can\'t stat', a_path, ':', why.args[1])
ok = 0
try:
b_stat = os.stat(b_path)
except OSError as why:
except OSError:
# print('Can\'t stat', b_path, ':', why.args[1])
ok = 0

Expand Down
2 changes: 1 addition & 1 deletion Lib/getpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def unix_getpass(prompt='Password: ', stream=None):
stack.enter_context(input)
if not stream:
stream = input
except OSError as e:
except OSError:
# If that fails, see if stdin can be controlled.
stack.close()
try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/importlib/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
_frozen_importlib = None
try:
import _frozen_importlib_external
except ImportError as exc:
except ImportError:
_frozen_importlib_external = _bootstrap_external
import abc
import warnings
Expand Down
4 changes: 2 additions & 2 deletions Lib/lib2to3/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def write_file(self, new_text, filename, old_text, encoding):
if os.path.lexists(backup):
try:
os.remove(backup)
except OSError as err:
except OSError:
self.log_message("Can't remove backup %s", backup)
try:
os.rename(filename, backup)
except OSError as err:
except OSError:
self.log_message("Can't rename %s to %s", filename, backup)
# Actually write the new file
write = super(StdoutRefactoringTool, self).write_file
Expand Down
2 changes: 1 addition & 1 deletion Lib/msilib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def add_data(db, table, values):
raise TypeError("Unsupported type %s" % field.__class__.__name__)
try:
v.Modify(MSIMODIFY_INSERT, r)
except Exception as e:
except Exception:
raise MSIError("Could not insert "+repr(values)+" into "+table)

r.ClearData()
Expand Down
4 changes: 2 additions & 2 deletions Lib/multiprocessing/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def serve_client(self, conn):
try:
obj, exposed, gettypeid = \
self.id_to_local_proxy_obj[ident]
except KeyError as second_ke:
except KeyError:
raise ke

if methodname not in exposed:
Expand Down Expand Up @@ -296,7 +296,7 @@ def serve_client(self, conn):
try:
try:
send(msg)
except Exception as e:
except Exception:
send(('#UNSERIALIZABLE', format_exc()))
except Exception as e:
util.info('exception in thread serving %r',
Expand Down
2 changes: 1 addition & 1 deletion Lib/multiprocessing/popen_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def poll(self, flag=os.WNOHANG):
if self.returncode is None:
try:
pid, sts = os.waitpid(self.pid, flag)
except OSError as e:
except OSError:
# Child process not yet created. See #1731717
# e.errno == errno.ECHILD == 10
return None
Expand Down
2 changes: 1 addition & 1 deletion Lib/poplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def _parsecap(line):
for capline in rawcaps:
capnm, capargs = _parsecap(capline)
caps[capnm] = capargs
except error_proto as _err:
except error_proto:
raise error_proto('-ERR CAPA not supported by server')
return caps

Expand Down
2 changes: 1 addition & 1 deletion Lib/test/pythoninfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def collect_info(info):
):
try:
collect_func(info_add)
except Exception as exc:
except Exception:
error = True
print("ERROR: %s() failed" % (collect_func.__name__),
file=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_cgitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_html(self):
def test_text(self):
try:
raise ValueError("Hello World")
except ValueError as err:
except ValueError:
text = cgitb.text(sys.exc_info())
self.assertIn("ValueError", text)
self.assertIn("Hello World", text)
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class I:
# In debug mode, printed XXX undetected error and
# raises AttributeError
I()
except AttributeError as x:
except AttributeError:
pass
else:
self.fail("attribute error for I.__init__ got masked")
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

try:
import _testcapi
except ImportError as exc:
except ImportError:
_testcapi = None

try:
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_decimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5600,13 +5600,13 @@ def doit(ty):
args, kwds = mkargs(C, c_sig)
try:
getattr(c_type(9), attr)(*args, **kwds)
except Exception as err:
except Exception:
raise TestFailed("invalid signature for %s: %s %s" % (c_func, args, kwds))

args, kwds = mkargs(P, p_sig)
try:
getattr(p_type(9), attr)(*args, **kwds)
except Exception as err:
except Exception:
raise TestFailed("invalid signature for %s: %s %s" % (p_func, args, kwds))

doit('Decimal')
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def _do_ssl_shutdown(self):
if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE):
return
except OSError as err:
except OSError:
# Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
# from OpenSSL's SSL_shutdown(), corresponding to a
# closed socket condition. See also:
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_sys_settrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ def raises():
def test_raise():
try:
raises()
except Exception as exc:
x = 1
except Exception:
pass

test_raise.events = [(0, 'call'),
(1, 'line'),
Expand Down Expand Up @@ -191,7 +191,7 @@ def _settrace_and_raise(tracefunc):
def settrace_and_raise(tracefunc):
try:
_settrace_and_raise(tracefunc)
except RuntimeError as exc:
except RuntimeError:
pass

settrace_and_raise.events = [(2, 'exception'),
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def convert_values(ns_timestamps):
try:
result = pytime_converter(value, time_rnd)
expected = expected_func(value)
except Exception as exc:
except Exception:
self.fail("Error on timestamp conversion: %s" % debug_info)
self.assertEqual(result,
expected,
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def f():
with captured_output("stderr") as stderr_f:
try:
f()
except RecursionError as exc:
except RecursionError:
render_exc()
else:
self.fail("no recursion occurred")
Expand Down Expand Up @@ -360,7 +360,7 @@ def g(count=10):
with captured_output("stderr") as stderr_g:
try:
g()
except ValueError as exc:
except ValueError:
render_exc()
else:
self.fail("no value error was raised")
Expand Down Expand Up @@ -396,7 +396,7 @@ def h(count=10):
with captured_output("stderr") as stderr_h:
try:
h()
except ValueError as exc:
except ValueError:
render_exc()
else:
self.fail("no value error was raised")
Expand Down Expand Up @@ -424,7 +424,7 @@ def h(count=10):
with captured_output("stderr") as stderr_g:
try:
g(traceback._RECURSIVE_CUTOFF)
except ValueError as exc:
except ValueError:
render_exc()
else:
self.fail("no error raised")
Expand Down Expand Up @@ -452,7 +452,7 @@ def h(count=10):
with captured_output("stderr") as stderr_g:
try:
g(traceback._RECURSIVE_CUTOFF + 1)
except ValueError as exc:
except ValueError:
render_exc()
else:
self.fail("no error raised")
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_urllib2net.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_sites_no_connection_close(self):
try:
with urllib.request.urlopen(URL) as res:
pass
except ValueError as e:
except ValueError:
self.fail("urlopen failed for site not sending \
Connection:close")
else:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def test_uuid1_eui64(self):
# the value from too_large_getter above.
try:
self.uuid.uuid1(node=node)
except ValueError as e:
except ValueError:
self.fail('uuid1 was given an invalid node ID')

def test_uuid1(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def doClassCleanups(cls):
function, args, kwargs = cls._class_cleanups.pop()
try:
function(*args, **kwargs)
except Exception as exc:
except Exception:
cls.tearDown_exceptions.append(sys.exc_info())

def __call__(self, *args, **kwds):
Expand Down
2 changes: 1 addition & 1 deletion Lib/urllib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ def retrieve(self, url, filename=None, reporthook=None, data=None):
hdrs = fp.info()
fp.close()
return url2pathname(_splithost(url1)[1]), hdrs
except OSError as msg:
except OSError:
pass
fp = self.open(url, data)
try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/xml/sax/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def make_parser(parser_list=()):
for parser_name in list(parser_list) + default_parser_list:
try:
return _create_parser(parser_name)
except ImportError as e:
except ImportError:
import sys
if parser_name in sys.modules:
# The parser module was found, but importing it
Expand Down