Skip to main content

No project description provided

Project description

ast-comments

An extension to the built-in ast module. Finds comments in source code and adds them to the parsed tree.

Installation

pip install ast-comments

Usage

There is no difference in usage between ast and ast-comments

>>> import ast_comments as astcom
>>> tree = astcom.parse("hello = 'hello' # comment to hello")

Parsed tree is instance of the original ast.Module object

>>> tree
<_ast.Module object at 0x7ffba52322e0>

Any "statement" node of the tree has comments field

>>> tree.body[0].comments
('comment to hello',)
>>> astcom.dump(tree)
"Module(body=[Assign(targets=[Name(id='hello', ctx=Store())], value=Constant(value='hello', kind=None), type_comment=None, comments=('comment to hello',))], type_ignores=[])"

Contributing

You are welcome to open an issue or create a pull request

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

ast-comments-0.1.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ast_comments-0.1.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file ast-comments-0.1.1.tar.gz.

File metadata

  • Download URL: ast-comments-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.8.10 Linux/5.4.0-122-generic

File hashes

Hashes for ast-comments-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fb59eab4fd95e7b3366677be6682748edfc11822d3b3e9340d6f98e9459e4ea3
MD5 a44b9f3387085914380b38cf373918a1
BLAKE2b-256 f09586c6ad054c7051317171737e0e6c192f719f727fba08b0171928aa24a3da

See more details on using hashes here.

File details

Details for the file ast_comments-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ast_comments-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.8.10 Linux/5.4.0-122-generic

File hashes

Hashes for ast_comments-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d813c1836f6774671f3cbc2fa4c8d821839ab11fe843e6df43075fae922a28f7
MD5 81bab76eb4a87245d002f651973280e0
BLAKE2b-256 6c9df54aa7c6a86e154ff771db8d4c231c3d322d312a85ea572eefda6426c690

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page