Skip to content

coverage html crashes with RecursionError in ast traversal #1774

Closed
@oscarbenjamin

Description

@oscarbenjamin

Describe the bug

Running coverage html crashes with RecursionError in ast traversal when trying to measure coverage of SymPy's sympy.polys module.

To Reproduce

Tested in a fresh venv with Python 3.8, 3.11 and 3.12 using coverage 7.5.0. It seems to be a new problem in coverage 7.5.0 because I can't reproduce it with e.g. coverage 7.4.4.

To reproduce run:

pip install pytest coverage==7.5.0 pytest-cov hypothesis sympy==1.12
pytest --cov=sympy.polys --pyargs sympy.polys.tests.test_densetools
coverage html

Then coverage html crashes out with:

$ coverage html
Traceback (most recent call last):
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/bin/coverage", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/cmdline.py", line 970, in main
    status = CoverageScript().command_line(argv)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/cmdline.py", line 720, in command_line
    total = self.coverage.html_report(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/control.py", line 1171, in html_report
    ret = reporter.report(morfs)
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/html.py", line 335, in report
    self.write_html_page(ftr)
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/html.py", line 419, in write_html_page
    file_data = self.datagen.data_for_file(ftr.fr, ftr.analysis)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/html.py", line 138, in data_for_file
    for lineno, tokens in enumerate(fr.source_token_lines(), start=1):
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/phystokens.py", line 127, in source_token_lines
    soft_key_lines = SoftKeywordFinder(source).soft_key_lines
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/oscar/current/active/sympy/tmp/tmp2/venv/lib/python3.12/site-packages/coverage/phystokens.py", line 86, in __init__
    self.visit(ast.parse(source))
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 417, in generic_visit
    self.visit(value)
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 415, in generic_visit
    self.visit(item)
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
...
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 417, in generic_visit
    self.visit(value)
  File "/home/oscar/.pyenv/versions/3.12.0/lib/python3.12/ast.py", line 407, in visit
    return visitor(node)
           ^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded

Expected behavior

Should produce coverage html report.

Additional context

There are other ways to reproduce this e.g. in a sympy git checkout:

pytest --cov=sympy.polys --cov-report=html sympy/polys

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfixed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions