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
- Here is a talk I gave in Pycon 2023. It explains the capabilities of fun-with-ast.
- It is a great learning personal development experience.
- 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.
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
toWhile
- Fun #5: for loop into tail recursion.
- Fun #7: Add node AND comment.
How to Contribute
- Follow the steps in Contribute to projects.
- You can chose an existing open issue or open a new one.
- Start working ....
- Before submitting a pull request make sure tests are passing.
How to Run Tests
- In
fun-with-ast
we use pytest. - Use your IDE to run all tests in
tests
directory. - OR, use command line:
cd <your path to fun-with-ast fork>/fun_with_ast/tests
pytest --version
, should be at least7.2.2
- run
pytest
- No tests should fail - some tests would be skipped / xfail.
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for fun_with_ast-0.1.70-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb0c409bf193985934284c1811c784bfcb964a840d93407b0e3c40488139e6dd |
|
MD5 | 86839ee7ef40ece159daebdd1bb216cd |
|
BLAKE2b-256 | e20932b2f61ac52a6c995d607c10e47ffcaa59dcee8dd79cb95527d08253bcf5 |