473,657 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

metaclass that inherits a class of that metaclass?

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?

Jul 19 '05 #1
16 1615
Why in the name of all that is holy and just would you need to do such
a thing?

Jul 19 '05 #2
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.

Jul 19 '05 #3
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?

Jul 19 '05 #4
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.zoerho ff(AT)gmail.com
zoerhoff(AT)fre eshell.org
Jul 19 '05 #5
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?

Jul 19 '05 #6
"God made me an atheist, who are you to question His wisdom?"

-- Saint Infidel the Skeptic

Jul 19 '05 #7
> 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).

Jul 19 '05 #8
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

Jul 19 '05 #9
In article <11************ *********@z14g2 000cwz.googlegr oups.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
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1609
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): super(Metaclass, cls).__init__(cls, name, bases, *args, **kwargs) print 'cls=',cls, cls.__new cls.__new__ = staticmethod(cls.__new) def __new(self,cls,*args):
5
2260
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() around the existing code. So I made a metaclass that essentially replaces every method of a class with a 'wrapper' method, that does the locking, invocation, unlocking. Is this the right approach? It seems to work fine. But I have
33
2517
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
2
1938
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 runtime by calling some function or 'meta-constructor' which returns a customized class and sets a class attribute according a given parameter. Ideally, I'd be able to do something like:
14
2026
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 I need to 'disable' the code in M_B on C ? The correct way to do that seems to be with a M_C metaclass, subclass of M_B, implementing but not calling parent class methods, or calling 'type' methods.
9
1655
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 M_A (type) :
4
3307
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 custom metaclass with a __getattribute__ method, the method is used when acessing some attribute directly with the class object, but not when you do it from the instance.
2
1963
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 was that, as classes' class a metaclass would be able to return a different class based on input... .... until i thought of factory functions and, Python considering
4
2467
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 has all of its decorator implementation inside a decorator() method. Every other attribute access is being proxied to decorator().getParent(). Here's my attempt: -------------------------------------------------------
0
8425
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8622
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.