gh-133367: Add missing options to ast CLI (#133369)

Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
This commit is contained in:
Semyon Moroz 2025-05-05 21:17:43 +04:00 committed by GitHub
parent 5c245ffce7
commit 2b4e2b7830
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 154 additions and 9 deletions

View file

@ -1,4 +1,4 @@
:mod:`!ast` --- Abstract Syntax Trees
:mod:`!ast` --- Abstract syntax trees
=====================================
.. module:: ast
@ -29,7 +29,7 @@ compiled into a Python code object using the built-in :func:`compile` function.
.. _abstract-grammar:
Abstract Grammar
Abstract grammar
----------------
The abstract grammar is currently defined as follows:
@ -2156,10 +2156,10 @@ Async and await
of :class:`ast.operator`, :class:`ast.unaryop`, :class:`ast.cmpop`,
:class:`ast.boolop` and :class:`ast.expr_context`) on the returned tree
will be singletons. Changes to one will be reflected in all other
occurrences of the same value (e.g. :class:`ast.Add`).
occurrences of the same value (for example, :class:`ast.Add`).
:mod:`ast` Helpers
:mod:`ast` helpers
------------------
Apart from the node classes, the :mod:`ast` module defines these utility functions
@ -2484,7 +2484,7 @@ and classes for traversing abstract syntax trees:
.. _ast-compiler-flags:
Compiler Flags
Compiler flags
--------------
The following flags may be passed to :func:`compile` in order to change
@ -2533,7 +2533,7 @@ effects on the compilation of a program:
.. _ast-cli:
Command-Line Usage
Command-line usage
------------------
.. versionadded:: 3.9
@ -2572,6 +2572,28 @@ The following options are accepted:
Indentation of nodes in AST (number of spaces).
.. option:: --feature-version <version>
Python version in the format 3.x (for example, 3.10). Defaults to the
current version of the interpreter.
.. versionadded:: next
.. option:: -O <level>
--optimize <level>
Optimization level for parser. Defaults to no optimization.
.. versionadded:: next
.. option:: --show-empty
Show empty lists and fields that are ``None``. Defaults to not showing empty
objects.
.. versionadded:: next
If :file:`infile` is specified its contents are parsed to AST and dumped
to stdout. Otherwise, the content is read from stdin.

View file

@ -875,6 +875,11 @@ ast
that the root node type is appropriate.
(Contributed by Irit Katriel in :gh:`130139`.)
* Add new ``--feature-version``, ``--optimize``, ``--show-empty`` options to
command-line interface.
(Contributed by Semyon Moroz in :gh:`133367`.)
bdb
---