MCPcopy
hub / github.com/rocky/python-uncompyle6 / maybe_show_tree

Function maybe_show_tree

uncompyle6/show.py:35–58  ·  view source on GitHub ↗

Show the ast based on the showast flag (or file object), writing to the appropriate stream depending on the type of the flag. :param show_tree: Flag which determines whether the parse tree is written to sys.stdout or not. (It is also to pass a file

(walker, ast)

Source from the content-addressed store, hash-verified

33
34
35def maybe_show_tree(walker, ast):
36 """
37 Show the ast based on the showast flag (or file object), writing to the
38 appropriate stream depending on the type of the flag.
39
40 :param show_tree: Flag which determines whether the parse tree is
41 written to sys.stdout or not. (It is also to pass a file
42 like object, into which the ast will be written).
43 :param ast: The ast to show.
44 """
45 if walker.showast:
46 if hasattr(walker.showast, "write"):
47 stream = walker.showast
48 else:
49 stream = sys.stdout
50 if (
51 isinstance(walker.showast, dict)
52 and walker.showast.get("after", False)
53 and hasattr(walker, "str_with_template")
54 ):
55 walker.str_with_template(ast)
56 else:
57 stream.write(str(ast))
58 stream.write("\n")
59
60
61def maybe_show_tree_param_default(show_tree, name, default):

Callers 3

maybe_show_treeMethod · 0.90
build_astMethod · 0.90
maybe_show_treeMethod · 0.90

Calls 3

str_with_templateMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected