MCPcopy Index your code
hub / github.com/rocky/python-uncompyle6 / preorder

Method preorder

uncompyle6/semantics/transform.py:89–113  ·  view source on GitHub ↗

Walk the tree in roughly 'preorder' (a bit of a lie explained below). For each node with typestring name *name* if the node has a method called n_*name*, call that before walking children. In typical use a node with children can call "preorder" in any order i

(self, node=None)

Source from the content-addressed store, hash-verified

87 maybe_show_tree(self, tree)
88
89 def preorder(self, node=None):
90 """Walk the tree in roughly 'preorder' (a bit of a lie explained below).
91 For each node with typestring name *name* if the
92 node has a method called n_*name*, call that before walking
93 children.
94
95 In typical use a node with children can call "preorder" in any
96 order it wants which may skip children or order then in ways
97 other than first to last. In fact, this this happens. So in
98 this sense this function not strictly preorder.
99 """
100 if node is None:
101 node = self.ast
102
103 try:
104 name = "n_" + self.typestring(node)
105 if hasattr(self, name):
106 func = getattr(self, name)
107 node = func(node)
108 except GenericASTTraversalPruningException:
109 return
110
111 for i, kid in enumerate(node):
112 node[i] = self.preorder(kid)
113 return node
114
115 def n_mkfunc(self, node):
116 """If the function has a docstring (this is found in the code

Callers 1

traverseMethod · 0.95

Calls 1

funcFunction · 0.50

Tested by

no test coverage detected