This may turn out to be a basic question but i have spent hours on looking this up. Clearly, i am missing something in the internals of how objects/instances as well as class objects are created. Any help is appreciated.
Let me first create objects using standard way.
As can be seen below, two instances (object_1 and object_2) have the same class object (class_object_1 and class_object_2 are same) and assertion succeeds
class MyClass:
pass
if __name__=='__main__':
object_1 = MyClass()
object_2 = MyClass()
class_object_1 = object_1.__class__
class_object_2 = object_2.__class__
assert(class_object_1 == class_object_2)
However, when i try repeating this by dynamically creating class object using type, i do not get same object and assertion fails
cls_object_1 = type("MyClass", (), {})
cls_object_2 = type("MyClass", (), {})
assert(cls_object_1 == cls_object_2)
I further repeated this using yet another way and assertion fails again.
klass_object_1 = type.__new__(type, "MyClass", (), {})
klass_object_2 = type.__new__(type, "MyClass", (), {})
assert(cls_object_1 == cls_object_2)
Why are these ways not equivalent? What extra thing happens in first way that returns the same class object for two instances?