Pattern Matching for the Python AST
Project description
Pattern Matcher for Python AST
This tool is about finding patterns in AST structures. As such, it may be useful for static analysis and linting.
import pmast
pm = pmast.PatternDispatch()
@pm('FunctionDef.Return')
def on_return(data, fd, ret):
# Store return statement (an ast node) for each function
data[fd.name] = ret
class Foo(object):
def x(self):
return 3
def y(self, foo, bar):
return 4
data = pm.dispatch(Foo)
assert data['x'].value.n == 3
assert data['y'].value.n == 4
The intent here is to be a little bit like XPath for the Python AST module.
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
pmast-0.1.1.tar.gz
(2.3 kB
view hashes)
Built Distribution
pmast-0.1.1-py3-none-any.whl
(3.5 kB
view hashes)