8000 fix test · python/cpython@aed06b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit aed06b7

Browse files
committed
fix test
1 parent 2201864 commit aed06b7

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

Lib/test/test_dis.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -431,18 +431,6 @@ def foo(a: int, b: str) -> str:
431431
RETURN_VALUE
432432
"""
433433

434-
issue_135700 = """\
435-
22
436-
333
437-
__dataclass_fields__: ClassVar
438-
"""
439-
440-
issue_135700_class = """\
441-
class _B:
442-
2
443-
c: int
444-
"""
445-
446434
compound_stmt_str = """\
447435
x = 0
448436
while 1:
@@ -1138,25 +1126,44 @@ def test_bug_46724(self):
11381126

11391127
def test_annotate_no_spurious_first_node_positions(self):
11401128
# Test that __annotate__ code doesn't inherit first AST node positions
1129+
issue_135700 = "1\nx: int"
1130+
issue_135700_class = "class A:\n 1\n x: int"
1131+
11411132
test_cases = [
11421133
("module", compile(issue_135700, "<string>", "exec").co_consts[1]),
1143-
("class", compile(ast.parse(issue_135700_class), "?", "exec").co_consts[0].co_consts[1])
1134+
(
1135+
"class",
1136+
compile(ast.parse(issue_135700_class), "?", "exec")
1137+
.co_consts[0]
1138+
.co_consts[1],
1139+
),
11441140
]
11451141

11461142
for case_name, annotate_code in test_cases:
11471143
with self.subTest(case=case_name):
11481144
instructions = list(dis.Bytecode(annotate_code))
1149-
1150-
spurious_positions = sum(
1151-
1 for instr in instructions
1152-
if (instr.positions and
1153-
instr.positions.lineno == 1 and
1154-
instr.positions.col_offset == 0 and
1155-
instr.positions.end_col_offset == 1)
1145+
print(instructions)
1146+
resume_pos = next(
1147+
(
1148+
inst.positions
1149+
for inst in instructions
1150+
if inst.opname == "RESUME"
1151+
),
1152+
None,
11561153
)
1157-
1158-
self.assertEqual(spurious_positions, 0,
1159-
f"No instructions in {case_name} __annotate__ should have first statement's position")
1154+
for instruction in instructions:
1155+
if instruction.opname == "BUILD_MAP":
1156+
break
1157+
if (
1158+
instruction.opname != "RESUME"
1159+
and instruction.positions
1160+
and instruction.positions.lineno
1161+
):
1162+
self.assertEqual(
1163+
instruction.positions,
1164+
resume_pos,
1165+
f"{case_name}: Unexpected position {instruction.positions} in {instruction.opname}, expected {resume_pos}",
1166+
)
11601167

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

0 commit comments

Comments
 (0)
0