Skip to content
Permalink
Browse files

bpo-38870: Expose a function to unparse an ast object in the ast modu…

…le (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.
  • Loading branch information
pablogsal committed Nov 24, 2019
1 parent 6bf644e commit 27fc3b6f3fc49a36d3f962caac5c5495696d12ed
@@ -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

This comment has been minimized.

Copy link
@tirkarthi

tirkarthi Nov 25, 2019

Contributor

Minor typo here : necesarily -> necessarily

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
@@ -121,6 +121,11 @@ Added the *indent* option to :func:`~ast.dump` which allows it to produce a
multiline indented output.
(Contributed by Serhiy Storchaka in :issue:`37995`.)

Added the :func:`ast.unparse` as a function in the :mod:`ast` module that can
be used to unparse an :class:`ast.AST` object and produce a string with code
that would produce an equivalent :class:`ast.AST` object when parsed.
(Contributed by Pablo Galindo and Batuhan Taskaya in :issue:`38870`.)

asyncio
-------

0 comments on commit 27fc3b6

Please sign in to comment.
You can’t perform that action at this time.