Skip to content

MaddieM4/pmast

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Pattern Matching for the Python AST

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published