Skip to main content

The ASTFormatter class accepts an AST tree and returns a valid source code representation of that tree.

Project description

The ASTFormatter class accepts an AST tree and returns a valid source code representation of that tree.

Example Usage

from astformatter import ASTFormatter
import ast

tree = ast.parse(open('modulefile.py'), 'modulefile.py', mode='exec')
src  = ASTFormatter().format(tree, mode='exec')

Bugs

  • Currently, indentation is fixed at 4 spaces.

  • Too many methods are exposed that shouldn’t be, in order to properly subclass ast.NodeVisitor.

  • Need to make the statement visitor methods consistent about returning a list of strings; most still just return a string.

  • Code modified to work with 3.x needs cleanup

Latest Changes

0.6.4 (2017-06-25)

  • Process docstring if exsts in Module, ClassDef, and FunctionDef nodes. #9 (darkfoxprime)

  • Add parens around unary operands if necessary #8 (zerebubuth)

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

ASTFormatter-0.6.4.tar.gz (7.6 kB view details)

Uploaded Source

File details

Details for the file ASTFormatter-0.6.4.tar.gz.

File metadata

File hashes

Hashes for ASTFormatter-0.6.4.tar.gz
Algorithm Hash digest
SHA256 e24e7763bcc8c96d4c7f86b6be2ab524911fc69af9e1d1580113759c5ab12002
MD5 c9ee9b2d53cd9d645aef5628274c1be4
BLAKE2b-256 1fcd4693e78b97d1bb7525a460be2907922f4432e752a6057b2b942bb38345e7

See more details on using hashes here.

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