We traced the code path by running the debugger on the source code.
Identified that Vulture generates an AST of the provided source code in the scan function in core.py
Each node in the AST is then visited by the visit function
The visit function decides what helper to use based on the type of node
For this issue, we specifically care about the visit_Call and visit_ClassDef functions because these are invoked when the list() function is called, and when a class is defined with the Enum subclass.
Based on these findings, here is a high level approach of the solution we will implement:
Extend the ast with scoping information using the asttokens package.
In visit_Call, check if the node.func.id=='list' - are we calling the list function?
If so, get the argument(node.args[0].id) and use the scoping information provided by asttokens to check if the argument is a class
If so, use the scope info about the class to check if Enum is a superclass.
If so, then add all the fields defined in the class to defined_variables
Debug output is attached below. See enum_scope.txt for more details.
Our progress thus far on issue #304
scan
function incore.py
visit
functionvisit
function decides what helper to use based on the type of nodevisit_Call
andvisit_ClassDef
functions because these are invoked when thelist()
function is called, and when a class is defined with theEnum
subclass.Based on these findings, here is a high level approach of the solution we will implement:
visit_Call
, check if thenode.func.id=='list'
- are we calling the list function?node.args[0].id
) and use the scoping information provided by asttokens to check if the argument is a classEnum
is a superclass.defined_variables
Debug output is attached below. See
enum_scope.txt
for more details.