Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69e9e8b

Browse files
committed
Reformat and edit docstrings to follow modern conventions. Single
line summary followed by blank line and description.
1 parent ded4bd7 commit 69e9e8b

1 file changed

Lines changed: 68 additions & 50 deletions

File tree

Lib/traceback.py

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ def print_list(extracted_list, file=None):
2525
_print(file, ' %s' % line.strip())
2626

2727
def format_list(extracted_list):
28-
"""Given a list of tuples as returned by extract_tb() or
28+
"""Format a list of traceback entry tuples for printing.
29+
30+
Given a list of tuples as returned by extract_tb() or
2931
extract_stack(), return a list of strings ready for printing.
30-
Each string in the resulting list corresponds to the item with
31-
the same index in the argument list. Each string ends in a
32-
newline; the strings may contain internal newlines as well, for
33-
those items whose source text line is not None."""
32+
Each string in the resulting list corresponds to the item with the
33+
same index in the argument list. Each string ends in a newline;
34+
the strings may contain internal newlines as well, for those items
35+
whose source text line is not None.
36+
"""
3437
list = []
3538
for filename, lineno, name, line in extracted_list:
3639
item = ' File "%s", line %d, in %s\n' % (filename,lineno,name)
@@ -42,9 +45,12 @@ def format_list(extracted_list):
4245

4346
def print_tb(tb, limit=None, file=None):
4447
"""Print up to 'limit' stack trace entries from the traceback 'tb'.
45-
If 'limit' is omitted or None, all entries are printed. If 'file' is
46-
omitted or None, the output goes to sys.stderr; otherwise 'file'
47-
should be an open file or file-like object with a write() method."""
48+
49+
If 'limit' is omitted or None, all entries are printed. If 'file'
50+
is omitted or None, the output goes to sys.stderr; otherwise
51+
'file' should be an open file or file-like object with a write()
52+
method.
53+
"""
4854
if not file:
4955
file = sys.stderr
5056
if limit is None:
@@ -69,14 +75,16 @@ def format_tb(tb, limit = None):
6975
return format_list(extract_tb(tb, limit))
7076

7177
def extract_tb(tb, limit = None):
72-
"""Return a list of up to 'limit' pre-processed stack trace entries
73-
extracted from the traceback object 'traceback'. This is useful for
74-
alternate formatting of stack traces. If 'limit' is omitted or None,
75-
all entries are extracted. A pre-processed stack trace entry is a
76-
quadruple (filename, line number, function name, text) representing
77-
the information that is usually printed for a stack trace. The text
78-
is a string with leading and trailing whitespace stripped; if the
79-
source is not available it is None."""
78+
"""Return list of up to limit pre-processed entries from traceback.
79+
80+
This is useful for alternate formatting of stack traces. If
81+
'limit' is omitted or None, all entries are extracted. A
82+
pre-processed stack trace entry is a quadruple (filename, line
83+
number, function name, text) representing the information that is
84+
usually printed for a stack trace. The text is a string with
85+
leading and trailing whitespace stripped; if the source is not
86+
available it is None.
87+
"""
8088
if limit is None:
8189
if hasattr(sys, 'tracebacklimit'):
8290
limit = sys.tracebacklimit
@@ -98,14 +106,16 @@ def extract_tb(tb, limit = None):
98106

99107

100108
def print_exception(etype, value, tb, limit=None, file=None):
101-
"""Print exception information and up to 'limit' stack trace entries
102-
from the traceback 'tb' to 'file'. This differs from print_tb() in
103-
the following ways: (1) if traceback is not None, it prints a header
104-
"Traceback (most recent call last):"; (2) it prints the exception type and
105-
value after the stack trace; (3) if type is SyntaxError and value has
106-
the appropriate format, it prints the line where the syntax error
109+
"""Print exception up to 'limit' stack trace entries from 'tb' to 'file'.
110+
111+
This differs from print_tb() in the following ways: (1) if
112+
traceback is not None, it prints a header "Traceback (most recent
113+
call last):"; (2) it prints the exception type and value after the
114+
stack trace; (3) if type is SyntaxError and value has the
115+
appropriate format, it prints the line where the syntax error
107116
occurred with a caret on the next line indicating the approximate
108-
position of the error."""
117+
position of the error.
118+
"""
109119
if not file:
110120
file = sys.stderr
111121
if tb:
@@ -117,12 +127,14 @@ def print_exception(etype, value, tb, limit=None, file=None):
117127
_print(file, lines[-1], '')
118128

119129
def format_exception(etype, value, tb, limit = None):
120-
"""Format a stack trace and the exception information. The arguments
121-
have the same meaning as the corresponding arguments to
122-
print_exception(). The return value is a list of strings, each
130+
"""Format a stack trace and the exception information.
131+
132+
The arguments have the same meaning as the corresponding arguments
133+
to print_exception(). The return value is a list of strings, each
123134
ending in a newline and some containing internal newlines. When
124135
these lines are concatenated and printed, exactly the same text is
125-
printed as does print_exception()."""
136+
printed as does print_exception().
137+
"""
126138
if tb:
127139
list = ['Traceback (most recent call last):\n']
128140
list = list + format_tb(tb, limit)
@@ -132,14 +144,16 @@ def format_exception(etype, value, tb, limit = None):
132144
return list
133145

134146
def format_exception_only(etype, value):
135-
"""Format the exception part of a traceback. The arguments are the
136-
exception type and value such as given by sys.last_type and
137-
sys.last_value. The return value is a list of strings, each ending
138-
in a newline. Normally, the list contains a single string;
139-
however, for SyntaxError exceptions, it contains several lines that
140-
(when printed) display detailed information about where the syntax
141-
error occurred. The message indicating which exception occurred is
142-
the always last string in the list."""
147+
"""Format the exception part of a traceback.
148+
149+
The arguments are the exception type and value such as given by
150+
sys.last_type and sys.last_value. The return value is a list of
151+
strings, each ending in a newline. Normally, the list contains a
152+
single string; however, for SyntaxError exceptions, it contains
153+
several lines that (when printed) display detailed information
154+
about where the syntax error occurred. The message indicating
155+
which exception occurred is the always last string in the list.
156+
"""
143157
list = []
144158
if type(etype) == types.ClassType:
145159
stype = etype.__name__
@@ -184,8 +198,7 @@ def _some_str(value):
184198

185199

186200
def print_exc(limit=None, file=None):
187-
"""This is a shorthand for 'print_exception(sys.exc_type,
188-
sys.exc_value, sys.exc_traceback, limit, file)'.
201+
"""Shorthand for 'print_exception(sys.exc_type, sys.exc_value, sys.exc_traceback, limit, file)'.
189202
(In fact, it uses sys.exc_info() to retrieve the same information
190203
in a thread-safe way.)"""
191204
if not file:
@@ -206,10 +219,12 @@ def print_last(limit=None, file=None):
206219

