Skip to content
Merged
Next Next commit
add unit test for const trimming
  • Loading branch information
iritkatriel committed Sep 29, 2022
commit 27102b2de60a81fbdf4022976546f909ba628e4e
14 changes: 13 additions & 1 deletion Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,22 @@ def test_merge_code_attrs(self):

self.assertIs(f1.__code__.co_linetable, f2.__code__.co_linetable)

@support.cpython_only
def test_strip_unused_consts(self):
def f():
"docstring"
if True:
return "used"
else:
return "unused"

self.assertEqual(f.__code__.co_consts,
("docstring", True, "used"))

# Stripping unused constants is not a strict requirement for the
# Python semantics, it's a more an implementation detail.
@support.cpython_only
def test_strip_unused_consts(self):
def test_strip_unused_None(self):
# Python 3.10rc1 appended None to co_consts when None is not used
# at all. See bpo-45056.
def f1():
Expand Down