diff options
| author | Pablo Galindo <Pablogsal@gmail.com> | 2019-11-24 23:02:40 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-24 23:02:40 +0000 |
| commit | 27fc3b6f3fc49a36d3f962caac5c5495696d12ed (patch) | |
| tree | a95472c5bd4a5a0588a3725b4b8b1a94547c9999 /Doc/library | |
| parent | 6bf644ec82f14cceae68278dc35bafb00875efae (diff) | |
| download | cpython-git-27fc3b6f3fc49a36d3f962caac5c5495696d12ed.tar.gz | |
bpo-38870: Expose a function to unparse an ast object in the ast module (GH-17302)
Add ast.unparse() as a function in the ast module that can be used to unparse an
ast.AST object and produce a string with code that would produce an equivalent ast.AST
object when parsed.
Diffstat (limited to 'Doc/library')
| -rw-r--r-- | Doc/library/ast.rst | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Doc/library/ast.rst b/Doc/library/ast.rst index b468f4235d..a7e0729b90 100644 --- a/Doc/library/ast.rst +++ b/Doc/library/ast.rst @@ -161,6 +161,19 @@ and classes for traversing abstract syntax trees: Added ``type_comments``, ``mode='func_type'`` and ``feature_version``. +.. function:: unparse(ast_obj) + + Unparse an :class:`ast.AST` object and generate a string with code + that would produce an equivalent :class:`ast.AST` object if parsed + back with :func:`ast.parse`. + + .. warning:: + The produced code string will not necesarily be equal to the original + code that generated the :class:`ast.AST` object. + + .. versionadded:: 3.9 + + .. function:: literal_eval(node_or_string) Safely evaluate an expression node or a string containing a Python literal or |
