limpy /

Filename Size Date modified Message
limpy
40 B
1.2 KB
1.4 KB
3.1 KB
436 B
73 B
1.6 KB

LimPy

Limited Python

LimPy parses a limited version of the Python grammar. It supports basic Python syntax, but is known not to support the following:

  • classes
  • function definition
  • multi-variable assignment
  • list and generator comprehensions

The goal is to be able to expose various Python objects to a scripting environment where non-professional programmers can write simple code to solve various problems.

Origins

LimPy originated in a survey system at YouGov where it gave the users scripting questionnaires the ability to include various bits of Python code that is executed during survey interviews.

A previous version of the survey system allowed Python code but it was not type checked and non-syntactical bugs were only reached at run time.

LimPy was successful in still offering much of the power of Python at runtime but checking types, operations on types, and function/method call signatures before runtime to ensure that an entire class of bugs was avoided.

Role

LimPy checks code. You supply it with a namespace of helper objects, another namespace of variables and source code and it will raise various LimPy exceptions if there are problems or return the parsed code and the updated namespace of variables if there were new variables defined in the source.

LimPy does not execute the code. That is up to your runtime system to handle. The returned variables namespace contains only types as values, not real runtime values. Deciding what to do with that namespace is up to your runtime code.

Because LimPy is a strict subset of Python, it can typically be exec'd directly by Python.

Testing

LimPy includes some unit tests. To run them, simply invoke setup.py test or install the latest pytest. See the jenkins script for the routine used at YouGov to perform continuous integration testing on this project.

Changes

2.0

  • Added limpy.types.Signature, which replaces build_sig, SigInfo, and signature functions. Any code that uses or references these deprecated functions will need to be updated.
  • TypeSpecification.add_method now only accepts a Signature instance.
  • LimPy now expects all dynamically-dispatched types to be classes that must provide IDynamicType (and need not necessarily be subclasses of DynamicDispatch).

Clients upgrading to LimPy 2.0 will typically just need to update their @limpy.types.signature decorators to instead use @limpy.types.Signature. Any calls to a TypeSpecification.add_method will need to first construct a Signature instance (with the same parameters).

For libraries that do more intimate things with the signatures, it will be necessary to update those references. See the repository changelog for details on how this was done within the LimPy project itself.

1.2.2

  • Improved newline counting and tests.
  • Empty source or source only comments is now valid LimPy.

1.2.1

  • Restored Python 2.5 compatibility.

1.2

  • Updated to PLY 3.4
  • Now by default LimPy does not write files to the current directory.

1.1

  • LimPy no longer allows assignment to Python reserved words.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.