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. :param tree_el ast: :param parent Group: :rtype: list[Variable]
(tree_el, parent)
| 165 | |
| 166 | |
| 167 | def make_local_variables(tree_el, parent): |
| 168 | """ |
| 169 | Given an ast of all the lines in a function, generate a list of |
| 170 | variables in that function. Variables are tokens and what they link to. |
| 171 | |
| 172 | :param tree_el ast: |
| 173 | :param parent Group: |
| 174 | :rtype: list[Variable] |
| 175 | """ |
| 176 | variables = [] |
| 177 | for el in walk(tree_el): |
| 178 | if el['nodeType'] == 'Expr_Assign': |
| 179 | variables.append(process_assign(el)) |
| 180 | if el['nodeType'] == 'Stmt_Use': |
| 181 | for use in el['uses']: |
| 182 | owner_token = djoin(use['name']['parts']) |
| 183 | token = use['alias']['name'] if use['alias'] else owner_token |
| 184 | variables.append(Variable(token, points_to=owner_token, |
| 185 | line_number=lineno(el))) |
| 186 | |
| 187 | # Make a 'this'/'self' variable for use anywhere we need it that points to the class |
| 188 | if isinstance(parent, Group) and parent.group_type in GROUP_TYPE.CLASS: |
| 189 | variables.append(Variable('this', parent, line_number=parent.line_number)) |
| 190 | variables.append(Variable('self', parent, line_number=parent.line_number)) |
| 191 | |
| 192 | return list(filter(None, variables)) |
| 193 | |
| 194 | |
| 195 | def get_inherits(tree): |
no test coverage detected