GH-100117: Make co_lines more efficient (GH-100447)

This commit is contained in:
Brandt Bucher 2023-01-10 02:56:53 -08:00 committed by GitHub
parent b2f7b2ef0b
commit f07daaf4f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 38 deletions

View file

@ -161,9 +161,8 @@ if 1:
s256 = "".join(["\n"] * 256 + ["spam"])
co = compile(s256, 'fn', 'exec')
self.assertEqual(co.co_firstlineno, 1)
lines = list(co.co_lines())
self.assertEqual(lines[0][2], 0)
self.assertEqual(lines[1][2], 257)
lines = [line for _, _, line in co.co_lines()]
self.assertEqual(lines, [0, 257])
def test_literals_with_leading_zeroes(self):
for arg in ["077787", "0xj", "0x.", "0e", "090000000000000",
@ -955,9 +954,9 @@ if 1:
for func in (no_code1, no_code2):
with self.subTest(func=func):
code = func.__code__
lines = list(code.co_lines())
start, end, line = lines[0]
[(start, end, line)] = code.co_lines()
self.assertEqual(start, 0)
self.assertEqual(end, len(code.co_code))
self.assertEqual(line, code.co_firstlineno)
def get_code_lines(self, code):