Skip to content
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

gh-102799: remove unnecessary calls to sys.exc_info() in tests #102800

Merged
merged 1 commit into from
Mar 18, 2023
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
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