1
1
import ast
2
+ import dataclasses
2
3
import inspect
3
4
import os
4
5
import re
32
33
from typing import Union
33
34
from weakref import ref
34
35
35
- import attr
36
36
import pluggy
37
37
38
38
import _pytest
@@ -445,7 +445,7 @@ def recursionindex(self) -> Optional[int]:
445
445
446
446
447
447
@final
448
- @attr . s ( repr = False , init = False , auto_attribs = True )
448
+ @dataclasses . dataclass
449
449
class ExceptionInfo (Generic [E ]):
450
450
"""Wraps sys.exc_info() objects and offers help for navigating the traceback."""
451
451
@@ -649,12 +649,12 @@ def getrepr(
649
649
"""
650
650
if style == "native" :
651
651
return ReprExceptionInfo (
652
- ReprTracebackNative (
652
+ reprtraceback = ReprTracebackNative (
653
653
traceback .format_exception (
654
654
self .type , self .value , self .traceback [0 ]._rawentry
655
655
)
656
656
),
657
- self ._getreprcrash (),
657
+ reprcrash = self ._getreprcrash (),
658
658
)
659
659
660
660
fmt = FormattedExcinfo (
@@ -684,7 +684,7 @@ def match(self, regexp: Union[str, Pattern[str]]) -> "Literal[True]":
684
684
return True
685
685
686
686
687
- @attr . s ( auto_attribs = True )
687
+ @dataclasses . dataclass
688
688
class FormattedExcinfo :
689
689
"""Presenting information about failing Functions and Generators."""
690
690
@@ -699,8 +699,8 @@ class FormattedExcinfo:
699
699
funcargs : bool = False
700
700
truncate_locals : bool = True
701
701
chain : bool = True
702
- astcache : Dict [Union [str , Path ], ast .AST ] = attr . ib (
703
- factory = dict , init = False , repr = False
702
+ astcache : Dict [Union [str , Path ], ast .AST ] = dataclasses . field (
703
+ default_factory = dict , init = False , repr = False
704
704
)
705
705
706
706
def _getindent (self , source : "Source" ) -> int :
@@ -978,7 +978,7 @@ def repr_excinfo(
978
978
return ExceptionChainRepr (repr_chain )
979
979
980
980
981
- @attr . s (eq = False , auto_attribs = True )
981
+ @dataclasses . dataclass (eq = False )
982
982
class TerminalRepr :
983
983
def __str__ (self ) -> str :
984
984
# FYI this is called from pytest-xdist's serialization of exception
@@ -996,14 +996,14 @@ def toterminal(self, tw: TerminalWriter) -> None:
996
996
997
997
998
998
# This class is abstract -- only subclasses are instantiated.
999
- @attr . s (eq = False )
999
+ @dataclasses . dataclass (eq = False )
1000
1000
class ExceptionRepr (TerminalRepr ):
1001
1001
# Provided by subclasses.
1002
- reprcrash : Optional ["ReprFileLocation" ]
1003
1002
reprtraceback : "ReprTraceback"
1004
-
1005
- def __attrs_post_init__ (self ) -> None :
1006
- self .sections : List [Tuple [str , str , str ]] = []
1003
+ reprcrash : Optional ["ReprFileLocation" ]
1004
+ sections : List [Tuple [str , str , str ]] = dataclasses .field (
1005
+ init = False , default_factory = list
1006
+ )
1007
1007
1008
1008
def addsection (self , name : str , content : str , sep : str = "-" ) -> None :
1009
1009
self .sections .append ((name , content , sep ))
@@ -1014,16 +1014,23 @@ def toterminal(self, tw: TerminalWriter) -> None:
1014
1014
tw .line (content )
1015
1015
1016
1016
1017
- @attr . s (eq = False , auto_attribs = True )
1017
+ @dataclasses . dataclass (eq = False )
1018
1018
class ExceptionChainRepr (ExceptionRepr ):
1019
1019
chain : Sequence [Tuple ["ReprTraceback" , Optional ["ReprFileLocation" ], Optional [str ]]]
1020
1020
1021
- def __attrs_post_init__ (self ) -> None :
1022
- super ().__attrs_post_init__ ()
1021
+ def __init__ (
1022
+ self ,
1023
+ chain : Sequence [
1024
+ Tuple ["ReprTraceback" , Optional ["ReprFileLocation" ], Optional [str ]]
1025
+ ],
1026
+ ) -> None :
1023
1027
# reprcrash and reprtraceback of the outermost (the newest) exception
1024
1028
# in the chain.
1025
- self .reprtraceback = self .chain [- 1 ][0 ]
1026
- self .reprcrash = self .chain [- 1 ][1 ]
1029
+ super ().__init__ (
1030
+ reprtraceback = chain [- 1 ][0 ],
1031
+ reprcrash = chain [- 1 ][1 ],
1032
+ )
1033
+ self .chain = chain
1027
1034
1028
1035
def toterminal (self , tw : TerminalWriter ) -> None :
1029
1036
for element in self .chain :
@@ -1034,7 +1041,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
1034
1041
super ().toterminal (tw )
1035
1042
1036
1043
1037
- @attr . s (eq = False , auto_attribs = True )
1044
+ @dataclasses . dataclass (eq = False )
1038
1045
class ReprExceptionInfo (ExceptionRepr ):
1039
1046
reprtraceback : "ReprTraceback"
1040
1047
reprcrash : "ReprFileLocation"
@@ -1044,7 +1051,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
1044
1051
super ().toterminal (tw )
1045
1052
1046
1053
1047
- @attr . s (eq = False , auto_attribs = True )
1054
+ @dataclasses . dataclass (eq = False )
1048
1055
class ReprTraceback (TerminalRepr ):
1049
1056
reprentries : Sequence [Union ["ReprEntry" , "ReprEntryNative" ]]
1050
1057
extraline : Optional [str ]
@@ -1073,12 +1080,12 @@ def toterminal(self, tw: TerminalWriter) -> None:
1073
1080
1074
1081
class ReprTracebackNative (ReprTraceback ):
1075
1082
def __init__ (self , tblines : Sequence [str ]) -> None :
1076
- self .style = "native"
1077
1083
self .reprentries = [ReprEntryNative (tblines )]
1078
1084
self .extraline = None
1085
+ self .style = "native"
1079
1086
1080
1087
1081
- @attr . s (eq = False , auto_attribs = True )
1088
+ @dataclasses . dataclass (eq = False )
1082
1089
class ReprEntryNative (TerminalRepr ):
1083
1090
lines : Sequence [str ]
1084
1091
@@ -1088,7 +1095,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
1088
1095
tw .write ("" .join (self .lines ))
1089
1096
1090
1097
1091
- @attr . s (eq = False , auto_attribs = True )
1098
+ @dataclasses . dataclass (eq = False )
1092
1099
class ReprEntry (TerminalRepr ):
1093
1100
lines : Sequence [str ]
1094
1101
reprfuncargs : Optional ["ReprFuncArgs" ]
@@ -1168,12 +1175,15 @@ def __str__(self) -> str:
1168
1175
)
1169
1176
1170
1177
1171
- @attr . s (eq = False , auto_attribs = True )
1178
+ @dataclasses . dataclass (eq = False )
1172
1179
class ReprFileLocation (TerminalRepr ):
1173
- path : str = attr . ib ( converter = str )
1180
+ path : str
1174
1181
lineno : int
1175
1182
message : str
1176
1183
1184
+ def __post_init__ (self ) -> None :
1185
+ self .path = str (self .path )
1186
+
1177
1187
def toterminal (self , tw : TerminalWriter ) -> None :
1178
1188
# Filename and lineno output for each entry, using an output format
1179
1189
# that most editors understand.
@@ -1185,7 +1195,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
1185
1195
tw .line (f":{ self .lineno } : { msg } " )
1186
1196
1187
1197
1188
- @attr . s (eq = False , auto_attribs = True )
1198
+ @dataclasses . dataclass (eq = False )
1189
1199
class ReprLocals (TerminalRepr ):
1190
1200
lines : Sequence [str ]
1191
1201
@@ -1194,7 +1204,7 @@ def toterminal(self, tw: TerminalWriter, indent="") -> None:
1194
1204
tw .line (indent + line )
1195
1205
1196
1206
1197
- @attr . s (eq = False , auto_attribs = True )
1207
+ @dataclasses . dataclass (eq = False )
1198
1208
class ReprFuncArgs (TerminalRepr ):
1199
1209
args : Sequence [Tuple [str , object ]]
1200
1210
0 commit comments