Skip to content
Closed
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
Prev Previous commit
Next Next commit
Add a few tests
  • Loading branch information
Eclips4 committed Feb 22, 2025
commit 5aec965a9ea1721cb7decd8caa91e1d8e20c2e89
22 changes: 22 additions & 0 deletions Lib/test/test_peepholer.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,28 @@ def negzero():
self.assertInBytecode(code, opname)
self.check_lnotab(code)

def test_folding_of_tuples_on_constants(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def test_folding_of_tuples_on_constants(self):
def test_folding_of_tuples_of_constants(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And we actually, already have test_folding_of_tuples_of_constants, maybe we could add more to those instead?

tests =[
('()', True, 0),
('(1, 2, 3)', True, 3),
('("a", "b", "c")', True, 3),
('(1, a)', False, 2),
('(a, b, c)', False, 3),
('(1, (2, 3))', True, 2),
('(a, (b, c))', False, 2),
('(1, [], {})', False, 3),
(repr(tuple(range(30))), True, 30),
('(1, (2, (3, (4, (5)))))', True, 2)
]
for expr, is_const, length in tests:
with self.subTest(expr=expr, is_const=is_const, length=length):
code = compile(expr, '', 'eval')
if is_const:
self.assertNotInBytecode(code, 'BUILD_TUPLE', length)
self.assertInBytecode(code, 'LOAD_CONST', eval(expr))
else:
self.assertInBytecode(code, 'BUILD_TUPLE', length)

def test_elim_extra_return(self):
# RETURN LOAD_CONST None RETURN --> RETURN
def f(x):
Expand Down