I can't comment on why you'd want to do something like this, but if you do need such dynamic behavior, perhaps consider using a metaclass to accomplish your goal?
Regardless, if you're wondering whether using the same class name will cause problems later on (I'm assuming you mean problems other than maintainability - as others have said, this has a high potential of being confusing and unnecessarily complex), then no, it won't.
The documentation for type()
is pretty clear about what the arguments are for:
The name string is the class name and becomes the
__name__
attribute; the bases tuple itemizes the base classes and becomes the__bases__
attribute; and the dict dictionary is the namespace containing definitions for class body and becomes the__dict__
attribute
That description shows that the name is simply used to populate a __name__
field. It turns out that it's basically for the humans, as shown in another answer.
In fact, you don't even need to use type()
to do this - you can do it with the simple class
statement.
class X(object): pass
class Y(object): pass
def create_other_y():
class Y(X): pass
global Y2
Y2 = Y
create_other_y()
(Y, Y2) # => (__main__.Y, __main__.Y)
(Y.__bases__, Y2.__bases__) # => ((object,), (__main__.X,))