Giter Club home page Giter Club logo

astunparse's Introduction

AST Unparser

image

image

image

An AST unparser for Python.

This is a factored out version of unparse found in the Python source distribution; under Demo/parser in Python 2 and under Tools/parser in Python 3.

Basic example:

import inspect
import ast
import astunparse

# get back the source code
astunparse.unparse(ast.parse(inspect.getsource(ast)))

# get a pretty-printed dump of the AST
astunparse.dump(ast.parse(inspect.getsource(ast)))

This library is single-source compatible with Python 2.6 through Python 3.5. It is authored by the Python core developers; I have simply merged the Python 2.7 and the Python 3.5 source and test suites, and added a wrapper. This factoring out is to provide a library implementation that supports both versions.

Added to this is a pretty-printing dump utility function.

The test suite both runs specific tests and also roundtrips much of the standard library.

Extensions and Alternatives

Similar projects include:

None of these roundtrip much of the standard library and fail several of the basic tests in the test_unparse test suite.

This library uses mature and core maintained code instead of trying to patch existing libraries. The unparse and the test_unparse modules are under the PSF license.

Extensions include:

  • typed-astunparse: extends astunparse to support type annotations.

Features

  • unparses Python AST.
  • pretty-prints AST.

astunparse's People

Contributors

amundhov avatar cav71 avatar fjarri avatar graingert avatar hroncok avatar jwilk avatar mbdevpl avatar nvbn avatar serge-sans-paille avatar simonpercivall avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.