Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

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.

Files for ASTFormatter, version 0.6.4
Filename, size File type Python version Upload date Hashes
Filename, size ASTFormatter-0.6.4.tar.gz (7.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page