MCPcopy Create free account
hub / github.com/scottrogowski/code2flow / make_local_variables

Function make_local_variables

code2flow/python.py:107–129  ·  view source on GitHub ↗

Given an ast of all the lines in a function, generate a list of variables in that function. Variables are tokens and what they link to. In this case, what it links to is just a string. However, that is resolved later. :param lines list[ast]: :param parent Group: :rtype:

(lines, parent)

Source from the content-addressed store, hash-verified

105
106
107def make_local_variables(lines, parent):
108 """
109 Given an ast of all the lines in a function, generate a list of
110 variables in that function. Variables are tokens and what they link to.
111 In this case, what it links to is just a string. However, that is resolved
112 later.
113
114 :param lines list[ast]:
115 :param parent Group:
116 :rtype: list[Variable]
117 """
118 variables = []
119 for tree in lines:
120 for element in ast.walk(tree):
121 if type(element) == ast.Assign:
122 variables += process_assign(element)
123 if type(element) in (ast.Import, ast.ImportFrom):
124 variables += process_import(element)
125 if parent.group_type == GROUP_TYPE.CLASS:
126 variables.append(Variable('self', parent, lines[0].lineno))
127
128 variables = list(filter(None, variables))
129 return variables
130
131
132def get_inherits(tree):

Callers 2

make_nodesMethod · 0.70
make_root_nodeMethod · 0.70

Calls 3

process_importFunction · 0.85
VariableClass · 0.85
process_assignFunction · 0.70

Tested by

no test coverage detected