Skip to main content

No project description provided

Project description

Fun with AST

Provides developers with a programmatic tool to change our own code. This repository contains a library to analyze and manipulate python code using Abstract Systax Tress manipulation.

Using the library

See the test-fun-with-ast project for examples of using the fun-with-ast library.

Why Fun-with-AST

  1. Here is a talk I gave in Pycon 2023. It explains the capabilities of fun-with-ast.
  2. It is a great learning personal development experience.
  3. Enables smart and complex manipulations

Examples: AST Parse vs. AST Unparse vs. fun-with-ast Source Code Preserver

The examples below show an original program that first was unparsed with python ast module, and then was unparsed using the fun-with-ast library. The actual code that generates these example can be found in the test-fun-with-ast library.

  1. Parse-Unparse Fibonacci Calculator

Potential usages:

  • Fun #1: Keep source to source transformations
  • Fun #2: switch else / if bodies
  • Fun #3: mutation testing switch < into <=
  • Fun #4: Switch For to While
  • Fun #5: for loop into tail recursion.
  • Fun #7: Add node AND comment.

How to Contribute

  1. Follow the steps in Contribute to projects.
  2. You can chose an existing open issue or open a new one.
  3. Start working ....
  4. Before submitting a pull request make sure tests are passing.

How to Run Tests

  1. In fun-with-ast we use pytest.
  2. Use your IDE to run all tests in tests directory.
  3. OR, use command line:
    1. cd <your path to fun-with-ast fork>/fun_with_ast/tests
    2. pytest --version, should be at least 7.2.2
    3. run pytest
    4. No tests should fail - some tests would be skipped / xfail.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fun_with_ast-0.1.70.tar.gz (81.2 kB view hashes)

Uploaded Source

Built Distribution

fun_with_ast-0.1.70-py3-none-any.whl (51.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page