Skip to content

Instantly share code, notes, and snippets.

@jimbaker
Last active January 3, 2016 09:19
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/8441725 to your computer and use it in GitHub Desktop.
Save jimbaker/8441725 to your computer and use it in GitHub Desktop.
Possible Clamp DSL to support reflection on Java generics, which will then generate the necessary type signatures in Jython
# Uses names from a motivating paste by Oti Humbel, http://pastebin.com/1deBqEAV
from some_source import View, IEntityView, EntityManagerPlug2
# clamp_base is implemented, extends is a hypothetical class decorator similar to proposed support
# for Java class annotations that will rewrite the class bytecode with the necessary type signature data, using
# http://asm.ow2.org/asm40/javadoc/user/org/objectweb/asm/signature/SignatureVisitor.html
from clamp import clamp_base, extends
FooPackage = clamp_base(package="foo")
# need to be able to write the equivalent to this Java class
# public class JavaManager implements EntityManagerPlug2<View extends IEntityView> { ... }
# so that reflection on the generics used with the class, eg cls.getGenericInterfaces(), etc, still will work
@extends(View, IEntityView)
class PythonManager(EntityManagerPlug2, FooPackage):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment