Good real-world uses of metaclasses (e.g. in Python)

Posted by Carles Barrobés on Stack Overflow See other posts from Stack Overflow or by Carles Barrobés
Published on 2010-05-25T18:43:59Z Indexed on 2010/05/27 6:21 UTC
Read the original article Hit count: 178

Filed under:
|

I'm learning about metaclasses in Python. I think it is a very powerful technique, and I'm looking for good uses for them. I'd like some feedback of good useful real-world examples of using metaclasses. I'm not looking for example code on how to write a metaclass (there are plenty examples of useless metaclasses out there), but real examples where you have applied the technique and it was really the appropriate solution. The rule is: no theoretical possibilities, but metaclasses at work in a real application.

I'll start with the one example I know:

  • Django models, for declarative programming, where the base class Model uses a metaclass to fill the model objects of useful ORM functionality from the attribute definitions.

Looking forward to your contributions.

© Stack Overflow or respective owner

Related posts about python

Related posts about metaprogramming