Query AST elements by using CSS Selector-like syntax
Project description
AST Selector
Query AST elements by using CSS Selector-like syntax
"Query AST elements 🌲 by using CSS Selector-like 💅 syntax."
Installation and usage
Installation
pip install ast-selector
Usage
from ast_selector import AstSelector
tree = load_python_code_as_ast_tree()
query = "FunctionDef Raise $FunctionDef"
# Query all functions that raises at least an exception
functions_raising_exceptions = AstSelector(query, tree).all()
Use Cases
Functions that return int
from ast_selector import AstSelector
tree = load_python_code_as_ast_tree()
query = "FunctionDef.returns[id=int] $FunctionDef"
# Query all functions that return ints e.g. def sum() -> int
function_element = AstSelector(query, tree).first()
License
MIT
Credits
It's extremely hard to keep hacking on open source like that while keeping a full-time job. I thank God from the bottom of my heart for both the inspiration and the energy.
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_selector-0.2.0.tar.gz
(6.2 kB
view details)
Built Distribution
File details
Details for the file ast_selector-0.2.0.tar.gz
.
File metadata
- Download URL: ast_selector-0.2.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6991884efd4248060ecf3da169e8ade4d48d2ab64fdb99046afbcb98aa5a27a1 |
|
MD5 | 46edcf29e65e6ade78d5ece735e1bcde |
|
BLAKE2b-256 | 6fd7efea6d20f174e549766e09f46e6f3ed646c32d16e1b5ec44af892c533cc6 |
File details
Details for the file ast_selector-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: ast_selector-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.2.0 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfcc130fdf9bdc7cd105f5d53fc5acd575a4067c6710b1d909fe1e68bf411388 |
|
MD5 | a87bc880eadb4ec8cea9b7c6c1458d03 |
|
BLAKE2b-256 | 9d50f81b5caed1b90a32ca494b3f4a66c50897f36960adb4789a17efae80549c |