Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 13 Doc/library/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions 5 Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
pablogsal marked this conversation as resolved.
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
-------

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.