@@ -1641,7 +1641,7 @@ def getclosurevars(func):
1641
1641
_Traceback = namedtuple ('_Traceback' , 'filename lineno function code_context index' )
1642
1642
1643
1643
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 ):
1645
1645
instance = super ().__new__ (cls , filename , lineno , function , code_context , index )
1646
1646
instance .positions = positions
1647
1647
return instance
@@ -1660,6 +1660,7 @@ def _get_code_position(code, instruction_index):
1660
1660
if instruction_index < 0 :
1661
1661
return (None , None , None , None )
1662
1662
positions_gen = code .co_positions ()
1663
+ # The nth entry in code.co_positions() corresponds to instruction (2*n)th since Python 3.10+
1663
1664
return next (itertools .islice (positions_gen , instruction_index // 2 , None ))
1664
1665
1665
1666
def getframeinfo (frame , context = 1 ):
@@ -1683,7 +1684,7 @@ def getframeinfo(frame, context=1):
1683
1684
else :
1684
1685
frame , * positions = (frame , * positions )
1685
1686
1686
- lineno , * _ = positions
1687
+ lineno = positions [ 0 ]
1687
1688
1688
1689
if not isframe (frame ):
1689
1690
raise TypeError ('{!r} is not a frame or traceback object' .format (frame ))
@@ -1703,7 +1704,7 @@ def getframeinfo(frame, context=1):
1703
1704
lines = index = None
1704
1705
1705
1706
return Traceback (filename , lineno , frame .f_code .co_name , lines ,
1706
- index , dis .Positions (* positions ))
1707
+ index , positions = dis .Positions (* positions ))
1707
1708
1708
1709
def getlineno (frame ):
1709
1710
"""Get the line number from a frame object, allowing for optimization."""
0 commit comments