No, they are still different.
a = CustASample()
b = Sample()
a.__class__ is b.__class__
-> False
Here is how you could do it:
class A(object):
def __init__(self):
self.__class__ = B
class B(object):
def bark(self):
print "Wuff!"
a = A()
b = B()
a.__class__ is b.__class__
-> True
a.bark()
-> Wuff!
b.bark()
-> Wuff!
Usually you do this in a method __new__instead of __init__:
class C(object):
def __new__(cls):
return A()
To answer your updated question:
>>> a = object()
>>> b = object()
>>> a == b
False
Why not be equal to b, since both are just objects without attributes?
, . == __eq__, . , . a is b.
is . ( CPython - .) :
>>> id(a)
156808