why not extending the syntax for classes, too ?

Michele Simionato mis6 at pitt.edu
Sat Feb 8 15:55:06 EST 2003


Michael Hudson <mwh at python.net> wrote in message news:<7h3isvu235l.fsf at pc150.maths.bris.ac.uk>...
> mis6 at pitt.edu (Michele Simionato) writes:
> 
> > Within the proposals of extending the function syntax,
> > reported on the python-dev summary recently posted on c.l.p.,
> > I like the most the proposal with "is", as for instance in
> > 
> > def double(x) is staticmethod:
> >     return 2*x
> > 
> > I like the "is" syntax more than the syntax with "as" and the syntax 
> > with the square brackets, especially because with "is"  it would be
> > natural to extend the notation for classes, using metaclasses as class
> > descriptors. 
> 
> I'm not sure 'is' gels well with the procedural implementation of the
> syntax.
> 
> > Metaclasses are typically denoted by adjectives and thus,
> > instead of writing, for instance
> > 
> > class C(B): 
> >     __metaclass__=Traced 
> >     #assuming Traced is a metaclass adding tracing capabilities
> > 
> > one could write
> > 
> > class C(B) is Traced:
> >     #This is much more readable
> > 
> > I am curious to know if this has already been proposed.
> 
> Yes, in the thread titled IIRC "no macros in python" from
> ~15-Dec-2002.

I missed that. Better if I am not the only proponent ;)

> Your idea has a certain inconsistency: in the def the 'filter'
> callable gets the whole function object.  In the class statement the
> 'filter' gets the bits you need to make the class.

? Sorry, I do not understand what do you mean :-(

> It also doesn't chain well, but given your preference of syntax, I
> guess you don't care :-)
> 

I was thinking to chain with commas, as in

class C is Traced,Profiled,Protected: #etc. etc.

Cheers,

                      Michele




More information about the Python-list mailing list