Skip to content

Commit e14cb29

Browse files
committed
fix test
1 parent eca9248 commit e14cb29

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

Lib/test/test_dis.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,28 +1141,25 @@ def test_annotate_source_locations(self):
11411141

11421142
for case_name, annotate_code in test_cases:
11431143
with self.subTest(case=case_name):
1144-
instructions = list(dis.Bytecode(annotate_code))
1145-
resume_pos = next(
1146-
(
1147-
inst.positions
1148-
for inst in instructions
1149-
if inst.opname == "RESUME"
1150-
),
1151-
None,
1144+
line_starts_iterator = dis.findlinestarts(annotate_code)
1145+
valid_line_starts = [
1146+
item[0]
1147+
for item in line_starts_iterator
1148+
if item[1] is not None
1149+
] # The first item is not RESUME in class case
1150+
setup_scope_begin = valid_line_starts[0]
1151+
setup_scope_end = valid_line_starts[1]
1152+
setup_annotations_scope_positions = {
1153+
instr.positions
1154+
for instr in dis.get_instructions(annotate_code)
1155+
if setup_scope_begin <= instr.offset < setup_scope_end
1156+
and instr.positions
1157+
}
1158+
self.assertEqual(
1159+
len(setup_annotations_scope_positions),
1160+
1,
1161+
f"{case_name}: Expected uniform positions, found {len(setup_annotations_scope_positions)}: {setup_annotations_scope_positions}",
11521162
)
1153-
for instruction in instructions:
1154-
if instruction.opname == "BUILD_MAP":
1155-
break
1156-
if (
1157-
instruction.opname != "RESUME"
1158-
and instruction.positions
1159-
and instruction.positions.lineno
1160-
):
1161-
self.assertEqual(
1162-
instruction.positions,
1163-
resume_pos,
1164-
f"{case_name}: Unexpected position {instruction.positions} in {instruction.opname}, expected {resume_pos}",
1165-
)
11661163

11671164
def test_kw_names(self):
11681165
# Test that value is displayed for keyword argument names:

0 commit comments

Comments
 (0)