Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An AST unparser for Python

License

NotificationsYou must be signed in to change notification settings

simonpercivall/astunparse

Repository files navigation

https://badge.fury.io/py/astunparse.pnghttps://travis-ci.org/simonpercivall/astunparse.png?branch=masterhttps://readthedocs.org/projects/astunparse/badge/

An AST unparser for Python.

This is a factored out version ofunparse found in the Pythonsource distribution; under Demo/parser in Python 2 and under Tools/parserin Python 3.

Basic example:

import inspectimport astimport astunparse# get back the source codeastunparse.unparse(ast.parse(inspect.getsource(ast)))# get a pretty-printed dump of the ASTastunparse.dump(ast.parse(inspect.getsource(ast)))

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

Added to this is a pretty-printingdump utility function.

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

Extensions and Alternatives

Similar projects include:

None of these roundtrip much of the standard library and fail several of the basictests in thetest_unparse test suite.

This library uses mature and core maintained code instead of trying to patchexisting libraries. Theunparse and thetest_unparse modulesare under the PSF license.

Extensions include:

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

Features

  • unparses Python AST.
  • pretty-prints AST.

About

An AST unparser for Python

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp