@@ -789,9 +789,9 @@ def repr_traceback_entry(
789
789
else :
790
790
message = excinfo and excinfo .typename or ""
791
791
path = self ._makepath (entry .path )
792
- filelocrepr = ReprFileLocation (path , entry .lineno + 1 , message )
792
+ reprfileloc = ReprFileLocation (path , entry .lineno + 1 , message )
793
793
localsrepr = self .repr_locals (entry .locals )
794
- return ReprEntry (lines , reprargs , localsrepr , filelocrepr , style )
794
+ return ReprEntry (lines , reprargs , localsrepr , reprfileloc , style )
795
795
if excinfo :
796
796
lines .extend (self .get_exconly (excinfo , indent = 4 ))
797
797
return ReprEntry (lines , None , None , None , style )
@@ -911,6 +911,7 @@ def repr_excinfo(self, excinfo: ExceptionInfo) -> "ExceptionChainRepr":
911
911
return ExceptionChainRepr (repr_chain )
912
912
913
913
914
+ @attr .s
914
915
class TerminalRepr :
915
916
def __str__ (self ) -> str :
916
917
# FYI this is called from pytest-xdist's serialization of exception
@@ -927,8 +928,9 @@ def toterminal(self, tw: TerminalWriter) -> None:
927
928
raise NotImplementedError ()
928
929
929
930
931
+ @attr .s
930
932
class ExceptionRepr (TerminalRepr ):
931
- def __init__ (self ) -> None :
933
+ def __attrs_post_init__ (self ):
932
934
self .sections = [] # type: List[Tuple[str, str, str]]
933
935
934
936
def addsection (self , name : str , content : str , sep : str = "-" ) -> None :
@@ -940,19 +942,20 @@ def toterminal(self, tw: TerminalWriter) -> None:
940
942
tw .line (content )
941
943
942
944
945
+ @attr .s
943
946
class ExceptionChainRepr (ExceptionRepr ):
944
- def __init__ (
945
- self ,
946
- chain : Sequence [
947
+ chain = attr .ib (
948
+ type = Sequence [
947
949
Tuple ["ReprTraceback" , Optional ["ReprFileLocation" ], Optional [str ]]
948
- ],
949
- ) -> None :
950
- super ().__init__ ()
951
- self .chain = chain
950
+ ]
951
+ )
952
+
953
+ def __attrs_post_init__ (self ):
954
+ super ().__attrs_post_init__ ()
952
955
# reprcrash and reprtraceback of the outermost (the newest) exception
953
956
# in the chain
954
- self .reprtraceback = chain [- 1 ][0 ]
955
- self .reprcrash = chain [- 1 ][1 ]
957
+ self .reprtraceback = self . chain [- 1 ][0 ]
958
+ self .reprcrash = self . chain [- 1 ][1 ]
956
959
957
960
def toterminal (self , tw : TerminalWriter ) -> None :
958
961
for element in self .chain :
@@ -963,13 +966,10 @@ def toterminal(self, tw: TerminalWriter) -> None:
963
966
super ().toterminal (tw )
964
967
965
968
969
+ @attr .s
966
970
class ReprExceptionInfo (ExceptionRepr ):
967
- def __init__ (
968
- self , reprtraceback : "ReprTraceback" , reprcrash : "ReprFileLocation"
969
- ) -> None :
970
- super ().__init__ ()
971
- self .reprtraceback = reprtraceback
972
- self .reprcrash = reprcrash
971
+ reprtraceback = attr .ib (type = "ReprTraceback" )
972
+ reprcrash = attr .ib (type = "ReprFileLocation" )
973
973
974
974
def toterminal (self , tw : TerminalWriter ) -> None :
975
975
self .reprtraceback .toterminal (tw )
@@ -1010,30 +1010,22 @@ def __init__(self, tblines: Sequence[str]) -> None:
1010
1010
self .extraline = None
1011
1011
1012
1012
1013
+ @attr .s
1013
1014
class ReprEntryNative (TerminalRepr ):
1015
+ lines = attr .ib (type = Sequence [str ])
1014
1016
style = "native" # type: _TracebackStyle
1015
1017
1016
- def __init__ (self , tblines : Sequence [str ]) -> None :
1017
- self .lines = tblines
1018
-
1019
1018
def toterminal (self , tw : TerminalWriter ) -> None :
1020
1019
tw .write ("" .join (self .lines ))
1021
1020
1022
1021
1022
+ @attr .s
1023
1023
class ReprEntry (TerminalRepr ):
1024
- def __init__ (
1025
- self ,
1026
- lines : Sequence [str ],
1027
- reprfuncargs : Optional ["ReprFuncArgs" ],
1028
- reprlocals : Optional ["ReprLocals" ],
1029
- filelocrepr : Optional ["ReprFileLocation" ],
1030
- style : "_TracebackStyle" ,
1031
- ) -> None :
1032
- self .lines = lines
1033
- self .reprfuncargs = reprfuncargs
1034
- self .reprlocals = reprlocals
1035
- self .reprfileloc = filelocrepr
1036
- self .style = style
1024
+ lines = attr .ib (type = Sequence [str ])
1025
+ reprfuncargs = attr .ib (type = Optional ["ReprFuncArgs" ])
1026
+ reprlocals = attr .ib (type = Optional ["ReprLocals" ])
1027
+ reprfileloc = attr .ib (type = Optional ["ReprFileLocation" ])
1028
+ style = attr .ib (type = "_TracebackStyle" )
1037
1029
1038
1030
def _write_entry_lines (self , tw : TerminalWriter ) -> None :
1039
1031
"""Writes the source code portions of a list of traceback entries with syntax highlighting.
@@ -1118,18 +1110,18 @@ def toterminal(self, tw: TerminalWriter) -> None:
1118
1110
tw .line (":{}: {}" .format (self .lineno , msg ))
1119
1111
1120
1112
1113
+ @attr .s
1121
1114
class ReprLocals (TerminalRepr ):
1122
- def __init__ (self , lines : Sequence [str ]) -> None :
1123
- self .lines = lines
1115
+ lines = attr .ib (type = Sequence [str ])
1124
1116
1125
1117
def toterminal (self , tw : TerminalWriter , indent = "" ) -> None :
1126
1118
for line in self .lines :
1127
1119
tw .line (indent + line )
1128
1120
1129
1121
1122
+ @attr .s
1130
1123
class ReprFuncArgs (TerminalRepr ):
1131
- def __init__ (self , args : Sequence [Tuple [str , object ]]) -> None :
1132
- self .args = args
1124
+ args = attr .ib (type = Sequence [Tuple [str , object ]])
1133
1125
1134
1126
def toterminal (self , tw : TerminalWriter ) -> None :
1135
1127
if self .args :
0 commit comments