@@ -71,9 +71,8 @@ def __eq__(self, other):
71
71
72
72
@property
73
73
def path (self ) -> Union [py .path .local , str ]:
74
- """Return a path object pointing to source code (or a str in case
75
- of OSError / non-existing file).
76
- """
74
+ """Return a path object pointing to source code, or an ``str`` in
75
+ case of ``OSError`` / non-existing file."""
77
76
if not self .raw .co_filename :
78
77
return ""
79
78
try :
@@ -420,15 +419,16 @@ def from_exc_info(
420
419
exc_info : Tuple ["Type[_E]" , "_E" , TracebackType ],
421
420
exprinfo : Optional [str ] = None ,
422
421
) -> "ExceptionInfo[_E]" :
423
- """Returns an ExceptionInfo for an existing exc_info tuple.
422
+ """Return an ExceptionInfo for an existing exc_info tuple.
424
423
425
424
.. warning::
426
425
427
426
Experimental API
428
427
429
- :param exprinfo: a text string helping to determine if we should
430
- strip ``AssertionError`` from the output, defaults
431
- to the exception message/``__str__()``
428
+ :param exprinfo:
429
+ A text string helping to determine if we should strip
430
+ ``AssertionError`` from the output. Defaults to the exception
431
+ message/``__str__()``.
432
432
"""
433
433
_striptext = ""
434
434
if exprinfo is None and isinstance (exc_info [1 ], AssertionError ):
@@ -444,15 +444,16 @@ def from_exc_info(
444
444
def from_current (
445
445
cls , exprinfo : Optional [str ] = None
446
446
) -> "ExceptionInfo[BaseException]" :
447
- """Returns an ExceptionInfo matching the current traceback.
447
+ """Return an ExceptionInfo matching the current traceback.
448
448
449
449
.. warning::
450
450
451
451
Experimental API
452
452
453
- :param exprinfo: a text string helping to determine if we should
454
- strip ``AssertionError`` from the output, defaults
455
- to the exception message/``__str__()``
453
+ :param exprinfo:
454
+ A text string helping to determine if we should strip
455
+ ``AssertionError`` from the output. Defaults to the exception
456
+ message/``__str__()``.
456
457
"""
457
458
tup = sys .exc_info ()
458
459
assert tup [0 ] is not None , "no current exception"
@@ -467,7 +468,7 @@ def for_later(cls) -> "ExceptionInfo[_E]":
467
468
return cls (None )
468
469
469
470
def fill_unfilled (self , exc_info : Tuple ["Type[_E]" , _E , TracebackType ]) -> None :
470
- """fill an unfilled ExceptionInfo created with for_later()"""
471
+ """Fill an unfilled ExceptionInfo created with `` for_later()``. """
471
472
assert self ._excinfo is None , "ExceptionInfo was already filled"
472
473
self ._excinfo = exc_info
473
474
@@ -568,7 +569,8 @@ def getrepr(
568
569
Show locals per traceback entry.
569
570
Ignored if ``style=="native"``.
570
571
571
- :param str style: long|short|no|native|value traceback style
572
+ :param str style:
573
+ long|short|no|native|value traceback style.
572
574
573
575
:param bool abspath:
574
576
If paths should be changed to absolute or left unchanged.
@@ -583,7 +585,8 @@ def getrepr(
583
585
:param bool truncate_locals:
584
586
With ``showlocals==True``, make sure locals can be safely represented as strings.
585
587
586
- :param bool chain: if chained exceptions in Python 3 should be shown.
588
+ :param bool chain:
589
+ If chained exceptions in Python 3 should be shown.
587
590
588
591
.. versionchanged:: 3.9
589
592
@@ -643,7 +646,7 @@ class FormattedExcinfo:
643
646
astcache = attr .ib (default = attr .Factory (dict ), init = False , repr = False )
644
647
645
648
def _getindent (self , source : "Source" ) -> int :
646
- # figure out indent for given source
649
+ # Figure out indent for the given source.
647
650
try :
648
651
s = str (source .getstatement (len (source ) - 1 ))
649
652
except KeyboardInterrupt :
@@ -704,7 +707,7 @@ def get_exconly(
704
707
) -> List [str ]:
705
708
lines = []
706
709
indentstr = " " * indent
707
- # get the real exception information out
710
+ # Get the real exception information out.
708
711
exlines = excinfo .exconly (tryshort = True ).split ("\n " )
709
712
failindent = self .fail_marker + indentstr [1 :]
710
713
for line in exlines :
@@ -730,8 +733,7 @@ def repr_locals(self, locals: Mapping[str, object]) -> Optional["ReprLocals"]:
730
733
str_repr = saferepr (value )
731
734
else :
732
735
str_repr = safeformat (value )
733
- # if len(str_repr) < 70 or not isinstance(value,
734
- # (list, tuple, dict)):
736
+ # if len(str_repr) < 70 or not isinstance(value, (list, tuple, dict)):
735
737
lines .append ("{:<10} = {}" .format (name , str_repr ))
736
738
# else:
737
739
# self._line("%-10s =\\" % (name,))
@@ -809,16 +811,17 @@ def repr_traceback(self, excinfo: ExceptionInfo) -> "ReprTraceback":
809
811
def _truncate_recursive_traceback (
810
812
self , traceback : Traceback
811
813
) -> Tuple [Traceback , Optional [str ]]:
812
- """
813
- Truncate the given recursive traceback trying to find the starting point
814
- of the recursion.
814
+ """Truncate the given recursive traceback trying to find the starting
815
+ point of the recursion.
815
816
816
- The detection is done by going through each traceback entry and finding the
817
- point in which the locals of the frame are equal to the locals of a previous frame (see ``recursionindex()``.
817
+ The detection is done by going through each traceback entry and
818
+ finding the point in which the locals of the frame are equal to the
819
+ locals of a previous frame (see ``recursionindex()``).
818
820
819
- Handle the situation where the recursion process might raise an exception (for example
820
- comparing numpy arrays using equality raises a TypeError), in which case we do our best to
821
- warn the user of the error and show a limited traceback.
821
+ Handle the situation where the recursion process might raise an
822
+ exception (for example comparing numpy arrays using equality raises a
823
+ TypeError), in which case we do our best to warn the user of the
824
+ error and show a limited traceback.
822
825
"""
823
826
try :
824
827
recursionindex = traceback .recursionindex ()
@@ -863,8 +866,8 @@ def repr_excinfo(self, excinfo: ExceptionInfo) -> "ExceptionChainRepr":
863
866
excinfo_ ._getreprcrash () if self .style != "value" else None
864
867
) # type: Optional[ReprFileLocation]
865
868
else :
866
- # fallback to native repr if the exception doesn't have a traceback:
867
- # ExceptionInfo objects require a full traceback to work
869
+ # Fallback to native repr if the exception doesn't have a traceback:
870
+ # ExceptionInfo objects require a full traceback to work.
868
871
reprtraceback = ReprTracebackNative (
869
872
traceback .format_exception (type (e ), e , None )
870
873
)
@@ -915,7 +918,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
915
918
# This class is abstract -- only subclasses are instantiated.
916
919
@attr .s (** {ATTRS_EQ_FIELD : False }) # type: ignore
917
920
class ExceptionRepr (TerminalRepr ):
918
- # Provided by in subclasses.
921
+ # Provided by subclasses.
919
922
reprcrash = None # type: Optional[ReprFileLocation]
920
923
reprtraceback = None # type: ReprTraceback
921
924
@@ -942,7 +945,7 @@ class ExceptionChainRepr(ExceptionRepr):
942
945
def __attrs_post_init__ (self ) -> None :
943
946
super ().__attrs_post_init__ ()
944
947
# reprcrash and reprtraceback of the outermost (the newest) exception
945
- # in the chain
948
+ # in the chain.
946
949
self .reprtraceback = self .chain [- 1 ][0 ]
947
950
self .reprcrash = self .chain [- 1 ][1 ]
948
951
@@ -974,7 +977,7 @@ class ReprTraceback(TerminalRepr):
974
977
entrysep = "_ "
975
978
976
979
def toterminal (self , tw : TerminalWriter ) -> None :
977
- # the entries might have different styles
980
+ # The entries might have different styles.
978
981
for i , entry in enumerate (self .reprentries ):
979
982
if entry .style == "long" :
980
983
tw .line ("" )
@@ -1017,7 +1020,7 @@ class ReprEntry(TerminalRepr):
1017
1020
style = attr .ib (type = "_TracebackStyle" )
1018
1021
1019
1022
def _write_entry_lines (self , tw : TerminalWriter ) -> None :
1020
- """Writes the source code portions of a list of traceback entries with syntax highlighting.
1023
+ """Write the source code portions of a list of traceback entries with syntax highlighting.
1021
1024
1022
1025
Usually entries are lines like these:
1023
1026
@@ -1099,8 +1102,8 @@ class ReprFileLocation(TerminalRepr):
1099
1102
message = attr .ib (type = str )
1100
1103
1101
1104
def toterminal (self , tw : TerminalWriter ) -> None :
1102
- # filename and lineno output for each entry,
1103
- # using an output format that most editors understand
1105
+ # Filename and lineno output for each entry, using an output format
1106
+ # that most editors understand.
1104
1107
msg = self .message
1105
1108
i = msg .find ("\n " )
1106
1109
if i != - 1 :
@@ -1175,10 +1178,10 @@ def getfslineno(obj: object) -> Tuple[Union[str, py.path.local], int]:
1175
1178
return code .path , code .firstlineno
1176
1179
1177
1180
1178
- # relative paths that we use to filter traceback entries from appearing to the user;
1179
- # see filter_traceback
1181
+ # Relative paths that we use to filter traceback entries from appearing to the user;
1182
+ # see filter_traceback.
1180
1183
# note: if we need to add more paths than what we have now we should probably use a list
1181
- # for better maintenance
1184
+ # for better maintenance.
1182
1185
1183
1186
_PLUGGY_DIR = py .path .local (pluggy .__file__ .rstrip ("oc" ))
1184
1187
# pluggy is either a package or a single module depending on the version
@@ -1197,14 +1200,14 @@ def filter_traceback(entry: TracebackEntry) -> bool:
1197
1200
* internal traceback from pytest or its internal libraries, py and pluggy.
1198
1201
"""
1199
1202
# entry.path might sometimes return a str object when the entry
1200
- # points to dynamically generated code
1201
- # see https://bitbucket.org/pytest-dev/py/issues/71
1203
+ # points to dynamically generated code.
1204
+ # See https://bitbucket.org/pytest-dev/py/issues/71.
1202
1205
raw_filename = entry .frame .code .raw .co_filename
1203
1206
is_generated = "<" in raw_filename and ">" in raw_filename
1204
1207
if is_generated :
1205
1208
return False
1206
1209
# entry.path might point to a non-existing file, in which case it will
1207
- # also return a str object. see #1133
1210
+ # also return a str object. See #1133.
1208
1211
p = py .path .local (entry .path )
1209
1212
return (
1210
1213
not p .relto (_PLUGGY_DIR ) and not p .relto (_PYTEST_DIR ) and not p .relto (_PY_DIR )
0 commit comments