RecursionError on long elif
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 681
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
Given
def func(x):
if x == "a":
return "a"
elif x == "a":
return "a"
elif x == "a":
return "a"
elif x == "a":
return "a"
elif x == "a": # repeat elif/return 160 times total
return "a"
We get the error when running flake8 on it:
ERROR:1:1: X002 File "flake8/main/cli.py", line 16, in main
ERROR:1:1: X002 File "flake8/main/application.py", line 412, in run
ERROR:1:1: X002 File "flake8/main/application.py", line 400, in _run
ERROR:1:1: X002 File "flake8/main/application.py", line 318, in run_checks
ERROR:1:1: X002 File "flake8/checker.py", line 340, in run
ERROR:1:1: X002 File "flake8/checker.py", line 324, in run_serial
ERROR:1:1: X002 File "flake8/checker.py", line 612, in run_checks
ERROR:1:1: X002 File "flake8/checker.py", line 520, in run_ast_checks
ERROR:1:1: X002 File "mccabe.py", line 266, in run
ERROR:1:1: X002 File "mccabe.py", line 47, in preorder
ERROR:1:1: X002 File "mccabe.py", line 41, in dispatch
ERROR:1:1: X002 File "mccabe.py", line 167, in default
ERROR:1:1: X002 File "mccabe.py", line 31, in default
ERROR:1:1: X002 File "mccabe.py", line 41, in dispatch
ERROR:1:1: X002 File "mccabe.py", line 135, in visitFunctionDef
ERROR:1:1: X002 File "mccabe.py", line 111, in dispatch_list
ERROR:1:1: X002 File "mccabe.py", line 41, in dispatch
ERROR:1:1: X002 File "mccabe.py", line 177, in visitIf
ERROR:1:1: X002 File "mccabe.py", line 190, in _subgraph
ERROR:1:1: X002 File "mccabe.py", line 204, in _subgraph_parse
ERROR:1:1: X002 File "mccabe.py", line 111, in dispatch_list
...
ERROR:1:1: X002 File "mccabe.py", line 177, in visitIf
ERROR:1:1: X002 File "mccabe.py", line 190, in _subgraph
ERROR:1:1: X002 File "mccabe.py", line 204, in _subgraph_parse
ERROR:1:1: X002 File "mccabe.py", line 111, in dispatch_list
ERROR:1:1: X002 File "mccabe.py", line 41, in dispatch
ERROR:1:1: X002 File "mccabe.py", line 177, in visitIf
ERROR:1:1: X002 File "mccabe.py", line 190, in _subgraph
ERROR:1:1: X002 File "mccabe.py", line 204, in _subgraph_parse
ERROR:1:1: X002 File "mccabe.py", line 111, in dispatch_list
ERROR:1:1: X002 File "mccabe.py", line 41, in dispatch
ERROR:1:1: X002 File "mccabe.py", line 177, in visitIf
ERROR:1:1: X002 File "mccabe.py", line 190, in _subgraph
ERROR:1:1: X002 File "mccabe.py", line 196, in _subgraph_parse
ERROR:1:1: X002 File "mccabe.py", line 111, in dispatch_list
ERROR:1:1: X002 File "mccabe.py", line 41, in dispatch
ERROR:1:1: X002 RecursionError: maximum recursion depth exceeded
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the long elif example and inspect the traversal in mccabe.py, especially the functions named in the traceback such as visitIf and _subgraph_parse. Done means flake8 can process the example without RecursionError while preserving its complexity analysis.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100