Skip to content

Commit

Permalink
pythongh-102799: remove unnecessary calls to sys.exc_info() in tests (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
iritkatriel authored and warsaw committed Apr 11, 2023
1 parent 999cc8d commit f624ea4
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 124 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,8 @@ async def test_fork_not_share_event_loop(self):
os.write(w, b'LOOP:' + str(id(loop)).encode())
except RuntimeError:
os.write(w, b'NO LOOP')
except:
os.write(w, b'ERROR:' + ascii(sys.exc_info()).encode())
except BaseException as e:
os.write(w, b'ERROR:' + ascii(e).encode())
finally:
os._exit(0)
else:
Expand Down
18 changes: 9 additions & 9 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ def test_notes(self):
def testWithTraceback(self):
try:
raise IndexError(4)
except:
tb = sys.exc_info()[2]
except Exception as e:
tb = e.__traceback__

e = BaseException().with_traceback(tb)
self.assertIsInstance(e, BaseException)
Expand Down Expand Up @@ -653,8 +653,8 @@ def test_invalid_delattr(self):
def testNoneClearsTracebackAttr(self):
try:
raise IndexError(4)
except:
tb = sys.exc_info()[2]
except Exception as e:
tb = e.__traceback__

e = Exception()
e.__traceback__ = tb
Expand Down Expand Up @@ -1337,11 +1337,11 @@ class MyException(Exception, metaclass=Meta):
def g():
try:
return g()
except RecursionError:
return sys.exc_info()
e, v, tb = g()
self.assertIsInstance(v, RecursionError, type(v))
self.assertIn("maximum recursion depth exceeded", str(v))
except RecursionError as e:
return e
exc = g()
self.assertIsInstance(exc, RecursionError, type(exc))
self.assertIn("maximum recursion depth exceeded", str(exc))


@cpython_only
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5492,10 +5492,10 @@ def alarm_handler(signal, frame):
self.fail("caught timeout instead of Alarm")
except Alarm:
pass
except:
except BaseException as e:
self.fail("caught other exception instead of Alarm:"
" %s(%s):\n%s" %
(sys.exc_info()[:2] + (traceback.format_exc(),)))
(type(e), e, traceback.format_exc()))
else:
self.fail("nothing caught")
finally:
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,8 +1649,8 @@ def test_pythontypes(self):
check(_ast.AST(), size('P'))
try:
raise TypeError
except TypeError:
tb = sys.exc_info()[2]
except TypeError as e:
tb = e.__traceback__
# traceback
if tb is not None:
check(tb, size('2P2i'))
Expand Down
Loading

0 comments on commit f624ea4

Please sign in to comment.