Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - 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)
Release History

Release History

This version
History Node

0.6.4

History Node

0.6.3

History Node

0.6.2

History Node

0.6.1

History Node

0.6.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
ASTFormatter-0.6.4.tar.gz (7.6 kB) Copy SHA256 Checksum SHA256 Source Jun 25, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting