You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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?
The text was updated successfully, but these errors were encountered: