Return the Python objects represented by given AST. Compiling the AST code this way ensures that the source code is readable by e.g. `pdb` or `inspect`. Args: nodes: Union[ast.AST, Iterable[ast.AST]], the code to compile, as an AST object. indentation: Text, the string to use
(nodes,
indentation=' ',
include_source_map=False,
delete_on_exit=True)
| 106 | |
| 107 | # TODO(mdan): Rename: ast_to_entity |
| 108 | def ast_to_object(nodes, |
| 109 | indentation=' ', |
| 110 | include_source_map=False, |
| 111 | delete_on_exit=True): |
| 112 | """Return the Python objects represented by given AST. |
| 113 | |
| 114 | Compiling the AST code this way ensures that the source code is readable by |
| 115 | e.g. `pdb` or `inspect`. |
| 116 | |
| 117 | Args: |
| 118 | nodes: Union[ast.AST, Iterable[ast.AST]], the code to compile, as an AST |
| 119 | object. |
| 120 | indentation: Text, the string to use for indentation. |
| 121 | include_source_map: bool, whether return a source map. |
| 122 | delete_on_exit: bool, whether to delete the temporary file used for |
| 123 | compilation on exit. |
| 124 | |
| 125 | Returns: |
| 126 | Tuple[module, Text, Dict[LineLocation, OriginInfo]], containing: |
| 127 | the module containing the unparsed nodes, the source code corresponding to |
| 128 | nodes, and the source map. Is include_source_map is False, the source map |
| 129 | will be None. |
| 130 | """ |
| 131 | if not isinstance(nodes, (list, tuple)): |
| 132 | nodes = (nodes,) |
| 133 | |
| 134 | source = ast_to_source(nodes, indentation=indentation) |
| 135 | module, _ = source_to_entity(source, delete_on_exit) |
| 136 | |
| 137 | if include_source_map: |
| 138 | source_map = origin_info.create_source_map(nodes, source, module.__file__) |
| 139 | else: |
| 140 | source_map = None |
| 141 | |
| 142 | # TODO(mdan): Return a structured object. |
| 143 | return module, source, source_map |
nothing calls this directly
no test coverage detected