Skip to main content

Asteria (Al2O3)

Missing AST features

Features

  • Repr implementation to every node (uses astpretty if it is available, if not fall backs to the ast.dump)
  • AST Comparisons with other nodes
  • Custom initializer with finding default values according to ASDL spec
  • Shortcuts for fix_missing_locations, compile (e.g ast.parse("2+2").compile())
  • Unparsing shortcuts, ast.parse("2+2").to_source(). It uses astor if its available, if not it fallbacks to the ast.unparse interface.
  • Parent/Child relationships to nodes
  • Helpers functions for mutating tree (like add_global method to Module nodes which inserts given node at the top of body)
  • Symbol table access with get_symbol_table method
  • and many more...

Demo

>>> import ast
>>> import asteria
>>> ast.parse("2+2") == ast.parse("2+2")
True
>>> ast.parse("2+2").body[0].value
BinOp(
    left=Constant(value=2, kind=None),
    op=Add(),
    right=Constant(value=2, kind=None),
)
>>> ast.parse("print(2+2)").compile()
<code object <module> at 0x7f2602f21450, file "<ASTERIA>", line 1>
>>> eval(_)
4
>>> ast.parse("import asteria").to_source()
'import asteria'
>>> sample = ast.parse("2+2")
>>> sample.parentize()
>>> sample.body[0].value.left.parent
BinOp(
    left=Constant(value=2, kind=None),
    op=Add(),
    right=Constant(value=2, kind=None),
)
>>> sample.body[0].value.parent
Expr(
    value=BinOp(
        left=Constant(value=2, kind=None),
        op=Add(),
        right=Constant(value=2, kind=None),
    ),
)
>>> some_try = ast.parse("""\
... try:                
...     def x():        
...             print(1)
... finally: pass       
... """)
>>> some_try.parentize()
>>> some_try.body[0].body[0].body[0].value
Call(
    func=Name(id='print', ctx=Load()),
    args=[Constant(value=1, kind=None)],
    keywords=[],
)
>>> len(tuple(some_try.body[0].body[0].body[0].value.until_parented_by(ast.Try)))
3
>>> some_try.add_global(ast.parse("print('lol')").body[0])
>>> print(some_try.to_source())
print('lol')
try:

    def x():
        print(1)
finally:
    pass

Release files for asteria 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asteria 0.0.2
File Size Uploaded
asteria-0.0.2.tar.gz 4.8 kB Details

Release files / asteria-0.0.2.tar.gz

Download URL asteria-0.0.2.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
852ced0ee2bb064908b98748c0b4ddc2d0c7d8d71a4885b9efe0c1aff49a8e7b
BLAKE2b-256 checksum
How to use checksums
0445ef5cc71cdb44a91b4a0aa3fff8c6f660d082911ade053ca7bb2de0e1f940
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.0.2 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page