207220

208221
def print_stack(f=None, limit=None, file=None):
209-
"""This function prints a stack trace from its invocation point.
210-
The optional 'f' argument can be used to specify an alternate stack
211-
frame at which to start. The optional 'limit' and 'file' arguments
212-
have the same meaning as for print_exception()."""
222+
"""Print a stack trace from its invocation point.
223+
224+
The optional 'f' argument can be used to specify an alternate
225+
stack frame at which to start. The optional 'limit' and 'file'
226+
arguments have the same meaning as for print_exception().
227+
"""
213228
if f is None:
214229
try:
215230
raise ZeroDivisionError
@@ -218,7 +233,7 @@ def print_stack(f=None, limit=None, file=None):
218233
print_list(extract_stack(f, limit), file)
219234

220235
def format_stack(f=None, limit=None):
221-
"""A shorthand for 'format_list(extract_stack(f, limit))'."""
236+
"""Shorthand for 'format_list(extract_stack(f, limit))'."""
222237
if f is None:
223238
try:
224239
raise ZeroDivisionError
@@ -227,12 +242,14 @@ def format_stack(f=None, limit=None):
227242
return format_list(extract_stack(f, limit))
228243

229244
def extract_stack(f=None, limit = None):
230-
"""Extract the raw traceback from the current stack frame. The
231-
return value has the same format as for extract_tb(). The optional
232-
'f' and 'limit' arguments have the same meaning as for print_stack().
233-
Each item in the list is a quadruple (filename, line number,
234-
function name, text), and the entries are in order from oldest
235-
to newest stack frame."""
245+
"""Extract the raw traceback from the current stack frame.
246+
247+
The return value has the same format as for extract_tb(). The
248+
optional 'f' and 'limit' arguments have the same meaning as for
249+
print_stack(). Each item in the list is a quadruple (filename,
250+
line number, function name, text), and the entries are in order
251+
from oldest to newest stack frame.
252+
"""
236253
if f is None:
237254
try:
238255
raise ZeroDivisionError
@@ -258,9 +275,10 @@ def extract_stack(f=None, limit = None):
258275
return list
259276

260277
def tb_lineno(tb):
261-
"""Calculate the correct line number of the traceback given in tb
262-
(even with -O on)."""
278+
"""Calculate correct line number of traceback given in tb.
263279
280+
Even works with -O on.
281+
"""
264282
# Coded by Marc-Andre Lemburg from the example of PyCode_Addr2Line()
265283
# in compile.c.
266284
# Revised version by Jim Hugunin to work with JPython too.

0 commit comments

Comments
 (0)