mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-42823: Fix frame lineno when frame.f_trace is set (GH-24099)
* Add test for frame.f_lineno with/without tracing. * Make sure that frame.f_lineno is correct regardless of whether frame.f_trace is set. * Update importlib * Add NEWS
This commit is contained in:
parent
e40e2a2cc9
commit
ee9f98d9f4
8 changed files with 1182 additions and 1159 deletions
|
@ -1,4 +1,5 @@
|
|||
import re
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
import weakref
|
||||
|
@ -94,6 +95,26 @@ class ClearTest(unittest.TestCase):
|
|||
f.clear()
|
||||
self.assertTrue(endly)
|
||||
|
||||
def test_lineno_with_tracing(self):
|
||||
def record_line():
|
||||
f = sys._getframe(1)
|
||||
lines.append(f.f_lineno-f.f_code.co_firstlineno)
|
||||
|
||||
def test(trace):
|
||||
record_line()
|
||||
if trace:
|
||||
sys._getframe(0).f_trace = True
|
||||
record_line()
|
||||
record_line()
|
||||
|
||||
expected_lines = [1, 4, 5]
|
||||
lines = []
|
||||
test(False)
|
||||
self.assertEqual(lines, expected_lines)
|
||||
lines = []
|
||||
test(True)
|
||||
self.assertEqual(lines, expected_lines)
|
||||
|
||||
@support.cpython_only
|
||||
def test_clear_refcycles(self):
|
||||
# .clear() doesn't leave any refcycle behind
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue