[Python-ideas] Assignment decorators (Re: The Descriptor Protocol...)

Terry Reedy tjreedy at udel.edu
Fri Mar 4 00:30:55 CET 2011


On 3/3/2011 6:15 PM, Guido van Rossum wrote:

> The use case I can think of for the first example would be to declare
> fields in a model class that know their own field name, as in Django
> and AppEngine models, and many other libraries. But that use case is
> covered pretty well by metaclasses, and the @decorator syntax has the
> disadvantage of requiring at least two lines per field, whereas the
> current solution requires only one line (and there is no explicit
> repetition of the field name -- the metaclass takes care of it).

It seems that there are a number of things one can do with a metaclass 
that are not immediately obvious to everyone. This is not the first time 
I have seen that sort of answer. Perhaps a metaclasslib, to go with 
contextlib, would be useful. Or a HOWTO.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list