Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-136438: Make sure test_dis pass with all optimization levels #136593

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 2 commits into
base: main
Choose a base branch
from

Conversation

efimov-mikhail
Copy link
Contributor

@efimov-mikhail efimov-mikhail commented Jul 12, 2025

Now tests pass with all combinations of -OO and --without-doc-strings.

Before:

======================================================================
FAIL: test_info (test.test_dis.BytecodeTests.test_info)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 2324, in test_info
    self.assertRegex(b.info(), expected)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
AssertionError: Regex didn't match: 'Name:              code_info\nFilename:          (.*)\nArgument count:    1\nPositional-only arguments: 0\nKw-only arguments: 0\nNumber of locals:  1\nStack size:        \\d+\nFlags:             OPTIMIZED, NEWLOCALS, HAS_DOCSTRING\nConstants:\n   0: None\nNames:\n   0: _format_code_info\n   1: _get_code_object\nVariable names:\n   0: x' not found in 'Name:              code_info\nFilename:          /home/sikko/projects/cpython/Lib/dis.py\nArgument count:    1\nPositional-only arguments: 0\nKw-only arguments: 0\nNumber of locals:  1\nStack size:        5\nFlags:             OPTIMIZED, NEWLOCALS\nConstants:\n   0: None\nNames:\n   0: _format_code_info\n   1: _get_code_object\nVariable names:\n   0: x'

======================================================================
FAIL: test_code_info (test.test_dis.CodeInfoTests.test_code_info)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 1625, in test_code_info
    self.assertRegex(dis.code_info(x), expected)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Regex didn't match: 'Name:              code_info\nFilename:          (.*)\nArgument count:    1\nPositional-only arguments: 0\nKw-only arguments: 0\nNumber of locals:  1\nStack size:        \\d+\nFlags:             OPTIMIZED, NEWLOCALS, HAS_DOCSTRING\nConstants:\n   0: None\nNames:\n   0: _format_code_info\n   1: _get_code_object\nVariable names:\n   0: x' not found in 'Name:              code_info\nFilename:          /home/sikko/projects/cpython/Lib/dis.py\nArgument count:    1\nPositional-only arguments: 0\nKw-only arguments: 0\nNumber of locals:  1\nStack size:        5\nFlags:             OPTIMIZED, NEWLOCALS\nConstants:\n   0: None\nNames:\n   0: _format_code_info\n   1: _get_code_object\nVariable names:\n   0: x'

======================================================================
FAIL: test_show_code (test.test_dis.CodeInfoTests.test_show_code)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 1632, in test_show_code
    self.assertRegex(output.getvalue(), expected+"\n")
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Regex didn't match: 'Name:              code_info\nFilename:          (.*)\nArgument count:    1\nPositional-only arguments: 0\nKw-only arguments: 0\nNumber of locals:  1\nStack size:        \\d+\nFlags:             OPTIMIZED, NEWLOCALS, HAS_DOCSTRING\nConstants:\n   0: None\nNames:\n   0: _format_code_info\n   1: _get_code_object\nVariable names:\n   0: x\n' not found in 'Name:              code_info\nFilename:          /home/sikko/projects/cpython/Lib/dis.py\nArgument count:    1\nPositional-only arguments: 0\nKw-only arguments: 0\nNumber of locals:  1\nStack size:        5\nFlags:             OPTIMIZED, NEWLOCALS\nConstants:\n   0: None\nNames:\n   0: _format_code_info\n   1: _get_code_object\nVariable names:\n   0: x\n'

======================================================================
FAIL: test_disassemble_recursive (test.test_dis.DisTests.test_disassemble_recursive)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 1258, in test_disassemble_recursive
    check(dis_nested_1, depth=1)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 1255, in check
    self.assertEqual(dis, expected)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
AssertionError: '  --[965 chars]     0 (<code object <genexpr> at 0x..., file [306 chars]UE\n' != '  --[965 chars]     1 (<code object <genexpr> at 0x..., file [306 chars]UE\n'
    --           MAKE_CELL                0 (y)
  
   794           RESUME                   0
  
   795           LOAD_FAST_BORROW         0 (y)
                 BUILD_TUPLE              1
                 LOAD_CONST               0 (<code object foo at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 795>)
                 MAKE_FUNCTION
                 SET_FUNCTION_ATTRIBUTE   8 (closure)
                 STORE_FAST               1 (foo)
  
   798           LOAD_FAST_BORROW         1 (foo)
                 RETURN_VALUE
  
  Disassembly of <code object foo at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 795>:
    --           COPY_FREE_VARS           1
                 MAKE_CELL                0 (x)
  
   795           RESUME                   0
  
   797           LOAD_GLOBAL              1 (list + NULL)
                 LOAD_FAST_BORROW         0 (x)
                 BUILD_TUPLE              1
-                LOAD_CONST               0 (<code object <genexpr> at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 797>)
?                                         ^
+                LOAD_CONST               1 (<code object <genexpr> at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 797>)
?                                         ^
                 MAKE_FUNCTION
                 SET_FUNCTION_ATTRIBUTE   8 (closure)
                 LOAD_DEREF               1 (y)
                 CALL                     0
                 CALL                     1
                 RETURN_VALUE


======================================================================
FAIL: test_disassemble_recursive (test.test_dis.DisWithFileTests.test_disassemble_recursive)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 1258, in test_disassemble_recursive
    check(dis_nested_1, depth=1)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 1255, in check
    self.assertEqual(dis, expected)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
AssertionError: '  --[965 chars]     0 (<code object <genexpr> at 0x..., file [306 chars]UE\n' != '  --[965 chars]     1 (<code object <genexpr> at 0x..., file [306 chars]UE\n'
    --           MAKE_CELL                0 (y)
  
   794           RESUME                   0
  
   795           LOAD_FAST_BORROW         0 (y)
                 BUILD_TUPLE              1
                 LOAD_CONST               0 (<code object foo at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 795>)
                 MAKE_FUNCTION
                 SET_FUNCTION_ATTRIBUTE   8 (closure)
                 STORE_FAST               1 (foo)
  
   798           LOAD_FAST_BORROW         1 (foo)
                 RETURN_VALUE
  
  Disassembly of <code object foo at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 795>:
    --           COPY_FREE_VARS           1
                 MAKE_CELL                0 (x)
  
   795           RESUME                   0
  
   797           LOAD_GLOBAL              1 (list + NULL)
                 LOAD_FAST_BORROW         0 (x)
                 BUILD_TUPLE              1
-                LOAD_CONST               0 (<code object <genexpr> at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 797>)
?                                         ^
+                LOAD_CONST               1 (<code object <genexpr> at 0x..., file "/home/sikko/projects/cpython/Lib/test/test_dis.py", line 797>)
?                                         ^
                 MAKE_FUNCTION
                 SET_FUNCTION_ATTRIBUTE   8 (closure)
                 LOAD_DEREF               1 (y)
                 CALL                     0
                 CALL                     1
                 RETURN_VALUE

@bedevere-app bedevere-app bot mentioned this pull request Jul 12, 2025
8 tasks
@bedevere-app bedevere-app bot added the tests Tests in the Lib/test dir label Jul 12, 2025
@StanFromIreland StanFromIreland requested a review from sobolevn July 12, 2025 16:58
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.

2 participants