[New-bugs-announce] [issue42823] Incorrect frame.f_lineno when frame.f_trace is set

Mark Shannon report at bugs.python.org
Mon Jan 4 11:32:45 EST 2021


New submission from Mark Shannon <mark at hotpy.org>:

The logic for frame.f_lineno assumes that the internal C field will be updated when f_trace is set, but that is incorrect.
Consequently, the following code

import sys

def print_line():
    print(sys._getframe(1).f_lineno)

def test():
    print_line()
    sys._getframe(0).f_trace = True
    print_line()
    print_line()

test()

prints
7
8
8

it should print
7
9
10


Fixing this is required by PEP 626, but it should be fixed anyway.

----------
assignee: Mark.Shannon
messages: 384331
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: Incorrect frame.f_lineno when frame.f_trace is set

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42823>
_______________________________________


More information about the New-bugs-announce mailing list