python metaclass,type class and the object class -


i'm having headache trying understand cyclic relationship exit between metaclass type, object class, , class type.

i'm trying understand how python makes object.is because instance of metaclass type or because subclass of object class.

if because of being subclass of object class, mean if class object named class pyobj. mean in python starts pyobj?

i know objects created metaclass types/classes, types used create other object.

from this:

>>> isinstance(type, object) true >>> isinstance(object,type) true >>> issubclass(object,type) false >>> issubclass(type,object) true 

is safe python creates class object first using type metaclass (i'm simplifying metaclass brevity).

type('object',(),{}) 

which implies class object class of class type , not inherit attributes other class.

then creates class type:

type('type', (object,),{}) 

implying type class class of class type , inherits attributes object class.

then creates other classes inheriting class object

type('dict', (object,), {})   type('animal', (object), {}) 

which similar creating animal class :

class animal:      pass 

does mean metaclass used create class object still 1 used create animal class or metaclass type used default ?

which type being used, metaclass type or type class created after object created ?

where class type created base class object come play ?

i have tried understand going on between object , class responses above , in article http://www.cafepy.com/article/python_types_and_objects/python_types_and_objects.html

i'm still getting confused. relation between 2 class in terms of object creation?

will ever or chicken , egg situation?

python's core types have chicken , egg situation going on. type inherits object, object instance of type.

you can't reason of object or type defined first in python, because in regular python code not set relationship. python interpreter gets fiddling internals before environment set up, doesn't matter if types not defined front.

in example call type create new object , type types, you're not getting objects equivalent real type , object, new object type instance of builtin type metaclass, not hand-made type metaclass create later.

here's illustration of how interpreter goes it. code doesn't work, since can't create new-style class without inheriting object, nor can reassign type object's __class__ attribute (to make object instance of type). if could, start own independent type system!

my_object = type('my_object', (), {}) # doesn't work right, inherits object my_type = type('my_type', (my_object,), {}) my_object.__class__ = my_type     # doesn't work @ (it raise exception) 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

node.js - Using Node without global install -

php - CakePHP HttpSockets send array of paramms -