@@ -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 :
@@ -412,15 +411,16 @@ def from_exc_info(
412
411
exc_info : Tuple ["Type[_E]" , "_E" , TracebackType ],
413
412
exprinfo : Optional [str ] = None ,
414
413
) -> "ExceptionInfo[_E]" :
415
- """Returns an ExceptionInfo for an existing exc_info tuple.
414
+ """Return an ExceptionInfo for an existing exc_info tuple.
416
415
417
416
.. warning::
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 ):
@@ -436,15 +436,16 @@ def from_exc_info(
436
436
def from_current (
437
437
cls , exprinfo : Optional [str ] = None
438
438
) -> "ExceptionInfo[BaseException]" :
439
- """Returns an ExceptionInfo matching the current traceback.
439
+ """Return an ExceptionInfo matching the current traceback.
440
440
441
441
.. warning::
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
@@ -635,7 +638,7 @@ class FormattedExcinfo:
635
638
astcache = attr .ib (default = attr .Factory (dict ), init = False , repr = False )
636
639
637
640
def _getindent (self , source : "Source" ) -> int :
638
- # figure out indent for given source
641
+ # Figure out indent for the given source.
639
642
try :
640
643
s = str (source .getstatement (len (source ) - 1 ))
641
644
except KeyboardInterrupt :
@@ -696,7 +699,7 @@ def get_exconly(
696
699
) -> List [str ]:
697
700
lines = []
698
701
indentstr = " " * indent
699
- # get the real exception information out
702
+ # Get the real exception information out.
700
703
exlines = excinfo .exconly (tryshort = True ).split ("\n " )
701
704
failindent = self .fail_marker + indentstr [1 :]
702
705
for line in exlines :
@@ -722,8 +725,7 @@ def repr_locals(self, locals: Mapping[str, object]) -> Optional["ReprLocals"]:
722
725
str_repr = saferepr (value )
723
726
else :
724
727
str_repr = safeformat (value )
725
- # if len(str_repr) < 70 or not isinstance(value,
726
- # (list, tuple, dict)):
728
+ # if len(str_repr) < 70 or not isinstance(value, (list, tuple, dict)):
727
729
lines .append ("{:<10} = {}" .format (name , str_repr ))
728
730
# else:
729
731
# self._line("%-10s =\\" % (name,))
@@ -801,16 +803,17 @@ def repr_traceback(self, excinfo: ExceptionInfo) -> "ReprTraceback":
801
803
def _truncate_recursive_traceback (
802
804
self , traceback : Traceback
803
805
) -> Tuple [Traceback , Optional [str ]]:
804
- """
805
- Truncate the given recursive traceback trying to find the starting point
806
- of the recursion.
806
+ """Truncate the given recursive traceback trying to find the starting
807
+ point of the recursion.
807
808
808
- The detection is done by going through each traceback entry and finding the
809
- point in which the locals of the frame are equal to the locals of a previous frame (see ``recursionindex()``.
809
+ The detection is done by going through each traceback entry and
810
+ finding the point in which the locals of the frame are equal to the
811
+ locals of a previous frame (see ``recursionindex()``).
810
812
811
- Handle the situation where the recursion process might raise an exception (for example
812
- comparing numpy arrays using equality raises a TypeError), in which case we do our best to
813
- warn the user of the error and show a limited traceback.
813
+ Handle the situation where the recursion process might raise an
814
+ exception (for example comparing numpy arrays using equality raises a
815
+ TypeError), in which case we do our best to warn the user of the
816
+ error and show a limited traceback.
814
817
"""
815
818
try :
816
819
recursionindex = traceback .recursionindex ()
@@ -855,8 +858,8 @@ def repr_excinfo(self, excinfo: ExceptionInfo) -> "ExceptionChainRepr":
855
858
excinfo_ ._getreprcrash () if self .style != "value" else None
856
859
) # type: Optional[ReprFileLocation]
857
860
else :
858
- # fallback to native repr if the exception doesn't have a traceback:
859
- # ExceptionInfo objects require a full traceback to work
861
+ # Fallback to native repr if the exception doesn't have a traceback:
862
+ # ExceptionInfo objects require a full traceback to work.
860
863
reprtraceback = ReprTracebackNative (
861
864
traceback .format_exception (type (e ), e , None )
862
865
)
@@ -907,7 +910,7 @@ def toterminal(self, tw: TerminalWriter) -> None:
907
910
# This class is abstract -- only subclasses are instantiated.
908
911
@attr .s (** {ATTRS_EQ_FIELD : False }) # type: ignore
909
912
class ExceptionRepr (TerminalRepr ):
910
- # Provided by in subclasses.
913
+ # Provided by subclasses.
911
914
reprcrash = None # type: Optional[ReprFileLocation]
912
915
reprtraceback = None # type: ReprTraceback
913
916
@@ -934,7 +937,7 @@ class ExceptionChainRepr(ExceptionRepr):
934
937
def __attrs_post_init__ (self ) -> None :
935
938
super ().__attrs_post_init__ ()
936
939
# reprcrash and reprtraceback of the outermost (the newest) exception
937
- # in the chain
940
+ # in the chain.
938
941
self .reprtraceback = self .chain [- 1 ][0 ]
939
942
self .reprcrash = self .chain [- 1 ][1 ]
940
943
@@ -966,7 +969,7 @@ class ReprTraceback(TerminalRepr):
966
969
entrysep = "_ "
967
970
968
971
def toterminal (self , tw : TerminalWriter ) -> None :
969
- # the entries might have different styles
972
+ # The entries might have different styles.
970
973
for i , entry in enumerate (self .reprentries ):
971
974
if entry .style == "long" :
972
975
tw .line ("" )
@@ -1009,7 +1012,7 @@ class ReprEntry(TerminalRepr):
1009
1012
style = attr .ib (type = "_TracebackStyle" )
1010
1013
1011
1014
def _write_entry_lines (self , tw : TerminalWriter ) -> None :
1012
- """Writes the source code portions of a list of traceback entries with syntax highlighting.
1015
+ """Write the source code portions of a list of traceback entries with syntax highlighting.
1013
1016
1014
1017
Usually entries are lines like these:
1015
1018
@@ -1091,8 +1094,8 @@ class ReprFileLocation(TerminalRepr):
1091
1094
message = attr .ib (type = str )
1092
1095
1093
1096
def toterminal (self , tw : TerminalWriter ) -> None :
1094
- # filename and lineno output for each entry,
1095
- # using an output format that most editors understand
1097
+ # Filename and lineno output for each entry, using an output format
1098
+ # that most editors understand.
1096
1099
msg = self .message
1097
1100
i = msg .find ("\n " )
1098
1101
if i != - 1 :
@@ -1167,10 +1170,10 @@ def getfslineno(obj: object) -> Tuple[Union[str, py.path.local], int]:
1167
1170
return code .path , code .firstlineno
1168
1171
1169
1172
1170
- # relative paths that we use to filter traceback entries from appearing to the user;
1171
- # see filter_traceback
1173
+ # Relative paths that we use to filter traceback entries from appearing to the user;
1174
+ # see filter_traceback.
1172
1175
# note: if we need to add more paths than what we have now we should probably use a list
1173
- # for better maintenance
1176
+ # for better maintenance.
1174
1177
1175
1178
_PLUGGY_DIR = py .path .local (pluggy .__file__ .rstrip ("oc" ))
1176
1179
# pluggy is either a package or a single module depending on the version
@@ -1189,14 +1192,14 @@ def filter_traceback(entry: TracebackEntry) -> bool:
1189
1192
* internal traceback from pytest or its internal libraries, py and pluggy.
1190
1193
"""
1191
1194
# entry.path might sometimes return a str object when the entry
1192
- # points to dynamically generated code
1193
- # see https://bitbucket.org/pytest-dev/py/issues/71
1195
+ # points to dynamically generated code.
1196
+ # See https://bitbucket.org/pytest-dev/py/issues/71.
1194
1197
raw_filename = entry .frame .code .raw .co_filename
1195
1198
is_generated = "<" in raw_filename and ">" in raw_filename
1196
1199
if is_generated :
1197
1200
return False
1198
1201
# entry.path might point to a non-existing file, in which case it will
1199
- # also return a str object. see #1133
1202
+ # also return a str object. See #1133.
1200
1203
p = py .path .local (entry .path )
1201
1204
return (
1202
1205
not p .relto (_PLUGGY_DIR ) and not p .relto (_PYTEST_DIR ) and not p .relto (_PY_DIR )
0 commit comments