Skip to main content

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


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)

Uploaded Source

Built Distribution

pmast-0.1.1-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page