Python – How to clone a class in Python

python

I have a class A and i want a class B with exactly the same capabilities.
I cannot or do not want to inherit from B, such as doing class B(A):pass
Still i want B to be identical to A, yet have a different i: id(A) != id(B)
Watch out, i am not talking about instances but classes to be cloned.

Best Answer

I'm pretty sure whatever you are trying to do can be solved in a better way, but here is something that gives you a clone of the class with a new id:

def c():
    class Clone(object):
        pass

    return Clone

c1 = c()
c2 = c()
print id(c1)
print id(c2)

gives:

4303713312
4303831072