Skip to content

Improve ast CLI with new options: --feature-version, --optimize, and --show-empty #133367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sobolevn opened this issue May 4, 2025 · 2 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@sobolevn
Copy link
Member

sobolevn commented May 4, 2025

Feature or enhancement

Current options:

» ./python.exe -m ast --help
usage: python.exe -m ast [-h] [-m {exec,single,eval,func_type}] [--no-type-comments] [-a]
                         [-i INDENT]
                         [infile]

positional arguments:
  infile                the file to parse; defaults to stdin

options:
  -h, --help            show this help message and exit
  -m, --mode {exec,single,eval,func_type}
                        specify what kind of code must be parsed
  --no-type-comments    don't add information about type comments
  -a, --include-attributes
                        include attributes such as line numbers and column offsets
  -i, --indent INDENT   indentation of nodes (number of spaces)
                     

Basically, our CLI is an interface to ast.dump + ast.parse, ast.parse.

But, ast.parse has several important options that are missing right now. I propose to add them:

  • --feature-version
  • and --optimize from parse
  • --show-empty from dump

Docs:

cc @donBarbos, will you be interested in working on this issue?
If not, please, tell me about that - I want to have this in 3.14 and the feature freeze is in several days.

Linked PRs

@sobolevn sobolevn added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels May 4, 2025
@donBarbos
Copy link
Contributor

sure, i would be glad to implement it

@sobolevn
Copy link
Member Author

sobolevn commented May 4, 2025

awesome, tag me on PR - I will review it as soon as possible.

donBarbos added a commit to donBarbos/cpython that referenced this issue May 4, 2025
sobolevn added a commit that referenced this issue May 5, 2025
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: sobolevn <mail@sobolevn.me>
@sobolevn sobolevn closed this as completed May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants