Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

astcheck

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astcheck

Check Python ASTs against templates

  • 0.4.0
  • Source
  • PyPI
  • Socket score

Maintainers
1

astcheck

astcheck compares Python Abstract Syntax Trees against a template. This is useful for testing software that automatically generates or modifies Python code.

Installation::

pip install astcheck

Example use:

.. code:: python

import ast, astcheck

template = ast.Module(body=[
    ast.FunctionDef(name='double', args=ast.arguments(args=[ast.arg(arg='a')])),
    ast.Assign(value=ast.Call(func=ast.Name(id='double')))
])

sample = """
def double(a):
    do_things()
    return a*2
b = double(a)
"""

astcheck.assert_ast_like(ast.parse(sample), template)

Only the parts specified in the template are checked. In this example, the code inside the function, and the assignment target (b) could be anything.

For more details, see the documentation <http://astcheck.readthedocs.org/en/latest/index.html>_.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc