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)
| 33 | |
| 34 | |
| 35 | def 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 | |
| 61 | def maybe_show_tree_param_default(show_tree, name, default): |
no test coverage detected