simple metaclass question
Michael Hudson
mwh at python.net
Wed Nov 13 14:10:52 EST 2002
Carl Banks <imbosol at vt.edu> writes:
> Alex Martelli wrote:
> > Carl Banks wrote:
> > ...
> >> 2. Because M is not a subclass of type, instances of M are not types.
> >> Therefore, A is not a type. (I'm not sure of this one, though. I
> >> think in Python an object can be a type only if it is a subclass of
> >> type; I'm not sure if this is true in other languages with
> >
> > I'm not exactly sure of what it is that you believe, but, for the record:
> > objects CAN be types of other objects, in Python, without subclassing the
> > built-in `type` -- for example:
>
> Thanks. I was thinking at the C level, where objects that serve as
> types have to have a certain fixed structure. To create a metatype in
> Python (not C), it would have to be an instance of a class that
> subtypes type, right?
I don't know whether type(type(ob)) is always a subtype of type -- I
think so -- but certainly the thing you write
class Bob:
__metaclass__ = ...<---- here
doesn't have to be a subtype of type. It can be handy to have a
function here, for instance -- but if this function doesn't return a
subtype of type, inheriting from the resulting class gets totally
bewildering (or at least, I managed to totally bewilder myself along
these lines).
> Gawd, it takes a lot to spin my head in circles, but this metaclass
> stuff is doing it.
Yeah, with metaclasses who needs drugs? Or merry-go-rounds?
plenty-more-where-this-confusion-came-from-ly y'rs
M.
--
> Touche! But this confirms you are composed of logic gates.
Crud, I thought those were neurons in there.
-- Thomas F. Burdick, Kenny Tilton, comp.lang.lisp
More information about the Python-list
mailing list