why not extending the syntax for classes, too ?

holger krekel pyth at devel.trillke.net
Fri Feb 7 12:20:39 EST 2003


Michele Simionato wrote:
> 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 agree (but then again i was of those proposing it 
over on python-dev :-)

> 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. 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. Just my $0.02
> on the way of avoiding too many underscores ;-) 

Yip, i like that.  Though I am not sure if 'is' fits with all the 
semantics of the underlying ideas.  But that can't be decided
now because that isn't settled.

One of the possible irrations with 'is' is that in python
the keyword 'is' currently is used for conditional expressions 
as in 

    if obj is None:
        ...

but the above "class/def() is ...:" notation actually performs 
some transformations (i.e. changes objects).  But then again, 
it's easy enough to not confuse those two usages of 'is' because 
hardly anybody would think that 'class' or 'def' bound by a ':' 
marks conditional expressions. 

all-the-best, 

    holger





More information about the Python-list mailing list