Skip to content

Commit b9fd5ee

Browse files
committed
Address feedback from review
1 parent b6f23a1 commit b9fd5ee

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

Doc/library/inspect.rst

+19-18
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ Classes and functions
11631163
The interpreter stack
11641164
---------------------
11651165

1166-
When the following functions return "frame records," each record is a
1166+
When the following functions return ":class:`FrameInfo` objects," each record is a
11671167
:class:`FrameInfo` object. For backwards compatibility these objects allow
11681168
tuple-like operations on all attributes except ``positions``. This behavior
11691169
is considered deprecated and may be removed in the future.
@@ -1199,8 +1199,9 @@ is considered deprecated and may be removed in the future.
11991199

12001200
.. attribute:: positions
12011201

1202-
A tuple containing the start line number, end line number, start column offset and end column
1203-
offset associated with the instruction being executed by the frame this record corresponds to.
1202+
A :class:`dis.Positions` object containing the start line number, end line
1203+
number, start column offset and end column offset associated with the
1204+
instruction being executed by the frame this record corresponds to.
12041205

12051206
.. versionchanged:: 3.5
12061207
Return a named tuple instead of a tuple.
@@ -1280,10 +1281,10 @@ line.
12801281

12811282
.. function:: getouterframes(frame, context=1)
12821283

1283-
Get a list of frame records for a frame and all outer frames. These frames
1284-
represent the calls that lead to the creation of *frame*. The first entry in the
1285-
returned list represents *frame*; the last entry represents the outermost call
1286-
on *frame*'s stack.
1284+
Get a list of :class:`FrameInfo` objects for a frame and all outer frames.
1285+
These frames represent the calls that lead to the creation of *frame*. The
1286+
first entry in the returned list represents *frame*; the last entry
1287+
represents the outermost call on *frame*'s stack.
12871288

12881289
.. versionchanged:: 3.5
12891290
A list of :term:`named tuples <named tuple>`
@@ -1295,10 +1296,10 @@ line.
12951296

12961297
.. function:: getinnerframes(traceback, context=1)
12971298

1298-
Get a list of frame records for a traceback's frame and all inner frames. These
1299-
frames represent calls made as a consequence of *frame*. The first entry in the
1300-
list represents *traceback*; the last entry represents where the exception was
1301-
raised.
1299+
Get a list of :class:`FrameInfo` objects for a traceback's frame and all
1300+
inner frames. These frames represent calls made as a consequence of *frame*.
1301+
The first entry in the list represents *traceback*; the last entry represents
1302+
where the exception was raised.
13021303

13031304
.. versionchanged:: 3.5
13041305
A list of :term:`named tuples <named tuple>`
@@ -1322,9 +1323,9 @@ line.
13221323

13231324
.. function:: stack(context=1)
13241325

1325-
Return a list of frame records for the caller's stack. The first entry in the
1326-
returned list represents the caller; the last entry represents the outermost
1327-
call on the stack.
1326+
Return a list of :class:`FrameInfo` objects for the caller's stack. The
1327+
first entry in the returned list represents the caller; the last entry
1328+
represents the outermost call on the stack.
13281329

13291330
.. versionchanged:: 3.5
13301331
A list of :term:`named tuples <named tuple>`
@@ -1336,10 +1337,10 @@ line.
13361337

13371338
.. function:: trace(context=1)
13381339

1339-
Return a list of frame records for the stack between the current frame and the
1340-
frame in which an exception currently being handled was raised in. The first
1341-
entry in the list represents the caller; the last entry represents where the
1342-
exception was raised.
1340+
Return a list of :class:`FrameInfo` objects for the stack between the current
1341+
frame and the frame in which an exception currently being handled was raised
1342+
in. The first entry in the list represents the caller; the last entry
1343+
represents where the exception was raised.
13431344

13441345
.. versionchanged:: 3.5
13451346
A list of :term:`named tuples <named tuple>`

Lib/inspect.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,8 @@ def getframeinfo(frame, context=1):
17021702
else:
17031703
lines = index = None
17041704

1705-
return Traceback(filename, lineno, frame.f_code.co_name, lines, index, tuple(positions))
1705+
return Traceback(filename, lineno, frame.f_code.co_name, lines,
1706+
index, dis.Positions(*positions))
17061707

17071708
def getlineno(frame):
17081709
"""Get the line number from a frame object, allowing for optimization."""

Lib/test/test_inspect.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io
88
import linecache
99
import os
10+
import dis
1011
from os.path import normcase
1112
import _pickle
1213
import pickle
@@ -365,19 +366,19 @@ def test_stack(self):
365366
frameinfo = revise(*frame1[1:])
366367
self.assertEqual(frameinfo,
367368
(modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0))
368-
self.assertEqual(frame1.positions, (16, 16, 9, 24))
369+
self.assertEqual(frame1.positions, dis.Positions(16, 16, 9, 24))
369370
frameinfo = revise(*frame2[1:])
370371
self.assertEqual(frameinfo,
371372
(modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0))
372-
self.assertEqual(frame2.positions, (9, 9, 4, 22))
373+
self.assertEqual(frame2.positions, dis.Positions(9, 9, 4, 22))
373374
frameinfo = revise(*frame3[1:])
374375
self.assertEqual(frameinfo,
375376
(modfile, 43, 'argue', [' spam(a, b, c)\n'], 0))
376-
self.assertEqual(frame3.positions, (43, 43, 12, 25))
377+
self.assertEqual(frame3.positions, dis.Positions(43, 43, 12, 25))
377378
frameinfo = revise(*frame4[1:])
378379
self.assertEqual(frameinfo,
379380
(modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0))
380-
self.assertEqual(frame4.positions, (39, 39, 8, 27))
381+
self.assertEqual(frame4.positions, dis.Positions(39, 39, 8, 27))
381382
# Test named tuple fields
382383
record = mod.st[0]
383384
self.assertIs(record.frame, mod.fr)
@@ -392,13 +393,13 @@ def test_trace(self):
392393
frame1, frame2, frame3, = git.tr
393394
self.assertEqual(revise(*frame1[1:]),
394395
(modfile, 43, 'argue', [' spam(a, b, c)\n'], 0))
395-
self.assertEqual(frame1.positions, (43, 43, 12, 25))
396+
self.assertEqual(frame1.positions, dis.Positions(43, 43, 12, 25))
396397
self.assertEqual(revise(*frame2[1:]),
397398
(modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0))
398-
self.assertEqual(frame2.positions, (9, 9, 4, 22))
399+
self.assertEqual(frame2.positions, dis.Positions(9, 9, 4, 22))
399400
self.assertEqual(revise(*frame3[1:]),
400401
(modfile, 18, 'eggs', [' q = y / 0\n'], 0))
401-
self.assertEqual(frame3.positions, (18, 18, 8, 13))
402+
self.assertEqual(frame3.positions, dis.Positions(18, 18, 8, 13))
402403

403404
def test_frame(self):
404405
args, varargs, varkw, locals = inspect.getargvalues(mod.fr)

0 commit comments

Comments
 (0)