@@ -411,13 +411,13 @@ def filter(
411411 """
412412 return Traceback (filter (fn , self ), self ._excinfo )
413413
414- def getcrashentry (self ) -> Optional [ TracebackEntry ] :
414+ def getcrashentry (self ) -> TracebackEntry :
415415 """Return last non-hidden traceback entry that lead to the exception of a traceback."""
416416 for i in range (- 1 , - len (self ) - 1 , - 1 ):
417417 entry = self [i ]
418418 if not entry .ishidden ():
419419 return entry
420- return None
420+ return self [ - 1 ]
421421
422422 def recursionindex (self ) -> Optional [int ]:
423423 """Return the index of the frame/TracebackEntry where recursion originates if
@@ -602,13 +602,11 @@ def errisinstance(
602602 """
603603 return isinstance (self .value , exc )
604604
605- def _getreprcrash (self ) -> Optional [ "ReprFileLocation" ] :
605+ def _getreprcrash (self ) -> "ReprFileLocation" :
606606 exconly = self .exconly (tryshort = True )
607607 entry = self .traceback .getcrashentry ()
608- if entry :
609- path , lineno = entry .frame .code .raw .co_filename , entry .lineno
610- return ReprFileLocation (path , lineno + 1 , exconly )
611- return None
608+ path , lineno = entry .frame .code .raw .co_filename , entry .lineno
609+ return ReprFileLocation (path , lineno + 1 , exconly )
612610
613611 def getrepr (
614612 self ,
@@ -946,23 +944,18 @@ def repr_excinfo(
946944 )
947945 else :
948946 reprtraceback = self .repr_traceback (excinfo_ )
949-
950- # will be None if all traceback entries are hidden
951- reprcrash : Optional [ReprFileLocation ] = excinfo_ ._getreprcrash ()
952- if reprcrash :
953- if self .style == "value" :
954- repr_chain += [(reprtraceback , None , descr )]
955- else :
956- repr_chain += [(reprtraceback , reprcrash , descr )]
947+ reprcrash : Optional [ReprFileLocation ] = (
948+ excinfo_ ._getreprcrash () if self .style != "value" else None
949+ )
957950 else :
958951 # Fallback to native repr if the exception doesn't have a traceback:
959952 # ExceptionInfo objects require a full traceback to work.
960953 reprtraceback = ReprTracebackNative (
961954 traceback .format_exception (type (e ), e , None )
962955 )
963956 reprcrash = None
964- repr_chain += [(reprtraceback , reprcrash , descr )]
965957
958+ repr_chain += [(reprtraceback , reprcrash , descr )]
966959 if e .__cause__ is not None and self .chain :
967960 e = e .__cause__
968961 excinfo_ = (
@@ -1053,7 +1046,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
10531046@dataclasses .dataclass (eq = False )
10541047class ReprExceptionInfo (ExceptionRepr ):
10551048 reprtraceback : "ReprTraceback"
1056- reprcrash : Optional [ "ReprFileLocation" ]
1049+ reprcrash : "ReprFileLocation"
10571050
10581051 def toterminal (self , tw : TerminalWriter ) -> None :
10591052 self .reprtraceback .toterminal (tw )
0 commit comments