[3.11] GH-93662: Make sure that column offsets are correct in multi-line method calls. (GH-93673) (#93895)

Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
Irit Katriel 2022-06-16 11:56:35 +01:00 committed by GitHub
parent 6e28032662
commit df091e14d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 5 deletions

View file

@ -574,6 +574,15 @@ def positions_from_location_table(code):
for _ in range(length):
yield (line, end_line, col, end_col)
def dedup(lst, prev=object()):
for item in lst:
if item != prev:
yield item
prev = item
def lines_from_postions(positions):
return dedup(l for (l, _, _, _) in positions)
def misshappen():
"""
@ -606,6 +615,13 @@ def misshappen():
) else p
def bug93662():
example_report_generation_message= (
"""
"""
).strip()
raise ValueError()
class CodeLocationTest(unittest.TestCase):
@ -616,10 +632,23 @@ class CodeLocationTest(unittest.TestCase):
self.assertEqual(l1, l2)
self.assertEqual(len(pos1), len(pos2))
def test_positions(self):
self.check_positions(parse_location_table)
self.check_positions(misshappen)
self.check_positions(bug93662)
def check_lines(self, func):
co = func.__code__
lines1 = list(dedup(l for (_, _, l) in co.co_lines()))
lines2 = list(lines_from_postions(positions_from_location_table(co)))
for l1, l2 in zip(lines1, lines2):
self.assertEqual(l1, l2)
self.assertEqual(len(lines1), len(lines2))
def test_lines(self):
self.check_lines(parse_location_table)
self.check_lines(misshappen)
self.check_lines(bug93662)
if check_impl_detail(cpython=True) and ctypes is not None: