@@ -763,7 +763,7 @@ def format_exception_as_a_whole(
763763 self ,
764764 etype : type ,
765765 evalue : BaseException ,
766- etb : TracebackType ,
766+ etb : Optional [ TracebackType ] ,
767767 number_of_lines_of_context ,
768768 tb_offset : Optional [int ],
769769 ):
@@ -772,7 +772,6 @@ def format_exception_as_a_whole(
772772 This may be called multiple times by Python 3 exception chaining
773773 (PEP 3134).
774774 """
775- assert etb is not None
776775 # some locals
777776 orig_etype = etype
778777 try :
@@ -783,7 +782,9 @@ def format_exception_as_a_whole(
783782 tb_offset = self .tb_offset if tb_offset is None else tb_offset
784783 assert isinstance (tb_offset , int )
785784 head = self .prepare_header (etype , self .long_header )
786- records = self .get_records (etb , number_of_lines_of_context , tb_offset )
785+ records = (
786+ self .get_records (etb , number_of_lines_of_context , tb_offset ) if etb else []
787+ )
787788
788789 frames = []
789790 skipped = 0
@@ -822,6 +823,7 @@ def format_exception_as_a_whole(
822823 def get_records (
823824 self , etb : TracebackType , number_of_lines_of_context : int , tb_offset : int
824825 ):
826+ assert etb is not None
825827 context = number_of_lines_of_context - 1
826828 after = context // 2
827829 before = context - after
@@ -836,19 +838,17 @@ def get_records(
836838 after = after ,
837839 pygments_formatter = formatter ,
838840 )
839- assert etb is not None
840841 return list (stack_data .FrameInfo .stack_data (etb , options = options ))[tb_offset :]
841842
842843 def structured_traceback (
843844 self ,
844845 etype : type ,
845846 evalue : Optional [BaseException ],
846- etb : TracebackType ,
847+ etb : Optional [ TracebackType ] ,
847848 tb_offset : Optional [int ] = None ,
848849 number_of_lines_of_context : int = 5 ,
849850 ):
850851 """Return a nice text document describing the traceback."""
851- assert etb is not None
852852 formatted_exception = self .format_exception_as_a_whole (etype , evalue , etb , number_of_lines_of_context ,
853853 tb_offset )
854854
0 commit comments