jendrikseipp / vulture

Find dead Python code
MIT License
3.54k stars 157 forks source link

RecursionError: maximum recursion depth exceeded #358

Open ericwb opened 6 months ago

ericwb commented 6 months ago

I tested out vulture on a project I maintain (Bandit). Unfortunately, the first result I got was a RecursionError. It's not clear to me if this is by-design or an edge case bug. Bandit itself does static analysis using an AST and vulture seems to trip up when inspecting the visitor logic.

To reproduce:

pip install vulture
git clone https://github.com/PyCQA/bandit
cd bandit
vulture .
  File "/Users/ericwb/workspace/reflex-web/venv/lib/python3.12/site-packages/vulture/core.py", line 721, in generic_visit
    self.visit(value)
  File "/Users/ericwb/workspace/reflex-web/venv/lib/python3.12/site-packages/vulture/core.py", line 687, in visit
    return self.generic_visit(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ericwb/workspace/reflex-web/venv/lib/python3.12/site-packages/vulture/core.py", line 721, in generic_visit
    self.visit(value)
  File "/Users/ericwb/workspace/reflex-web/venv/lib/python3.12/site-packages/vulture/core.py", line 672, in visit
    visitor(node)
  File "/Users/ericwb/workspace/reflex-web/venv/lib/python3.12/site-packages/vulture/core.py", line 521, in visit_BinOp
    utils.is_ast_string(node.left)
RecursionError: maximum recursion depth exceeded
jendrikseipp commented 6 months ago

Thanks for the report! This is definitely not by design. Happy to review a PR if you take the time to tackle this.

ericwb commented 6 months ago

Looks like this isn't occurring on Bandit source code, but one of its dependencies in the .tox directory.

Narrowing it down some, it occurs here: vulture .tox/py312/lib/python3.12/site-packages/astroid

ericwb commented 6 months ago

More specifically, it's this file: vulture bandit/.tox/py312/lib/python3.12/site-packages/astroid/tests/testdata/python3/data/joined_strings.py

ericwb commented 6 months ago

Here's a reference issue in astroid. So this might be an extreme edge case that doesn't need fixing. However, it would be nice if the RecursionError was caught and handled gracefully in vulture.

https://github.com/pylint-dev/astroid/issues/557

jendrikseipp commented 6 months ago

Thanks for looking into this! Can you make a pull request along those lines?