mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
GH-94694: Fix column offsets for multi-line method lookups (GH-94697)
This commit is contained in:
parent
a10cf2f6b3
commit
264b3ddfd5
4 changed files with 85 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue