DecoratorInjector in Python by Yannick
My friend Yannick is a huge fan of the Python programming language. As a die-hard geek, he's been coding various hacks over the years, but for some very strange reason, he never published a single of his (sometimes really nice) hacks
We pushed him again and again, and I'm glad to announce that after more than a year of intense pressure, Yannick has just published the first of his hacks! Congrats Yannick, and thanks for not choosing the GPL
This first hack is called "DecoratorInjection" (notice the nice Sphinx documentation):
This is an internal DSL providing fluent interface to inject decoration, i.e. decorate methods at runtime.
Method names can be specified directly or using a method grabber, which introspect the class.
The DSL is quite pleasant to read. For example you can easily perform AOP on your Python classes using a decorator and the following declaration:
decorate(PUBLIC_METHODS).of(classes_named("DAO.*").within(somemodule)).using(tracer)
which sould be read as:
decorate the public methods of the classes whose name start with "
DAO" in the module called "somemodule" using the "tracer" decorator
Nice work Yannick, and please publish more of your Python hacks!
Related posts:
- A todo list on Google App Engine… Python
- nose: testing in Python made easy
- Python + mod_python: why use PHP again?
- Rails-style Ruby meta-programming
- Revisiting Guice and AOP with AspectJ

April 1st, 2009 - 06:50
Thanks for the buzz