On Wed, Aug 10, 2011 at 8:33 AM, Fuzzyman <fuzzy...@gmail.com> wrote: > On Aug 5, 12:29 pm, Ryan <heni...@yahoo.com> wrote: >> In the context of descriptors, the __set__ method is not called for >> class attribute access. __set__ is only >> called to set the attribute on an instance instance of the owner class >> to a new value, value. WHY? > > It's an unfortunate asymmetry in the descriptor protocol. You can > write "class descriptors" with behaviour on get, but not on set. > > As others point out, metaclasses are an ugly way round this > (particularly given that *basically* a class can only have one > metaclass - so if you're inheriting from a class that already has a > custom metaclass you can't use this technique).
Keep in mind that you can still do something like this: class XMeta(Base.__class__): "Customize here" class X(Base, metaclass=XMeta): "Do your stuff." They you would put your descriptor hacking in XMeta and still take advantage of the original metaclass. -eric > > Michael Foord > -- > http://voidspace.org.uk/ > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list