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:
Mark Shannon 2021-01-05 12:04:10 +00:00 committed by GitHub
parent e40e2a2cc9
commit ee9f98d9f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 1182 additions and 1159 deletions

View file

@ -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