metaclass that inherits a class of that metaclass?

I

ironfroggy

Hoping this isn't seeming too confusing, but I need to create a
metaclass and a class using that metaclass, such that one of the bases
of the metaclass is the class created with that metaclass. I can't
figure out a way to do this, even after trying to add the class as a
base after the classes have been created.

Is there some way I can get this to work properly?
 
I

infidel

Why in the name of all that is holy and just would you need to do such
a thing?
 
I

ironfroggy

because they are representing a seperate typing system outside of
python, to which I am creating a bridge. The metaclass represents the
types of this other system and the class represents the most basic
object type, but since the types the metaclass represent are also
objects, this is the only way i see to represent the relationship
properly.
 
I

infidel

I don't think that makes any sense. How could you possibly create such
a circular relationship between things in any language? Besides, if I
understand metaclasses at all, only other metaclasses can be bases of a
metaclass.

Why not use python classes to represent the other system's types with a
python metaclass as the "type" type?
 
K

Kristian Zoerhoff

Why in the name of all that is holy and just would you need to do such
a thing?

Is anyone else amused that this came from the mouth of someone named "Infidel"?
 
I

ironfroggy

because i need the representations of the other systems types to
themselves be python classes, and so i need a metaclass to make sure
they follow certain rules. This metaclass is for that system what type
is for python, and type is an object, which is a type. same thing, no?
 
I

infidel

"God made me an atheist, who are you to question His wisdom?"

-- Saint Infidel the Skeptic
 
I

infidel

because i need the representations of the other systems types to
themselves be python classes, and so i need a metaclass to make sure
they follow certain rules. This metaclass is for that system what type
is for python

I think that's exactly the same thing I just said. More or less.
Although depending on exactly what you mean by "follow certain rules",
you might only need a common base class rather than a metaclass.
same thing, no?

Uh, no, I don't think so. type is, from my trivial understanding, the
base type and base metaclass for everything else in python. Saying
"type is an object" is only confusing you into thinking it is a
subclass of object, which is not the case. object is a class, which I
believe has type as it's metaclass (though I could be mistaken - this
gets terribly confusing very quickly).
 
K

Kay Schluehr

ironfroggy said:
because they are representing a seperate typing system outside of
python, to which I am creating a bridge.

Since a type-hierarchy is a tree also a subtree of it is a
type-hierarchy. You only have to map the root of a sub-hierarchy of
Python classes to the root of the hierarchy of the other typing system
and create an isomorphism between types. For exactly the same reason
you can map Pythons type hierarchy onto a sub-hierarchy of it. This
might not be completely sufficient because there are functions that
operate on types ( like mro(), isinstance(), type() etc. ). Those must
be mapped as well to counterparts of the other type-system. In
contemporary CS slang this is called a 'Functor of Categories' with
objects that are types ( and boolean values like True, False ) and
arrows that are type aware functions like those listed above.

Kay
 
J

Just

"infidel said:
[ ... ] type is, from my trivial understanding, the
base type and base metaclass for everything else in python. Saying
"type is an object" is only confusing you into thinking it is a
subclass of object, which is not the case.

Sure is:
( said:
object is a class, which I
believe has type as it's metaclass (though I could be mistaken - this
gets terribly confusing very quickly).
Correct:
<type 'type'>

type also has type as its metaclass:
<type 'type'>

In other words, type is an instance of itself.

Just
 
I

infidel

Ok, forget everything I've said. The more I think about this the less
I understand it. I'm way out of my league here.

sitting-down-and-shutting-up-ly y'rs,

infi
 
B

Bruno Desthuilliers

infidel a écrit :
Oh great, just when I thought I was starting to grok this mess.

+1

dont-worry-no-normal-humain-brain-can-handle-this-kind-of-stuff-ly'yrs
 
B

Bruno Desthuilliers

Kristian Zoerhoff a écrit :
Is anyone else amused that this came from the mouth of someone named "Infidel"?

I was just recovering from a ROFL attack when I noticed this too...
Guess what was the result ?
 
M

Michael Spencer

ironfroggy said:
Hoping this isn't seeming too confusing, but I need to create a
metaclass and a class using that metaclass, such that one of the bases
of the metaclass is the class created with that metaclass. I can't
figure out a way to do this, even after trying to add the class as a
base after the classes have been created.

Is there some way I can get this to work properly?
What do you have, and how doesn't it work?

I get:
... __metaclass__ = meta
... def __repr__(cls):
... return "I'm %s, an instance of %s" % (cls.__name__, type(cls))
...
Of course, re-assigning meta.__bases__ comes too late to affect the construction
sequence of cls.

Michael
 
S

Steve Holden

infidel said:
Ok, forget everything I've said. The more I think about this the less
I understand it. I'm way out of my league here.

sitting-down-and-shutting-up-ly y'rs,
Well, that's a sign of maturity right there ;-)

some-people-just-don't-know-when-to-ly y'rs - steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top