@@ -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 :
@@ -418,9 +417,10 @@ def from_exc_info(
418
417
419
418
Experimental API
420
419
421
- :param exprinfo: a text string helping to determine if we should
422
- strip ``AssertionError`` from the output, defaults
423
- to the exception message/``__str__()``
420
+ :param exprinfo:
421
+ A text string helping to determine if we should strip
422
+ ``AssertionError`` from the output. Defaults to the exception
423
+ message/``__str__()``.
424
424
"""
425
425
_striptext = ""
426
426
if exprinfo is None and isinstance (exc_info [1 ], AssertionError ):
@@ -442,9 +442,10 @@ def from_current(
442
442
443
443
Experimental API
444
444
445
- :param exprinfo: a text string helping to determine if we should
446
- strip ``AssertionError`` from the output, defaults
447
- to the exception message/``__str__()``
445
+ :param exprinfo:
446
+ A text string helping to determine if we should strip
447
+ ``AssertionError`` from the output. Defaults to the exception
448
+ message/``__str__()``.
448
449
"""
449
450
tup = sys .exc_info ()
450
451
assert tup [0 ] is not None , "no current exception"
@@ -459,7 +460,7 @@ def for_later(cls) -> "ExceptionInfo[_E]":
459
460
return cls (None )
460
461
461
462
def fill_unfilled (self , exc_info : Tuple ["Type[_E]" , _E , TracebackType ]) -> None :
462
- """fill an unfilled ExceptionInfo created with for_later()"""
463
+ """Fill an unfilled ExceptionInfo created with `` for_later()``. """
463
464
assert self ._excinfo is None , "ExceptionInfo was already filled"
464
465
self ._excinfo = exc_info
465
466
@@ -560,7 +561,8 @@ def getrepr(
560
561
Show locals per traceback entry.
561
562
Ignored if ``style=="native"``.
562
563
563
- :param str style: long|short|no|native|value traceback style
564
+ :param str style:
565
+ long|short|no|native|value traceback style.
564
566
565
567
:param bool abspath:
566
568
If paths should be changed to absolute or left unchanged.
@@ -575,7 +577,8 @@ def getrepr(
575
577
:param bool truncate_locals:
576
578
With ``showlocals==True``, make sure locals can be safely represented as strings.
577
579
578
- :param bool chain: if chained exceptions in Python 3 should be shown.
580
+ :param bool chain:
581
+ If chained exceptions in Python 3 should be shown.
579
582
580
583
.. versionchanged:: 3.9
581
584
@@ -634,7 +637,7 @@ class FormattedExcinfo:
634
637
astcache = attr .ib (default = attr .Factory (dict ), init = False , repr = False )
635
638
636
639
def _getindent (self , source : "Source" ) -> int :
637
- # figure out indent for given source
640
+ # Figure out indent for the given source.
638
641
try :
639
642
s = str (source .getstatement (len (source ) - 1 ))
640
643
except KeyboardInterrupt :
@@ -695,7 +698,7 @@ def get_exconly(
695
698
) -> List [str ]:
696
699
lines = []
697
700
indentstr = " " * indent
698
- # get the real exception information out
701
+ # Get the real exception information out.
699
702
exlines = excinfo .exconly (tryshort = True ).split ("\n " )
700
703
failindent = self .fail_marker + indentstr [1 :]
701
704
for line in exlines :
@@ -721,8 +724,7 @@ def repr_locals(self, locals: Mapping[str, object]) -> Optional["ReprLocals"]:
721
724
str_repr = saferepr (value )
722
725
else :
723
726
str_repr = safeformat (value )
724
- # if len(str_repr) < 70 or not isinstance(value,
725
- # (list, tuple, dict)):
727
+ # if len(str_repr) < 70 or not isinstance(value, (list, tuple, dict)):
726
728
lines .append ("{:<10} = {}" .format (name , str_repr ))
727
729
# else:
728
730
# self._line("%-10s =\\" % (name,))
@@ -800,16 +802,17 @@ def repr_traceback(self, excinfo: ExceptionInfo) -> "ReprTraceback":
800
802
def _truncate_recursive_traceback (
801
803
self , traceback : Traceback
802
804
) -> Tuple [Traceback , Optional [str ]]:
803
- """
804
- Truncate the given recursive traceback trying to find the starting point
805
- of the recursion.
805
+ """Truncate the given recursive traceback trying to find the starting
806
+ point of the recursion.
806
807
807
- The detection is done by going through each traceback entry and finding the
808
- point in which the locals of the frame are equal to the locals of a previous frame (see ``recursionindex()``.
808
+ The detection is done by going through each traceback entry and
809
+ finding the point in which the locals of the frame are equal to the
810
+ locals of a previous frame (see ``recursionindex()``).
809
811
810
- Handle the situation where the recursion process might raise an exception (for example
811
- comparing numpy arrays using equality raises a TypeError), in which case we do our best to
812
- warn the user of the error and show a limited traceback.
812
+ Handle the situation where the recursion process might raise an
813
+ exception (for example comparing numpy arrays using equality raises a
814
+ TypeError), in which case we do our best to warn the user of the
815
+ error and show a limited traceback.
813
816
"""
814
817
try :
815
818
recursionindex = traceback .recursionindex ()
@@ -854,8 +857,8 @@ def repr_excinfo(self, excinfo: ExceptionInfo) -> "ExceptionChainRepr":
854
857
excinfo_ ._getreprcrash () if self .style != "value" else None
855
858
) # type: Optional[ReprFileLocation]
856
859
else :
857
- # fallback to native repr if the exception doesn't have a traceback:
858
- # ExceptionInfo objects require a full traceback to work
860
+ # Fallback to native repr if the exception doesn't have a traceback:
861
+ # ExceptionInfo objects require a full traceback to work.
859
862
reprtraceback = ReprTracebackNative (
860
863
traceback .format_exception (type (e ), e , None )
861
864
)
@@ -906,7 +909,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
906
909
# This class is abstract -- only subclasses are instantiated.
907
910
@attr .s (** {ATTRS_EQ_FIELD : False }) # type: ignore
908
911
class ExceptionRepr (TerminalRepr ):
909
- # Provided by in subclasses.
912
+ # Provided by subclasses.
910
913
reprcrash = None # type: Optional[ReprFileLocation]
911
914
reprtraceback = None # type: ReprTraceback
912
915
@@ -933,7 +936,7 @@ class ExceptionChainRepr(ExceptionRepr):
933
936
def __attrs_post_init__ (self ) -> None :
934
937
super ().__attrs_post_init__ ()
935
938
# reprcrash and reprtraceback of the outermost (the newest) exception
936
- # in the chain
939
+ # in the chain.
937
940
self .reprtraceback = self .chain [- 1 ][0 ]
938
941
self .reprcrash = self .chain [- 1 ][1 ]
939
942
@@ -965,7 +968,7 @@ class ReprTraceback(TerminalRepr):
965
968
entrysep = "_ "
966
969
967
970
def toterminal (self , tw : TerminalWriter ) -> None :
968
- # the entries might have different styles
971
+ # The entries might have different styles.
969
972
for i , entry in enumerate (self .reprentries ):
970
973
if entry .style == "long" :
971
974
tw .line ("" )
@@ -1090,8 +1093,8 @@ class ReprFileLocation(TerminalRepr):
1090
1093
message = attr .ib (type = str )
1091
1094
1092
1095
def toterminal (self , tw : TerminalWriter ) -> None :
1093
- # filename and lineno output for each entry,
1094
- # using an output format that most editors understand
1096
+ # Filename and lineno output for each entry, using an output format
1097
+ # that most editors understand.
1095
1098
msg = self .message
1096
1099
i = msg .find ("\n " )
1097
1100
if i != - 1 :
@@ -1166,10 +1169,10 @@ def getfslineno(obj: object) -> Tuple[Union[str, py.path.local], int]:
1166
1169
return code .path , code .firstlineno
1167
1170
1168
1171
1169
- # relative paths that we use to filter traceback entries from appearing to the user;
1170
- # see filter_traceback
1172
+ # Relative paths that we use to filter traceback entries from appearing to the user;
1173
+ # see filter_traceback.
1171
1174
# note: if we need to add more paths than what we have now we should probably use a list
1172
- # for better maintenance
1175
+ # for better maintenance.
1173
1176
1174
1177
_PLUGGY_DIR = py .path .local (pluggy .__file__ .rstrip ("oc" ))
1175
1178
# pluggy is either a package or a single module depending on the version
@@ -1188,14 +1191,14 @@ def filter_traceback(entry: TracebackEntry) -> bool:
1188
1191
* internal traceback from pytest or its internal libraries, py and pluggy.
1189
1192
"""
1190
1193
# entry.path might sometimes return a str object when the entry
1191
- # points to dynamically generated code
1192
- # see https://bitbucket.org/pytest-dev/py/issues/71
1194
+ # points to dynamically generated code.
1195
+ # See https://bitbucket.org/pytest-dev/py/issues/71.
1193
1196
raw_filename = entry .frame .code .raw .co_filename
1194
1197
is_generated = "<" in raw_filename and ">" in raw_filename
1195
1198
if is_generated :
1196
1199
return False
1197
1200
# entry.path might point to a non-existing file, in which case it will
1198
- # also return a str object. see #1133
1201
+ # also return a str object. See #1133.
1199
1202
p = py .path .local (entry .path )
1200
1203
return (
1201
1204
not p .relto (_PLUGGY_DIR ) and not p .relto (_PYTEST_DIR ) and not p .relto (_PY_DIR )
0 commit comments