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? 16 1588
Why in the name of all that is holy and just would you need to do such
a thing?
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 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?
On 1 Jun 2005 09:41:53 -0700, infidel <sa***********@gmail.com> wrote: 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"?
--
Kristian
kristian.zoerhoff(AT)gmail.com
zoerhoff(AT)freeshell.org
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?
"God made me an atheist, who are you to question His wisdom?"
-- Saint Infidel the Skeptic
> 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).
ironfroggy wrote: 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
In article <11*********************@z14g2000cwz.googlegroups. com>,
"infidel" <sa***********@gmail.com> wrote: [ ... ] 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: type.__bases__
(<type 'object'>,)
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:
object.__class__
<type 'type'>
type also has type as its metaclass:
type.__class__
<type 'type'>
In other words, type is an instance of itself.
Just
Oh great, just when I thought I was starting to grok this mess.
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
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
Kristian Zoerhoff a écrit : On 1 Jun 2005 09:41:53 -0700, infidel <sa***********@gmail.com> wrote:
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 was just recovering from a ROFL attack when I noticed this too...
Guess what was the result ?
ironfroggy wrote: 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: class meta(type): pass
... class cls(object):
... __metaclass__ = meta
... def __repr__(cls):
... return "I'm %s, an instance of %s" % (cls.__name__, type(cls))
... meta.__bases__ = (cls,)+meta.__bases__ cls
I'm cls, an instance of <class 'meta'> assert type(cls) in cls.__subclasses__()
Of course, re-assigning meta.__bases__ comes too late to affect the construction
sequence of cls.
Michael
infidel wrote: 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
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robin Becker |
last post by:
A colleague wanted to initialize his class __new__ and tried code resembling this
#######################1
class Metaclass (type):
def __init__(cls, name, bases, *args, **kwargs):...
|
by: Irmen de Jong |
last post by:
Hi,
I've developed the Metaclass below, because I needed a way
to make a bunch of classes thread-safe.
I didn't want to change every method of the class by adding
lock.aqcuire()..lock.release()...
|
by: Jacek Generowicz |
last post by:
I would like to write a metaclass which would allow me to overload
names in the definition of its instances, like this
class Foo(object):
__metaclass__ = OverloadingClass
att = 1
att = 3
|
by: zipher |
last post by:
After searching through comp.lang.python and the web regarding
metaclasses, I could not find an example for customing classes using
metaclass parameters.
I want to be able to create a class at...
|
by: Pedro Werneck |
last post by:
Hi
I have a class A, with metaclass M_A, and class B, subclass of A, with
metaclass M_B, subclass of M_A.
A class C, subclass of B must have M_B or a subclass of it as metaclass,
but what if...
|
by: Christian Eder |
last post by:
Hi,
I think I have discovered a problem in context of
metaclasses and multiple inheritance in python 2.4,
which I could finally reduce to a simple example:
Look at following code:
class...
|
by: Pedro Werneck |
last post by:
Hi all
I noticed something strange here while explaining decorators to someone.
Not any real use code, but I think it's worth mentioning.
When I access a class attribute, on a class with a...
|
by: lbolognini |
last post by:
Hi all,
I dare risk my brain exploding by reaching for the understanding of
metaclasses.
At first i thought i almost got them, even if vaguely back in a corner
of my mind, my understanding...
|
by: thomas.karolski |
last post by:
Hi,
I would like to create a Decorator metaclass, which automatically
turns a class which inherits from the "Decorator" type into a
decorator.
A decorator in this case, is simply a class which...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |