Skip to content

Commit cc1ba32

Browse files
committed
Fix comments
1 parent 9d7d3ca commit cc1ba32

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

Lib/test/test_traceback.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,11 +3426,16 @@ def __len__(self):
34263426
return 0
34273427

34283428

3429-
class FalseyExceptionGroup(ExceptionGroup):
3429+
class FalseyBoolExceptionGroup(ExceptionGroup):
34303430
def __bool__(self):
34313431
return False
34323432

34333433

3434+
class FalseyLenExceptionGroup(ExceptionGroup):
3435+
def __len__(self):
3436+
return 0
3437+
3438+
34343439
class TestTracebackException(unittest.TestCase):
34353440
def do_test_smoke(self, exc, expected_type_str):
34363441
try:
@@ -3792,7 +3797,7 @@ def test_dont_swallow_cause_or_context_of_falsey_exception(self):
37923797
try:
37933798
try:
37943799
1/0
3795-
except:
3800+
except ZeroDivisionError:
37963801
raise exc
37973802
except exc as e:
37983803
self.assertIn(context_message, traceback.format_exception(e))
@@ -3999,24 +4004,25 @@ def test_comparison(self):
39994004
self.assertEqual(exc, ALWAYS_EQ)
40004005

40014006
def test_dont_swallow_subexceptions_of_falsey_exceptiongroup(self):
4002-
# see gh-132308: Ensure that subexceptions of exception group
4007+
# see gh-132308: Ensure that subexceptions of exception groups
40034008
# that evaluate as falsey are displayed in the output.
40044009
# Recall: `x` is falsey if `len(x)` returns 0 or `bool(x)` returns False.
40054010

4006-
try:
4007-
raise FalseyExceptionGroup("Gih", (KeyError(), NameError()))
4008-
except Exception as ee:
4009-
str_exc = ''.join(traceback.format_exception(ee))
4010-
self.assertIn('+---------------- 1 ----------------', str_exc)
4011-
self.assertIn('+---------------- 2 ----------------', str_exc)
4012-
4013-
# Test with a falsey exception, in last position, as sub-exceptions.
4014-
msg = 'bool'
4015-
try:
4016-
raise FalseyExceptionGroup("Gah", (KeyError(), FalseyBoolException(msg)))
4017-
except Exception as ee:
4018-
str_exc = traceback.format_exception(ee)
4019-
self.assertIn(f'{FalseyBoolException.__name__}: {msg}', str_exc[-2])
4011+
for falsey_exception in (FalseyBoolExceptionGroup, FalseyLenExceptionGroup):
4012+
try:
4013+
raise falsey_exception("Gih", (KeyError(), NameError()))
4014+
except Exception as ee:
4015+
str_exc = ''.join(traceback.format_exception(ee))
4016+
self.assertIn('+---------------- 1 ----------------', str_exc)
4017+
self.assertIn('+---------------- 2 ----------------', str_exc)
4018+
4019+
# Test with a falsey exception, in last position, as sub-exceptions.
4020+
msg = 'bool'
4021+
try:
4022+
raise falsey_exception("Gah", (KeyError(), FalseyBoolException(msg)))
4023+
except Exception as ee:
4024+
str_exc = traceback.format_exception(ee)
4025+
self.assertIn(f'{FalseyBoolException.__name__}: {msg}', str_exc[-2])
40204026

40214027

40224028
global_for_suggestions = None
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
The :class:`traceback.TracebackException` must include the ``__context__``, ``__cause__`` attributes
22
from falsey Exception, and the ``exceptions`` attribute from falsey ``ExceptionGroup`` in its render.
3-
For remind: ``x`` is falsey if ``len(x)`` returns 0 or ``bool(x)`` returns False.

0 commit comments

Comments
 (0)