@@ -411,13 +411,13 @@ def filter(
411
411
"""
412
412
return Traceback (filter (fn , self ), self ._excinfo )
413
413
414
- def getcrashentry (self ) -> Optional [ TracebackEntry ] :
414
+ def getcrashentry (self ) -> TracebackEntry :
415
415
"""Return last non-hidden traceback entry that lead to the exception of a traceback."""
416
416
for i in range (- 1 , - len (self ) - 1 , - 1 ):
417
417
entry = self [i ]
418
418
if not entry .ishidden ():
419
419
return entry
420
- return None
420
+ return self [ - 1 ]
421
421
422
422
def recursionindex (self ) -> Optional [int ]:
423
423
"""Return the index of the frame/TracebackEntry where recursion originates if
@@ -602,13 +602,11 @@ def errisinstance(
602
602
"""
603
603
return isinstance (self .value , exc )
604
604
605
- def _getreprcrash (self ) -> Optional [ "ReprFileLocation" ] :
605
+ def _getreprcrash (self ) -> "ReprFileLocation" :
606
606
exconly = self .exconly (tryshort = True )
607
607
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 )
612
610
613
611
def getrepr (
614
612
self ,
@@ -946,23 +944,18 @@ def repr_excinfo(
946
944
)
947
945
else :
948
946
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
+ )
957
950
else :
958
951
# Fallback to native repr if the exception doesn't have a traceback:
959
952
# ExceptionInfo objects require a full traceback to work.
960
953
reprtraceback = ReprTracebackNative (
961
954
traceback .format_exception (type (e ), e , None )
962
955
)
963
956
reprcrash = None
964
- repr_chain += [(reprtraceback , reprcrash , descr )]
965
957
958
+ repr_chain += [(reprtraceback , reprcrash , descr )]
966
959
if e .__cause__ is not None and self .chain :
967
960
e = e .__cause__
968
961
excinfo_ = (
@@ -1053,7 +1046,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
1053
1046
@dataclasses .dataclass (eq = False )
1054
1047
class ReprExceptionInfo (ExceptionRepr ):
1055
1048
reprtraceback : "ReprTraceback"
1056
- reprcrash : Optional [ "ReprFileLocation" ]
1049
+ reprcrash : "ReprFileLocation"
1057
1050
1058
1051
def toterminal (self , tw : TerminalWriter ) -> None :
1059
1052
self .reprtraceback .toterminal (tw )
0 commit comments