Skip to content

Instantly share code, notes, and snippets.

@jimbaker
Created January 15, 2014 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimbaker/8445537 to your computer and use it in GitHub Desktop.
Save jimbaker/8445537 to your computer and use it in GitHub Desktop.
Clamp uses 6 - or maybe 7 - metaprogramming functionalities available in Python, Jython specifically, and Java.

Clamp employs six (possibly seven) metaprogramming functionalities in Python/Jython:

  1. Metaclass support, which required unifying Java types (rooted by java.lang.Class) and Python new-style classes (rooted by type). This then enable the metaclass to build the desired class shape. It can do the following: constant type inference; construction of getters/setters; etc.

  2. Brand new, __proxymaker__ allows for a CustomMaker to intercept the construction of a Java proxy. (Jython specific.)

  3. Import hooks, to intercept the import of Java annotations. In particular, this means class annotations can be augmented (monkeypatched?) so they can be used as class decorators; method annotations so they can be used function decorators. Field annotations can be directly used by the metaclass support when working with a field.

  4. Class decorators.

  5. ASM bytecode rewriting. Requires interception at jar build.

  6. pth support

And since this is really more of a hook in setuptools:

  1. More of a hook of setuptools - custom setuptools hooks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment