mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
[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:
parent
6e28032662
commit
df091e14d8
3 changed files with 48 additions and 5 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue