A simple library for finding statement-level substructures in Abstract Syntax Trees
Project description
qChecker
A simple library for finding statement-level substructures (e.g. micro-anti-patterns/smells) in Abstract Syntax Trees
Install
pip install qchecker
Usage
qChecker is still in alpha and significant API changes are likely
Currently, subclasses of qchecker.Substructure
define structure names,
descriptions, and an iter_matches
class method which iterates
over qchecker.TextRange
s that match the pattern defined by the
Substructure's technical_description
.
For example:
import ast
from qchecker import IfElseReturnBool
code = """
class Foo:
def __init__(self, x):
self.x = x
def bar(self):
if self.x < 10:
return True
else:
return False
""".strip()
module = ast.parse(code)
matches = IfElseReturnBool.iter_matches(module)
print(IfElseReturnBool.technical_description)
print(*matches, sep="\n")
would print the technical_description
of the IfElseReturnBool
Substructure
followed by a TextRange
with the start and end line numbers and column offsets
of the structure in the code
string.
If(..)[Return bool] Else[Return !bool]
TextRange(6,8->9,24)
A SUBSTRUCTURES
list provides the list of all subclasses of Substructure
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for qchecker-0.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a23ed8d6fdb4e44d07a9ea77b3f831d128c26bcc3c3e64e20aa95f38cbec8d5 |
|
MD5 | f5d9895b3510766bac2d82b1cb96fae8 |
|
BLAKE2b-256 | 1afdc2d8f5021850d2a9bd7a1d0b653244f9dccdb7f6695d4d5721f27699137c |