Skip to content

Commit 4ea7490

Browse files
donBarboslkollar
authored andcommitted
pythongh-136438: Make sure test_compile pass with all optimization levels (pythonGH-136478)
1 parent 5f6f659 commit 4ea7490

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Lib/test/test_compile.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,10 @@ def f():
823823
else:
824824
return "unused"
825825

826-
self.assertEqual(f.__code__.co_consts,
827-
(f.__doc__, "used"))
826+
if f.__doc__ is None:
827+
self.assertEqual(f.__code__.co_consts, (True, "used"))
828+
else:
829+
self.assertEqual(f.__code__.co_consts, (f.__doc__, "used"))
828830

829831
@support.cpython_only
830832
def test_remove_unused_consts_no_docstring(self):
@@ -869,7 +871,11 @@ def test_strip_unused_None(self):
869871
def f1():
870872
"docstring"
871873
return 42
872-
self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
874+
875+
if f1.__doc__ is None:
876+
self.assertEqual(f1.__code__.co_consts, (42,))
877+
else:
878+
self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
873879

874880
# This is a regression test for a CPython specific peephole optimizer
875881
# implementation bug present in a few releases. It's assertion verifies

0 commit comments

Comments
 (0)