Skip to content

gh-136438: Make sure test_compile pass with all optimization levels #136478

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

donBarbos
Copy link
Contributor

@donBarbos donBarbos commented Jul 9, 2025

output before:

======================================================================
ERROR: test_compile_ast (test.test_compile.TestSpecifics.test_compile_ast)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../cpython/Lib/test/test_compile.py", line 597, in test_compile_ast
    co2 = compile(ast, '%s3' % fname, 'exec')
ValueError: empty body on FunctionDef

======================================================================
FAIL: test_remove_unused_consts (test.test_compile.TestSpecifics.test_remove_unused_consts)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../cpython/Lib/test/test_compile.py", line 826, in test_remove_unused_consts
    self.assertEqual(f.__code__.co_consts,
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
                     (f.__doc__, "used"))
                     ^^^^^^^^^^^^^^^^^^^^
AssertionError: Tuples differ: (True, 'used') != (None, 'used')

First differing element 0:
True
None

- (True, 'used')
?  ^^^

+ (None, 'used')
?  ^^^


======================================================================
FAIL: test_strip_unused_None (test.test_compile.TestSpecifics.test_strip_unused_None)
----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../cpython/Lib/test/test_compile.py", line 872, in test_strip_unused_None
    self.assertEqual(f1.__code__.co_consts, (f1.__doc__,))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Tuples differ: (42,) != (None,)

First differing element 0:
42
None

- (42,)
+ (None,)

----------------------------------------------------------------------

@bedevere-app bedevere-app bot added awaiting review tests Tests in the Lib/test dir labels Jul 9, 2025
@bedevere-app bedevere-app bot mentioned this pull request Jul 9, 2025
8 tasks
@StanFromIreland StanFromIreland requested a review from sobolevn July 10, 2025 06:29
@aisk
Copy link
Member

aisk commented Aug 13, 2025

Hi, I found that the failed test test_compile_ast is caused when try to compile this function:

def no_code1():
"doc string"

It will failed because the doc string in function body is omitted by the -OO flag. But this is more like a bug, and have been fixed in current main branch (I didn't found which commit but I think it don't matters). So I think we can merge current main branch (click the 'Update branch' button in this page bellow), and revert the changes in test_compile_ast function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants