GH-94694: Fix column offsets for multi-line method lookups (GH-94697)

This commit is contained in:
Brandt Bucher 2022-07-09 17:22:23 -07:00 committed by GitHub
parent a10cf2f6b3
commit 264b3ddfd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 2 deletions

View file

@ -1181,6 +1181,27 @@ f(
self.assertOpcodeSourcePositionIs(compiled_code, 'BINARY_OP',
line=1, end_line=1, column=0, end_column=27, occurrence=4)
def test_multiline_assert_rewritten_as_method_call(self):
# GH-94694: Don't crash if pytest rewrites a multiline assert as a
# method call with the same location information:
tree = ast.parse("assert (\n42\n)")
old_node = tree.body[0]
new_node = ast.Expr(
ast.Call(
ast.Attribute(
ast.Name("spam", ast.Load()),
"eggs",
ast.Load(),
),
[],
[],
)
)
ast.copy_location(new_node, old_node)
ast.fix_missing_locations(new_node)
tree.body[0] = new_node
compile(tree, "<test>", "exec")
class TestExpressionStackSize(unittest.TestCase):
# These tests check that the computed stack size for a code object