MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ast_to_object

Function ast_to_object

tensorflow/python/autograph/pyct/compiler.py:108–143  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

106
107# TODO(mdan): Rename: ast_to_entity
108def 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

Callers

nothing calls this directly

Calls 2

ast_to_sourceFunction · 0.85
source_to_entityFunction · 0.85

Tested by

no test coverage detected