Skip to content

Feature: Utilize a control flow graph to detect unused code #385

@ericwb

Description

@ericwb

I want to suggest a different way of detecting dead code. While the AST is useful, I think it can result in a number of false positives.

If you take the AST parsed output and convert into a control flow graph (CFG), you get a directed graph of the code blocks. If a block of code exists with no edges, you know the code is dead and unused.

Unfortunately, converting AST to CFG is not easy, but there are some existing libraries that do it, although I don't think they are well maintained to current versions of Python. Also, to be most useful and accurate, the CFG needs to be generated for the entire code based being analyzed, not just a single file.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions