[Python-Dev] Definining properties - a use case for class decorators?

Josiah Carlson jcarlson at uci.edu
Mon Oct 24 12:54:55 CEST 2005


Michele Simionato <michele.simionato at gmail.com> wrote:
> 
> On 10/24/05, Josiah Carlson <jcarlson at uci.edu> wrote:
> > I would criticise it for being dangerously close to worthless.  With the
> > minor support code that I (and others) have offered, no new syntax is
> > necessary.
> >
> > You can get the same semantics with...
> >
> > class NAME(_(TYPE), ARGS):
> >     BLOCK
> >
> > And a suitably defined _.  Remember, not every X line function should be
> > made a builtin or syntax.
> >
> >  - Josiah
> 
> Could you re-read my original message, please? Sugar is *everything*
> in this case. If the functionality is to be implemented via a __metaclass__
> hook, then it should be considered a hack that nobody in his right mind
> should use. OTOH, if there is a specific syntax for it, then it means
> this the usage
> has the benediction of the BDFL. This would be a HUGE change.
> For instance, I would never abuse metaclasses for that, whereas I
> would freely use a 'create' statement.

Metaclass abuse?  Oh, I'm sorry, I thought that the point of metaclasses
were to offer a way to make "magic" happen in a somewhat pragmatic
manner, you know, through metaprogramming.  I would call this particular
use a practical application of standard Python semantics.

Pardon me while I attempt to re-parse your above statement...
"If there is a specific syntax for [passing a temporary namespace to a
callable, created by some sort of block mechanism], then [using it for
property creation] has the benediction of the BDFL".

What I'm trying to say is that it already has a no-syntax syntax.  It
uses the "magic" of metaclasses, but one can make that "magic" as
explicit as necessary.

class NAME(PassNamespaceFromClassBlock(fcn=TYPE, args=ARGS)):
    BLOCK


Personally, I've not seen the desire to pass temporary namespaces to
functions until recently, so whether or not people will use it for
property creation, or any other way that people would find interesting
and/or useful, is at least a bit of prediction.  Maybe people will
prefer to use property('get_foo', 'set_foo', 'del_foo'), who knows?  But
you know what?  Regardless of what people want, they can use metaclasses
right now to create properties, where they would have to wait until
Python 2.5 comes out before they could use this proposed 'create'
statement.


 - Josiah



More information about the Python-Dev mailing list