Skip to content

Commit 937a3db

Browse files
committed
Add failing regression test
1 parent be862b4 commit 937a3db

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Lib/test/test_compile.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,26 @@ def test_complex_single_line_expression(self):
11811181
self.assertOpcodeSourcePositionIs(compiled_code, 'BINARY_OP',
11821182
line=1, end_line=1, column=0, end_column=27, occurrence=4)
11831183

1184+
def test_multiline_assert_rewritten_as_method_call(self):
1185+
# GH-94694
1186+
tree = ast.parse("assert (\n42\n)")
1187+
old_node = tree.body[0]
1188+
new_node = ast.Expr(
1189+
ast.Call(
1190+
ast.Attribute(
1191+
ast.Name("spam", ast.Load()),
1192+
"eggs",
1193+
ast.Load(),
1194+
),
1195+
[],
1196+
[],
1197+
)
1198+
)
1199+
ast.copy_location(new_node, old_node)
1200+
ast.fix_missing_locations(new_node)
1201+
tree.body[0] = new_node
1202+
compile(tree, "<test>", "exec")
1203+
11841204

11851205
class TestExpressionStackSize(unittest.TestCase):
11861206
# These tests check that the computed stack size for a code object

0 commit comments

Comments
 (0)