class with invalid base class
Michael Hudson
mwh at python.net
Wed Nov 5 08:35:52 EST 2003
Thomas Heller <theller at python.net> writes:
> "Andrew Dalke" <adalke at mindspring.com> writes:
>
> > Out of curiosity, I tried passing using an invalid base
> > for a class. I can't explain why I got the error messages
> > I did. Can someone here enlighten me?
> >
> > # Here I'm just curious
> >
> >>>> def spam(a, b):
> > ... return a+b
> > ...
> >>>> class Spam(spam):
> > ... pass
> > ...
> > Traceback (most recent call last):
> > File "<interactive input>", line 1, in ?
> > TypeError: function() argument 1 must be code, not str
> >>>>
> >
> > # What's 'function'? Why is it called?
>
> It's the Don Beaudry hook ;-). If the base class has callable a
> __class__ attribute, this is called with three arguments: The name of
> the new class, a tuple of the bases, and a dictionary. Or something like
> this, the details may be wrong...
Actually, I think it's type(baseclass) that gets called -- otherwise
you wouldn't be able to inherit from old-style classes! What's
changed since 2.2 is that type objects are now callable.
(Isn't it amazing how something as simple as metaclasses -- and they
*are* a simple idea -- can be *so* confusing? I wrote and rewrote
that paragraph at least three times...)
Cheers,
mwh
--
But since your post didn't lay out your assumptions, your goals,
or how you view language characteristics as fitting in with
either, you're not a *natural* candidate for embracing Design by
Contract <0.6 wink>. -- Tim Peters, giving Eiffel adoption advice
More information about the Python-list
mailing list