why not extending the syntax for classes, too ?

Michele Simionato mis6 at pitt.edu
Mon Feb 10 20:30:44 CET 2003


Michael Hudson <mwh at python.net> wrote in message news:<7h3r8agz5lx.fsf at pc150.maths.bris.ac.uk>...
> mis6 at pitt.edu (Michele Simionato) writes:
> 
> > > 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 :-(
> 
> In your idea:
> 
> def filter(*args):
>     print args
> 
> def func() is filter:
>     pass
> 
> prints: <function func at 0xXXXXXXXXX>
> 
> class C is filter:
>     pass
> 
> prints: ('C', (), {'__module__':'__main__'})
> 
> IOW lambda x:x works as a function filter but not as a class filter.


Having not followed the thread on python-dev, I see now that we are 
talking about different things, whence the confusion. I had in mind
(let me use "isinstanceof" in place of "is", for clarity)

def f(x) isinstanceof descriptor:

and

def C(B) isinstanceof metaclass:

In the first case the qualifier is a descriptor, in the second case a
metaclass. I never thought to use a function as you are suggesting instead.
I have to think about.

> > > 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.
> 
> Does that do the moral equivalent of
> 
> class _Foo(Traced,Profiled,Protected):
>     pass
> 
> C = _Foo('C', (), {whatever})
> 
> ?
> 
> Cheers,
> M.

No, I was too much implicit.

class C(B) is Traced,Profiled,Protected: 

to me was

class C(B): __metaclass__=type(
            "TracedProfiledProtected",(Traced,Profiled,Protected),{})

with Traced, Profiled and Protected all metaclasses.

I must confess that I have changed my mind and now I think that "is"
actually is confusing. "isinstanceof" is what I meant.

Anyway, I trust the developers enough to give them the choice of the syntax.
I am more interested in the functionality.

>From you post, I deduce that your intended functionality, with functions
with qualifiers, is different from what I thought. At this point,
I wonder if Holger and Erik are talking about yet another functionality ...

Cheers,

          Michele




More information about the Python-list mailing list