Skip to content

Commit 7b25a82

Browse files
Fix test_compile with -O mode (GH-115346)
1 parent ecf16ee commit 7b25a82

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Lib/test/test_compile.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def f():
749749
return "unused"
750750

751751
self.assertEqual(f.__code__.co_consts,
752-
("docstring", "used"))
752+
(f.__doc__, "used"))
753753

754754
@support.cpython_only
755755
def test_remove_unused_consts_no_docstring(self):
@@ -794,7 +794,7 @@ def test_strip_unused_None(self):
794794
def f1():
795795
"docstring"
796796
return 42
797-
self.assertEqual(f1.__code__.co_consts, ("docstring", 42))
797+
self.assertEqual(f1.__code__.co_consts, (f1.__doc__, 42))
798798

799799
# This is a regression test for a CPython specific peephole optimizer
800800
# implementation bug present in a few releases. It's assertion verifies
@@ -1047,6 +1047,8 @@ def no_code2():
10471047

10481048
for func in (no_code1, no_code2):
10491049
with self.subTest(func=func):
1050+
if func is no_code1 and no_code1.__doc__ is None:
1051+
continue
10501052
code = func.__code__
10511053
[(start, end, line)] = code.co_lines()
10521054
self.assertEqual(start, 0)
@@ -1524,6 +1526,7 @@ def test_multiline_boolean_expression(self):
15241526
self.assertOpcodeSourcePositionIs(compiled_code, 'POP_JUMP_IF_TRUE',
15251527
line=4, end_line=4, column=8, end_column=13, occurrence=2)
15261528

1529+
@unittest.skipIf(sys.flags.optimize, "Assertions are disabled in optimized mode")
15271530
def test_multiline_assert(self):
15281531
snippet = textwrap.dedent("""\
15291532
assert (a > 0 and

0 commit comments

Comments
 (0)