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

Method separate_namespaces

code2flow/python.py:165–191  ·  view source on GitHub ↗

Given an AST, recursively separate that AST into lists of ASTs for the subgroups, nodes, and body. This is an intermediate step to allow for cleaner processing downstream :param tree ast: :returns: tuple of group, node, and body trees. These are processed

(tree)

Source from the content-addressed store, hash-verified

163
164 @staticmethod
165 def separate_namespaces(tree):
166 """
167 Given an AST, recursively separate that AST into lists of ASTs for the
168 subgroups, nodes, and body. This is an intermediate step to allow for
169 cleaner processing downstream
170
171 :param tree ast:
172 :returns: tuple of group, node, and body trees. These are processed
173 downstream into real Groups and Nodes.
174 :rtype: (list[ast], list[ast], list[ast])
175 """
176 groups = []
177 nodes = []
178 body = []
179 for el in tree.body:
180 if type(el) in (ast.FunctionDef, ast.AsyncFunctionDef):
181 nodes.append(el)
182 elif type(el) == ast.ClassDef:
183 groups.append(el)
184 elif getattr(el, 'body', None):
185 tup = Python.separate_namespaces(el)
186 groups += tup[0]
187 nodes += tup[1]
188 body += tup[2]
189 else:
190 body.append(el)
191 return groups, nodes, body
192
193 @staticmethod
194 def make_nodes(tree, parent):

Callers 1

make_class_groupMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected