Skip to content

Commit 7adb50d

Browse files
committed
fixup! Address feedback from review
1 parent b9fd5ee commit 7adb50d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Doc/library/inspect.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ is considered deprecated and may be removed in the future.
12001200
.. attribute:: positions
12011201

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

12061206
.. versionchanged:: 3.5
@@ -1237,8 +1237,10 @@ is considered deprecated and may be removed in the future.
12371237

12381238
.. attribute:: positions
12391239

1240-
A tuple containing the start line number, end line number, start column offset and end column
1241-
offset associated with the instruction being executed by the frame this traceback corresponds to.
1240+
A :class:`dis.Positions` object containing the start line number, end
1241+
line number, start column offset, and end column offset associated with
1242+
the instruction being executed by the frame this traceback corresponds
1243+
to.
12421244

12431245
.. note::
12441246

Lib/inspect.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ def getclosurevars(func):
16411641
_Traceback = namedtuple('_Traceback', 'filename lineno function code_context index')
16421642

16431643
class Traceback(_Traceback):
1644-
def __new__(cls, filename, lineno, function, code_context, index, positions=None):
1644+
def __new__(cls, filename, lineno, function, code_context, index, *, positions=None):
16451645
instance = super().__new__(cls, filename, lineno, function, code_context, index)
16461646
instance.positions = positions
16471647
return instance
@@ -1660,6 +1660,7 @@ def _get_code_position(code, instruction_index):
16601660
if instruction_index < 0:
16611661
return (None, None, None, None)
16621662
positions_gen = code.co_positions()
1663+
# The nth entry in code.co_positions() corresponds to instruction (2*n)th since Python 3.10+
16631664
return next(itertools.islice(positions_gen, instruction_index // 2, None))
16641665

16651666
def getframeinfo(frame, context=1):
@@ -1683,7 +1684,7 @@ def getframeinfo(frame, context=1):
16831684
else:
16841685
frame, *positions = (frame, *positions)
16851686

1686-
lineno, *_ = positions
1687+
lineno = positions[0]
16871688

16881689
if not isframe(frame):
16891690
raise TypeError('{!r} is not a frame or traceback object'.format(frame))
@@ -1703,7 +1704,7 @@ def getframeinfo(frame, context=1):
17031704
lines = index = None
17041705

17051706
return Traceback(filename, lineno, frame.f_code.co_name, lines,
1706-
index, dis.Positions(*positions))
1707+
index, positions=dis.Positions(*positions))
17071708

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

0 commit comments

Comments
 (0)