PyCQA / PyCQA/mccabe

RecursionError on long elif

Open
#71 0 comments 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.