8000 GH-94036: Fix more attribute location quirks by brandtbucher · Pull Request #95028 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-94036: Fix more attribute location quirks #95028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add failing regression tests
  • Loading branch information
brandtbucher committed Jul 19, 2022
commit fa14e703d767892984dc6ff91872e165c2e1c642
61 changes: 60 additions & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,65 @@ def test_multiline_assert_rewritten_as_method_call(self):
tree.body[0] = new_node
compile(tree, "<test>", "exec")

def test_attribute_augassign(self):
source = "(\n lhs \n . \n rhs \n ) += 42"
code = compile(source, "<test>", "exec")
self.assertOpcodeSourcePositionIs(
code, "LOAD_ATTR", line=4, end_line=4, column=5, end_column=8
)
self.assertOpcodeSourcePositionIs(
code, "STORE_ATTR", line=4, end_line=4, column=5, end_column=8
)

def test_attribute_del(self):
source = "del (\n lhs \n . \n rhs \n )"
code = compile(source, "<test>", "exec")
self.assertOpcodeSourcePositionIs(
code, "DELETE_ATTR", line=4, end_line=4, column=5, end_column=8
)

def test_attribute_load(self):
source = "(\n lhs \n . \n rhs \n )"
code = compile(source, "<test>", "exec")
self.assertOpcodeSourcePositionIs(
code, "LOAD_ATTR", line=4, end_line=4, column=5, end_column=8
)

def test_attribute_store(self):
source = "(\n lhs \n . \n rhs \n ) = 42"
code = compile(source, "<test>", "exec")
self.assertOpcodeSourcePositionIs(
code, "STORE_ATTR", line=4, end_line=4, column=5, end_column=8
)

def test_method_call(self):
source = "(\n lhs \n . \n rhs \n )()"
code = compile(source, "<test>", "exec")
self.assertOpcodeSourcePositionIs(
code, "LOAD_ATTR", line=4, end_line=4, column=5, end_column=8
)
self.assertOpcodeSourcePositionIs(
code, "CALL", line=4, end_line=5, column=5, end_column=10
)

def test_weird_attribute_position_regressions(self):
def f():
(bar.
baz)
(bar.
baz(
))
files().setdefault(
0
).setdefault(
0
)
for line, end_line, column, end_column in f.__code__.co_positions():
self.assertIsNotNone(line)
self.assertIsNotNone(end_line)
self.assertIsNotNone(column)
self.assertIsNotNone(end_column)
self.assertLessEqual((line, column), (end_line, end_column))

class TestExpressionStackSize(unittest.TestCase):
# These tests check that the computed stack size for a code object
Expand All @@ -1210,7 +1269,7 @@ class TestExpressionStackSize(unittest.TestCase):
N = 100

def check_stack_size(self, code):
# To assert that the alleged stack size is not O(N), we
# To assert that the alleged stack size is not O(N), wevvvvvvvvvvvvvvvv
# check that it is smaller than log(N).
if isinstance(code, str):
code = compile(code, "<foo>", "single")
Expand Down
0